Module: I18n::Backend::ActiveRecord::Implementation

Includes:
Base, Flatten, TranslationModel
Included in:
I18n::Backend::ActiveRecord
Defined in:
lib/i18n/backend/active_record.rb

Instance Method Summary collapse

Instance Method Details

#available_localesObject



41
42
43
44
45
# File 'lib/i18n/backend/active_record.rb', line 41

def available_locales
  translation_model.available_locales
rescue ::ActiveRecord::StatementInvalid
  []
end

#init_translationsObject



75
76
77
# File 'lib/i18n/backend/active_record.rb', line 75

def init_translations
  @translations = translation_model.to_h
end

#initialized?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/i18n/backend/active_record.rb', line 71

def initialized?
  !@translations.nil?
end

#reload!Object



65
66
67
68
69
# File 'lib/i18n/backend/active_record.rb', line 65

def reload!
  @translations = nil

  self
end

#store_translations(locale, data, options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/i18n/backend/active_record.rb', line 47

def store_translations(locale, data, options = {})
  escape = options.fetch(:escape, true)

  flatten_translations(locale, data, escape, false).each do |key, value|
    translation = translation_model.locale(locale).lookup(expand_keys(key))

    if self.class.config.cleanup_with_destroy
      translation.destroy_all
    else
      translation.delete_all
    end

    translation_model.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



79
80
81
82
# File 'lib/i18n/backend/active_record.rb', line 79

def translations(do_init: false)
  init_translations if do_init || !initialized?
  @translations ||= {}
end