Class: I18n::Backend::SequelBitemporal
- Inherits:
-
Object
- Object
- I18n::Backend::SequelBitemporal
- Includes:
- Implementation
- Defined in:
- lib/i18n/backend/sequel_bitemporal/translation.rb,
lib/i18n/backend/sequel_bitemporal.rb,
lib/i18n/backend/sequel_bitemporal/missing.rb,
lib/i18n/backend/sequel_bitemporal/store_procs.rb
Overview
Sequel model used to store actual translations to the database.
This model expects two tables like the following to be already set up in your the database:
create_table :i18n_translations do
primary_key :id
String :locale, :null => false
String :key, :null => false
index [:locale, :key], :unique => true
end
create_table :i18n_translation_versions do
primary_key :id
foreign_key :master_id, :i18n_translations, :on_delete => :cascade
Time :created_at
Time :expired_at
Date :valid_from
Date :valid_to
String :value, :text => true
String :interpolations, :text => true
TrueClass :is_proc, :null => false, :default => false
end
This model supports two named scopes :locale and :lookup. The :locale scope simply adds a condition for a given locale:
I18n::Backend::SequelBitemporal::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::SequelBitemporal::Translation.lookup(:foo)
# => an array with both translation records :"foo.bar" and :"foo.baz"
I18n::Backend::SequelBitemporal::Translation.lookup([:foo, :bar])
I18n::Backend::SequelBitemporal::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::SequelBitemporal::Translation
Translation.create \
:locale => 'en'
:key => 'foo'
:value => lambda { |key, options| 'FOO' }
Translation.find_by_locale_and_key('en', 'foo').value
# => 'FOO'
Defined Under Namespace
Modules: Implementation, Missing, StoreProcs Classes: Translation, TranslationVersion
Class Method Summary collapse
- .master_table_name ⇒ Object
- .master_table_name=(table_name) ⇒ Object
- .version_table_name ⇒ Object
- .version_table_name=(table_name) ⇒ Object
Methods included from Implementation
#available_locales, #clear, #initialize, #store_translations
Class Method Details
.master_table_name ⇒ Object
15 16 17 |
# File 'lib/i18n/backend/sequel_bitemporal.rb', line 15 def self.master_table_name @master_table_name || :i18n_translations end |
.master_table_name=(table_name) ⇒ Object
11 12 13 |
# File 'lib/i18n/backend/sequel_bitemporal.rb', line 11 def self.master_table_name=(table_name) @master_table_name = table_name end |
.version_table_name ⇒ Object
23 24 25 |
# File 'lib/i18n/backend/sequel_bitemporal.rb', line 23 def self.version_table_name @version_table_name || :i18n_translation_versions end |
.version_table_name=(table_name) ⇒ Object
19 20 21 |
# File 'lib/i18n/backend/sequel_bitemporal.rb', line 19 def self.version_table_name=(table_name) @version_table_name = table_name end |