Module: I18n::Backend::SequelBitemporal::Missing

Includes:
Flatten
Defined in:
lib/i18n/backend/sequel_bitemporal/missing.rb

Constant Summary collapse

RESERVED_KEYS =
if defined?(I18n::RESERVED_KEYS)
  I18n::RESERVED_KEYS
else
  I18n::Backend::Base::RESERVED_KEYS
end

Instance Method Summary collapse

Instance Method Details

#store_default_translation(locale, key, interpolations) ⇒ Object



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

def store_default_translation(locale, key, interpolations)
  translation = Translation.new :locale => locale.to_s, :key => key
  # We're storing interpolations in the version
  translation.attributes = {:interpolations => interpolations}
  translation.save
end

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



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/i18n/backend/sequel_bitemporal/missing.rb', line 44

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

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

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



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/i18n/backend/sequel_bitemporal/missing.rb', line 63

def translate(locale, key, options = {})
  result = catch(:exception) do
    super
  end
  if I18n.const_defined?(:MissingTranslation) && result.is_a?(I18n::MissingTranslation)
    self.store_default_translations(locale, key, options)
    throw(:exception, result)
  end
  result
rescue I18n::MissingTranslationData => e
  self.store_default_translations(locale, key, options)
  raise e
end