Class: GettextSimpleRails::I18nInjector

Inherits:
Object
  • Object
show all
Defined in:
lib/gettext_simple_rails/i18n_injector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ I18nInjector

Returns a new instance of I18nInjector.



4
5
6
7
8
9
# File 'lib/gettext_simple_rails/i18n_injector.rb', line 4

def initialize(args = {})
  @args = args
  @debug = args[:debug]
  @i18n_backend = I18n.config.backend
  @store_hash = {}
end

Instance Attribute Details

#store_hashObject (readonly)

Returns the value of attribute store_hash.



2
3
4
# File 'lib/gettext_simple_rails/i18n_injector.rb', line 2

def store_hash
  @store_hash
end

Instance Method Details

#inject_from_static_translation_file(args) ⇒ Object



30
31
32
33
34
35
# File 'lib/gettext_simple_rails/i18n_injector.rb', line 30

def inject_from_static_translation_file(args)
  translation_hash = JSON.parse(File.read(args[:path]))
  translation_hash.each do |locale, language_hash|
    @i18n_backend.store_translations(locale.to_sym, language_hash)
  end
end

#inject_translator_translations(gettext_simple) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gettext_simple_rails/i18n_injector.rb', line 11

def inject_translator_translations(gettext_simple)
  @store_hash = {}
  
  GettextSimpleRails::Translators.load_all.each do |translator_data|
    translator = translator_data[:class].new
    next unless translator.detected?
    
    I18n.available_locales.each do |locale|
      next unless gettext_simple.locale_exists?(locale.to_s)
      locale = locale.to_s
      injector_recursive gettext_simple, locale, translator.translations
    end
  end
  
  @store_hash.each do |locale, language_hash|
    @i18n_backend.store_translations(locale.to_sym, language_hash)
  end
end