Module: I18n::Backend::Mongoid::Implementation
- Includes:
- Base, Flatten
- Included in:
- I18n::Backend::Mongoid
- Defined in:
- lib/i18n_backend_mongoid/i18n/backend/mongoid.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
-
#available_locales ⇒ Object
Get available locales from the translations hash.
- #initialize(model) ⇒ Object
- #initialized? ⇒ Boolean
-
#reload! ⇒ Object
Clean up translations hash and set initialized to false on reload!.
-
#store_translations(locale, data, options = {}) ⇒ Object
Stores translations for the given locale in memory.
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
7 8 9 |
# File 'lib/i18n_backend_mongoid/i18n/backend/mongoid.rb', line 7 def model @model end |
Instance Method Details
#available_locales ⇒ Object
Get available locales from the translations hash
31 32 33 34 35 36 37 |
# File 'lib/i18n_backend_mongoid/i18n/backend/mongoid.rb', line 31 def available_locales init_translations unless initialized? translations.inject([]) do |locales, (locale, data)| locales << locale unless (data.keys - [:i18n]).empty? locales end end |
#initialize(model) ⇒ Object
10 11 12 13 |
# File 'lib/i18n_backend_mongoid/i18n/backend/mongoid.rb', line 10 def initialize(model) @model = model init_translations end |
#initialized? ⇒ Boolean
15 16 17 |
# File 'lib/i18n_backend_mongoid/i18n/backend/mongoid.rb', line 15 def initialized? @initialized ||= false end |
#reload! ⇒ Object
Clean up translations hash and set initialized to false on reload!
40 41 42 43 44 |
# File 'lib/i18n_backend_mongoid/i18n/backend/mongoid.rb', line 40 def reload! @initialized = false @translations = nil init_translations end |
#store_translations(locale, data, options = {}) ⇒ Object
Stores translations for the given locale in memory. This uses a deep merge for the translations hash, so existing translations will be overwritten by new ones only at the deepest level of the hash.
23 24 25 26 27 28 |
# File 'lib/i18n_backend_mongoid/i18n/backend/mongoid.rb', line 23 def store_translations(locale, data, = {}) locale = locale.to_sym translations[locale] ||= {} data = data.deep_symbolize_keys translations[locale].deep_merge!(data) end |