class FastGettext::TranslationRepository::Db

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

Attributes

separator[RW]

Public Class Methods

included(_base) click to toggle source
# File lib/fast_gettext/translation_repository/db.rb, line 58
def self.included(_base)
  puts "you no longer need to include the result of require_models"
end
new(_name, options = {}) click to toggle source
# File lib/fast_gettext/translation_repository/db.rb, line 16
def initialize(_name, options = {})
  @model = options[:model]
end
require_models() click to toggle source
# File lib/fast_gettext/translation_repository/db.rb, line 53
def self.require_models
  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

Public Instance Methods

[](key) click to toggle source
# File lib/fast_gettext/translation_repository/db.rb, line 37
def [](key)
  @model.translation(key, FastGettext.locale)
end
available_locales() click to toggle source
# File lib/fast_gettext/translation_repository/db.rb, line 25
def available_locales
  if @model.respond_to? :available_locales
    @model.available_locales || []
  else
    []
  end
end
plural(*args) click to toggle source
# File lib/fast_gettext/translation_repository/db.rb, line 41
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() click to toggle source
# File lib/fast_gettext/translation_repository/db.rb, line 33
def pluralisation_rule
  @model.pluralsation_rule if @model.respond_to? :pluralsation_rule
end
reload() click to toggle source
# File lib/fast_gettext/translation_repository/db.rb, line 49
def reload
  true
end