Module: I18n::Backend::ActiveRecord::Implementation
- Includes:
- Base, Flatten
- Included in:
- I18n::Backend::ActiveRecord
- Defined in:
- lib/i18n/backend/active_record.rb
Instance Method Summary collapse
- #available_locales ⇒ Object
- #init_translations ⇒ Object
- #initialized? ⇒ Boolean
- #reload! ⇒ Object
- #store_translations(locale, data, options = {}) ⇒ Object
- #translations(do_init: false) ⇒ Object
Instance Method Details
#available_locales ⇒ Object
32 33 34 35 36 |
# File 'lib/i18n/backend/active_record.rb', line 32 def available_locales Translation.available_locales rescue ::ActiveRecord::StatementInvalid [] end |
#init_translations ⇒ Object
66 67 68 |
# File 'lib/i18n/backend/active_record.rb', line 66 def init_translations @translations = Translation.to_h end |
#initialized? ⇒ Boolean
62 63 64 |
# File 'lib/i18n/backend/active_record.rb', line 62 def initialized? !@translations.nil? end |
#reload! ⇒ Object
56 57 58 59 60 |
# File 'lib/i18n/backend/active_record.rb', line 56 def reload! @translations = nil self end |
#store_translations(locale, data, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/i18n/backend/active_record.rb', line 38 def store_translations(locale, data, = {}) escape = .fetch(:escape, true) flatten_translations(locale, data, escape, false).each do |key, value| translation = Translation.locale(locale).lookup((key)) if self.class.config.cleanup_with_destroy translation.destroy_all else translation.delete_all end Translation.create(locale: locale.to_s, key: key.to_s, value: value) end reload! if self.class.config.cache_translations end |
#translations(do_init: false) ⇒ Object
70 71 72 73 |
# File 'lib/i18n/backend/active_record.rb', line 70 def translations(do_init: false) init_translations if do_init || !initialized? @translations ||= {} end |