Module: DataMapper::Is::Localizable::InstanceMethods

Defined in:
lib/dm-is-localizable/is/localizable.rb

Instance Method Summary collapse

Instance Method Details

#available_languagesObject

list all available languages for this instance



90
91
92
# File 'lib/dm-is-localizable/is/localizable.rb', line 90

def available_languages
  Language.all :id => translations.map { |t| t.language_id }.uniq
end

#nr_of_available_languagesObject

the number of all available languages for this instance



95
96
97
# File 'lib/dm-is-localizable/is/localizable.rb', line 95

def nr_of_available_languages
  available_languages.size
end

#translate(attribute, language_code) ⇒ Object

translates the given attribute to the language identified by the given language_code



105
106
107
108
109
110
111
112
# File 'lib/dm-is-localizable/is/localizable.rb', line 105

def translate(attribute, language_code)
  if language = Language[language_code]
    t = translations.first(:language_id => language.id)
    t.respond_to?(attribute) ? t.send(attribute) : nil
  else
    nil
  end
end

#translations_complete?Boolean

checks if this instance is translated into all available languages for this model

Returns:

  • (Boolean)


100
101
102
# File 'lib/dm-is-localizable/is/localizable.rb', line 100

def translations_complete?
  self.class.nr_of_available_languages == translations.size
end