Module: I18n::Backend::Sequel::Missing

Includes:
Flatten
Defined in:
lib/i18n_backend_sequel/missing.rb

Instance Method Summary collapse

Instance Method Details

#store_default_translation(locale, key, interpolations) ⇒ Object



50
51
52
53
54
# File 'lib/i18n_backend_sequel/missing.rb', line 50

def store_default_translation(locale, key, interpolations)
  translation = Sequel::Translation.new(:locale => locale.to_s, :key => key)
  translation.interpolations = interpolations
  translation.save(:validate => false)
end

#store_default_translations(locale, key, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/i18n_backend_sequel/missing.rb', line 38

def store_default_translations(locale, key, options = {})
  count, scope, default, separator = options.values_at(:count, :scope, :default, :separator)
  separator ||= I18n.default_separator
  key = normalize_flat_keys(locale, key, scope, separator)

  if Sequel::Translation.locale(locale).lookup(key).empty?
    interpolations = options.keys - Base::RESERVED_KEYS
    keys = count ? I18n.t('i18n.plural.keys', :locale => locale).map { |k| [key, k].join(FLATTEN_SEPARATOR) } : [key]
    keys.each { |key| store_default_translation(locale, key, interpolations) }
  end
end

#translate(locale, key, options = {}) ⇒ Object



56
57
58
59
60
61
# File 'lib/i18n_backend_sequel/missing.rb', line 56

def translate(locale, key, options = {})
  super
rescue I18n::MissingTranslationData => e
  self.store_default_translations(locale, key, options)
  raise e
end