Module: Phrasing::Implementation

Included in:
I18n::Backend::Simple
Defined in:
lib/phrasing/implementation.rb

Instance Method Summary collapse

Instance Method Details

#lookup(locale, key, scope = [], options = {}) ⇒ Object

this method overrides part of the i18n gem, lib/i18n/backend/simple.rb



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/phrasing/implementation.rb', line 4

def lookup(locale, key, scope = [], options = {})
  return super unless ActiveRecord::Base.connected? && PhrasingPhrase.table_exists?

  scoped_key = I18n.normalize_keys(nil, key, scope, options[:separator]).join(".")

  phrase = PhrasingPhrase.where(locale: locale.to_s, key: scoped_key).first
  return phrase.value if phrase

  value = super(locale, key, scope, options)

  if value and (value.is_a? String or value.is_a? Symbol)
    # creation in background no matter if developer user the I18n#t or phrase helper
    PhrasingPhrase.create_phrase(scoped_key, value)
  end
  value
end