Class: FastGettext::TranslationRepository::Db

Inherits:
Object
  • Object
show all
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

Constant Summary collapse

@@seperator =

string that seperates multiple plurals

'||||'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Db

Returns a new instance of Db.



14
15
16
# File 'lib/fast_gettext/translation_repository/db.rb', line 14

def initialize(name,options={})
  @model = options[:model]
end

Class Method Details

.require_modelsObject



50
51
52
53
54
# File 'lib/fast_gettext/translation_repository/db.rb', line 50

def self.require_models
  require 'fast_gettext/translation_repository/db_models/translation_key'
  require 'fast_gettext/translation_repository/db_models/translation_text'
  FastGettext::TranslationRepository::DbModels
end

.seperatorObject



20
# File 'lib/fast_gettext/translation_repository/db.rb', line 20

def self.seperator;@@seperator;end

.seperator=(sep) ⇒ Object



19
# File 'lib/fast_gettext/translation_repository/db.rb', line 19

def self.seperator=(sep);@@seperator = sep;end

Instance Method Details

#[](key) ⇒ Object



38
39
40
# File 'lib/fast_gettext/translation_repository/db.rb', line 38

def [](key)
  @model.translation(key, FastGettext.locale)
end

#available_localesObject



22
23
24
25
26
27
28
# File 'lib/fast_gettext/translation_repository/db.rb', line 22

def available_locales
  if @model.respond_to? :available_locales
    @model.available_locales || []
  else
    []
  end
end

#plural(*args) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/fast_gettext/translation_repository/db.rb', line 42

def plural(*args)
  if translation = @model.translation(args*self.class.seperator, FastGettext.locale)
    translation.to_s.split(self.class.seperator)
  else
    []
  end
end

#pluralisation_ruleObject



30
31
32
33
34
35
36
# File 'lib/fast_gettext/translation_repository/db.rb', line 30

def pluralisation_rule
  if @model.respond_to? :pluralsation_rule
    @model.pluralsation_rule
  else
    nil
  end
end