Module: TidyI18n

Defined in:
lib/tidy_i18n.rb,
lib/tidy_i18n/locales.rb,
lib/tidy_i18n/missing_keys.rb,
lib/tidy_i18n/translations.rb,
lib/tidy_i18n/locales/tilde.rb,
lib/tidy_i18n/duplicate_keys.rb,
lib/tidy_i18n/locales/reverse.rb,
lib/tidy_i18n/translation_keys.rb,
lib/tidy_i18n/dictionary_converter.rb

Defined Under Namespace

Modules: Locales Classes: DictionaryConverter, DuplicateKeys, MissingKeys, ProjectRootNotConfigured, RaiseAllErrors, TranslationKey, TranslationKeys, Translations

Class Method Summary collapse

Class Method Details

.project_rootObject



17
18
19
# File 'lib/tidy_i18n.rb', line 17

def self.project_root
  @project_root
end

.project_root=(path) ⇒ Object



13
14
15
# File 'lib/tidy_i18n.rb', line 13

def self.project_root=(path)
  @project_root = path
end

.raise_error_on_missing_translation=(raise_error) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/tidy_i18n.rb', line 21

def self.raise_error_on_missing_translation=(raise_error)
  if raise_error
    I18n.exception_handler = RaiseAllErrors.new
  else
    I18n.exception_handler = I18n::ExceptionHandler.new
  end
end

.translate(key, options = {}) ⇒ Object Also known as: t



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tidy_i18n.rb', line 29

def self.translate(key, options={})
  raise ProjectRootNotConfigured if project_root.nil?
  if key[0] == "."
    key_prefix = caller[0].
      gsub("#{project_root}/", "").
      split(".").
      first.
      gsub("/", ".")
    I18n.translate("#{key_prefix}.#{key}", options)
  else
    I18n.translate(key, options)
  end
end