Class: Lit::I18nBackend
- Inherits:
-
Object
- Object
- Lit::I18nBackend
- Includes:
- I18n::Backend::Simple::Implementation
- Defined in:
- lib/lit/i18n_backend.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Instance Method Summary collapse
- #available_locales ⇒ Object
-
#initialize(cache) ⇒ I18nBackend
constructor
A new instance of I18nBackend.
- #reset_available_locales_cache ⇒ Object
-
#store_translations(locale, data, options = {}) ⇒ Object
Stores the given translations.
- #translate(locale, key, options = {}) ⇒ Object
Constructor Details
#initialize(cache) ⇒ I18nBackend
Returns a new instance of I18nBackend.
9 10 11 12 13 14 15 16 17 |
# File 'lib/lit/i18n_backend.rb', line 9 def initialize(cache) @cache = cache @available_locales_cache = nil @translations = {} reserved_keys = I18n.const_get :RESERVED_KEYS reserved_keys << :lit_default_copy I18n.send(:remove_const, :RESERVED_KEYS) I18n.const_set(:RESERVED_KEYS, reserved_keys) end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
7 8 9 |
# File 'lib/lit/i18n_backend.rb', line 7 def cache @cache end |
Instance Method Details
#available_locales ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lit/i18n_backend.rb', line 29 def available_locales return @available_locales_cache unless @available_locales_cache.nil? @locales ||= ::Rails.configuration.i18n.available_locales if @locales && !@locales.empty? @available_locales_cache = @locales.map(&:to_sym) else @available_locales_cache = Lit::Locale.ordered.visible.map { |l| l.locale.to_sym } end @available_locales_cache end |
#reset_available_locales_cache ⇒ Object
40 41 42 |
# File 'lib/lit/i18n_backend.rb', line 40 def reset_available_locales_cache @available_locales_cache = nil end |
#store_translations(locale, data, options = {}) ⇒ Object
Stores the given translations.
48 49 50 51 52 53 |
# File 'lib/lit/i18n_backend.rb', line 48 def store_translations(locale, data, = {}) super ActiveRecord::Base.transaction do store_item(locale, data) end if store_items? && valid_locale?(locale) end |
#translate(locale, key, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/lit/i18n_backend.rb', line 19 def translate(locale, key, = {}) [:lit_default_copy] = [:default].dup if can_dup_default() content = super(locale, key, ) if Lit.all_translations_are_html_safe && content.respond_to?(:html_safe) content.html_safe else content end end |