Class: GettextSimpleRails::I18nInjector
- Inherits:
-
Object
- Object
- GettextSimpleRails::I18nInjector
- Defined in:
- lib/gettext_simple_rails/i18n_injector.rb
Instance Attribute Summary collapse
-
#store_hash ⇒ Object
readonly
Returns the value of attribute store_hash.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ I18nInjector
constructor
A new instance of I18nInjector.
- #inject_from_static_translation_file(args) ⇒ Object
- #inject_translator_translations(gettext_simple) ⇒ Object
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_hash ⇒ Object (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 |