Module: I18n::Backend::Weeler::Implementation

Includes:
Base, Flatten
Included in:
I18n::Backend::Weeler
Defined in:
lib/i18n/backend/weeler.rb

Instance Method Summary collapse

Instance Method Details

#available_localesObject



59
60
61
# File 'lib/i18n/backend/weeler.rb', line 59

def available_locales
  I18n::Backend::Weeler::Translation.distinct.pluck(:locale).compact.map(&:to_sym)
end

#reload_cacheObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/i18n/backend/weeler.rb', line 45

def reload_cache
  i18n_cache.clear

  Translation.all.each do |translation|
    # Load in cache unless value is nil or it is blank and empty
    # translation acts like missing
    next if translation.value.nil? || (::Weeler.empty_translation_acts_like_missing && translation.value.blank?)

    i18n_cache.write [translation.locale, translation.key], translation
  end

  i18n_cache.write('UPDATED_AT', Setting.i18n_updated_at) if ActiveRecord::Base.connection.data_source_exists?('settings')
end

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



37
38
39
40
41
42
43
# File 'lib/i18n/backend/weeler.rb', line 37

def store_translations(locale, data, options = {})
  escape = options.fetch(:escape, true)
  flatten_translations(locale, data, escape, false).each do |key, value|
    Translation.locale(locale).lookup(expand_keys(key)).delete_all
    Translation.create(locale: locale.to_s, key: key.to_s, value: value)
  end
end