Class: Stringex::Localization::Backend::I18n
- Defined in:
- lib/stringex/localization/backend/i18n.rb
Constant Summary collapse
- LOAD_PATH_BASE =
File.join(File.(File.dirname(__FILE__)), '..', '..', '..', '..', 'locales')
Class Method Summary collapse
- .default_locale ⇒ Object
- .default_locale=(new_locale) ⇒ Object
- .i18n_translations_for(locale) ⇒ Object
- .initial_translation(scope, key, locale) ⇒ Object
- .load_translations(locale = nil) ⇒ Object
- .locale ⇒ Object
- .locale=(new_locale) ⇒ Object
- .reset_translations_cache ⇒ Object
- .store_translations(locale, scope, data) ⇒ Object
- .translations ⇒ Object
- .with_locale(new_locale, &block) ⇒ Object
Methods inherited from Base
Class Method Details
.default_locale ⇒ Object
16 17 18 |
# File 'lib/stringex/localization/backend/i18n.rb', line 16 def default_locale ::I18n.default_locale end |
.default_locale=(new_locale) ⇒ Object
20 21 22 |
# File 'lib/stringex/localization/backend/i18n.rb', line 20 def default_locale=(new_locale) ::I18n.default_locale = new_locale end |
.i18n_translations_for(locale) ⇒ Object
50 51 52 |
# File 'lib/stringex/localization/backend/i18n.rb', line 50 def i18n_translations_for(locale) ::I18n.translate("stringex", :locale => locale, :default => {}) end |
.initial_translation(scope, key, locale) ⇒ Object
38 39 40 |
# File 'lib/stringex/localization/backend/i18n.rb', line 38 def initial_translation(scope, key, locale) translations[locale][scope][key.to_sym] end |
.load_translations(locale = nil) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/stringex/localization/backend/i18n.rb', line 42 def load_translations(locale = nil) locale ||= self.locale path = Dir[File.join(LOAD_PATH_BASE, "#{locale}.yml")] ::I18n.load_path |= Dir[File.join(LOAD_PATH_BASE, "#{locale}.yml")] ::I18n.backend.load_translations reset_translations_cache end |
.locale ⇒ Object
8 9 10 |
# File 'lib/stringex/localization/backend/i18n.rb', line 8 def locale @locale || ::I18n.locale end |
.locale=(new_locale) ⇒ Object
12 13 14 |
# File 'lib/stringex/localization/backend/i18n.rb', line 12 def locale=(new_locale) @locale = new_locale end |
.reset_translations_cache ⇒ Object
54 55 56 |
# File 'lib/stringex/localization/backend/i18n.rb', line 54 def reset_translations_cache @translations = nil end |
.store_translations(locale, scope, data) ⇒ Object
28 29 30 31 |
# File 'lib/stringex/localization/backend/i18n.rb', line 28 def store_translations(locale, scope, data) ::I18n.backend.store_translations(locale, { :stringex => { scope => data } }) reset_translations_cache end |
.translations ⇒ Object
33 34 35 36 |
# File 'lib/stringex/localization/backend/i18n.rb', line 33 def translations # Set up hash like translations[:en][:transliterations]["é"] @translations ||= Hash.new { |hsh, locale| hsh[locale] = Hash.new({}).merge(i18n_translations_for(locale)) } end |
.with_locale(new_locale, &block) ⇒ Object
24 25 26 |
# File 'lib/stringex/localization/backend/i18n.rb', line 24 def with_locale(new_locale, &block) ::I18n.with_locale new_locale, &block end |