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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.extra_translationsObject



12
13
14
# File 'lib/i18n/extra_translations.rb', line 12

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

.localeObject



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

def locale
  @locale ||= I18n.default_locale
end

Class Method Details

.missing_translationsObject



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

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



21
22
23
24
25
26
27
28
29
30
# File 'lib/i18n/extra_translations.rb', line 21

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