Class: I18n::Backend::Sequel
- Inherits:
-
Object
- Object
- I18n::Backend::Sequel
- Includes:
- Implementation
- Defined in:
- lib/i18n/backend/sequel/translation.rb,
lib/i18n/backend/sequel.rb,
lib/i18n/backend/sequel/missing.rb,
lib/i18n/backend/sequel/store_procs.rb
Overview
Sequel model used to store actual translations to the database.
This model expects a table like the following to be already set up in your the database:
create_table :i18n_translations do |t|
String :locale, :null => false
String :key, :null => false
String :value, :text => true
String :interpolations, :text => true
TrueClass :is_proc, :null => false, :default => false
primary_key [:locale, :key]
end
This model supports to named scopes :locale and :lookup. The :locale scope simply adds a condition for a given locale:
I18n::Backend::Sequel::Translation.locale(:en).all
# => all translation records that belong to the :en locale
The :lookup scope adds a condition for looking up all translations that either start with the given keys (joined by an optionally given separator or I18n.default_separator) or that exactly have this key.
# with translations present for :"foo.bar" and :"foo.baz"
I18n::Backend::Sequel::Translation.lookup(:foo)
# => an array with both translation records :"foo.bar" and :"foo.baz"
I18n::Backend::Sequel::Translation.lookup([:foo, :bar])
I18n::Backend::Sequel::Translation.lookup(:"foo.bar")
# => an array with the translation record :"foo.bar"
When the StoreProcs module was mixed into this model then Procs will be stored to the database as Ruby code and evaluated when :value is called.
Translation = I18n::Backend::Sequel::Translation
Translation.create \
:locale => 'en'
:key => 'foo'
:value => lambda { |key, options| 'FOO' }
Translation.locale('en').lookup('foo').value
# => 'FOO'
Defined Under Namespace
Modules: Implementation, Missing, StoreProcs Classes: Translation