class Stringex::Localization::Backend::I18n
Constants
- LOAD_PATH_BASE
Public Class Methods
Source
# File lib/stringex/localization/backend/i18n.rb 22 def default_locale 23 ::I18n.default_locale 24 end
Source
# File lib/stringex/localization/backend/i18n.rb 26 def default_locale=(new_locale) 27 ::I18n.default_locale = new_locale 28 end
Source
# File lib/stringex/localization/backend/i18n.rb 64 def ensure_locales_enforced_or_not 65 return unless ::I18n.respond_to?(:enforce_available_locales) 66 # Allow users to have set this to false manually but default to true 67 return unless ::I18n.enforce_available_locales == nil 68 ::I18n.enforce_available_locales = ::I18n.available_locales != [] 69 end
Source
# File lib/stringex/localization/backend/i18n.rb 55 def i18n_translations_for(locale) 56 ensure_locales_enforced_or_not 57 ::I18n.translate("stringex", locale: locale, default: {}) 58 end
Source
# File lib/stringex/localization/backend/i18n.rb 44 def initial_translation(scope, key, locale) 45 translations[locale][scope][key.to_sym] 46 end
Source
# File lib/stringex/localization/backend/i18n.rb 48 def load_translations(locale = nil) 49 locale ||= self.locale 50 ::I18n.load_path |= Dir[File.join(LOAD_PATH_BASE, "#{locale}.yml")] 51 ::I18n.backend.load_translations 52 reset_translations_cache 53 end
Source
# File lib/stringex/localization/backend/i18n.rb 14 def locale 15 @locale || ::I18n.locale 16 end
Source
# File lib/stringex/localization/backend/i18n.rb 18 def locale=(new_locale) 19 @locale = new_locale 20 end
Source
# File lib/stringex/localization/backend/i18n.rb 8 def reset! 9 super 10 @locale = nil 11 ::I18n.reload! if defined?(::I18n) && ::I18n.respond_to?(:reload!) 12 end
Calls superclass method
Stringex::Localization::Backend::Base::reset!
Source
# File lib/stringex/localization/backend/i18n.rb 60 def reset_translations_cache 61 @translations = nil 62 end
Source
# File lib/stringex/localization/backend/i18n.rb 34 def store_translations(locale, scope, data) 35 ::I18n.backend.store_translations(locale, {stringex: {scope => data}}) 36 reset_translations_cache 37 end
Source
# File lib/stringex/localization/backend/i18n.rb 39 def translations 40 # Set up hash like translations[:en][:transliterations]["é"] 41 @translations ||= Hash.new { |hsh, locale| hsh[locale] = Hash.new({}).merge(i18n_translations_for(locale)) } 42 end
Source
# File lib/stringex/localization/backend/i18n.rb 30 def with_locale(new_locale, &block) 31 ::I18n.with_locale new_locale, &block 32 end