Class: I18n::ExtraTranslations

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/extra_translations.rb,
lib/i18n/extra_translations/store.rb,
lib/i18n/extra_translations/server.rb,
lib/i18n/extra_translations/simple_extension.rb

Defined Under Namespace

Modules: SimpleExtension Classes: Server, Store, UnexpectedTranslationError

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.extra_translationsObject



21
22
23
# File 'lib/i18n/extra_translations.rb', line 21

def extra_translations
  @extra_translations ||= ExtraTranslations::Store.new
end

.localeObject



26
27
28
# File 'lib/i18n/extra_translations.rb', line 26

def locale
  @locale ||= I18n.default_locale
end

Class Method Details

.missing_translationsObject



41
42
43
44
45
46
# File 'lib/i18n/extra_translations.rb', line 41

def missing_translations
  keys = all_keys_from(extra_translations, [], []) do |keys, _|
    !extra_translations.used?(keys)
  end
  keys.map{ |keys| keys.join('.') }
end

.unused_translations(filenames = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/i18n/extra_translations.rb', line 30

def unused_translations(filenames=nil)
  filenames ||= ["./config/locales/#{locale}.yml"]
  filenames.inject({}) do |memo, filename|
    data = YAML.load_file(filename)
    keys = all_keys_from(data, [])
    memo[filename] = keys.select{|keys| !extra_translations.used?(keys)}
    memo[filename].map!{|keys| keys.join('.')}
    memo
  end
end