Class: FastGettext::TranslationRepository::Db
- Inherits:
-
Object
- Object
- FastGettext::TranslationRepository::Db
- Defined in:
- lib/fast_gettext/translation_repository/db.rb
Overview
Responsibility:
- provide access to translations in database through a database abstraction
Options:
:model => Model that represents your keys
you can either use the models supplied under db/, extend them or build your own
only constraints:
key: find_by_key, translations
translation: text, locale
Class Attribute Summary collapse
-
.separator ⇒ Object
Returns the value of attribute separator.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #available_locales ⇒ Object
-
#initialize(_name, options = {}) ⇒ Db
constructor
A new instance of Db.
- #plural(*args) ⇒ Object
- #pluralisation_rule ⇒ Object
- #reload ⇒ Object
Constructor Details
#initialize(_name, options = {}) ⇒ Db
Returns a new instance of Db.
15 16 17 |
# File 'lib/fast_gettext/translation_repository/db.rb', line 15 def initialize(_name, = {}) @model = [:model] end |
Class Attribute Details
.separator ⇒ Object
Returns the value of attribute separator.
21 22 23 |
# File 'lib/fast_gettext/translation_repository/db.rb', line 21 def separator @separator end |
Class Method Details
.require_models ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fast_gettext/translation_repository/db.rb', line 52 def self.require_models require 'active_record' folder = "fast_gettext/translation_repository/db_models" require "#{folder}/translation_key" require "#{folder}/translation_text" Module.new do def self.included(_base) puts "you no longer need to include the result of require_models" end end end |
Instance Method Details
#[](key) ⇒ Object
36 37 38 |
# File 'lib/fast_gettext/translation_repository/db.rb', line 36 def [](key) @model.translation(key, FastGettext.locale) end |
#available_locales ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/fast_gettext/translation_repository/db.rb', line 24 def available_locales if @model.respond_to? :available_locales @model.available_locales || [] else [] end end |
#plural(*args) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/fast_gettext/translation_repository/db.rb', line 40 def plural(*args) if translation = @model.translation(args * self.class.separator, FastGettext.locale) translation.to_s.split(self.class.separator) else [] end end |
#pluralisation_rule ⇒ Object
32 33 34 |
# File 'lib/fast_gettext/translation_repository/db.rb', line 32 def pluralisation_rule @model.pluralisation_rule if @model.respond_to? :pluralisation_rule end |
#reload ⇒ Object
48 49 50 |
# File 'lib/fast_gettext/translation_repository/db.rb', line 48 def reload true end |