Module: DataMapper::Is::Localizable::InstanceMethods
- Defined in:
- lib/dm-is-localizable/is/localizable.rb
Instance Method Summary collapse
-
#available_languages ⇒ Object
list all available languages for this instance.
-
#nr_of_available_languages ⇒ Object
the number of all available languages for this instance.
-
#translate(attribute, language_code) ⇒ Object
translates the given attribute to the language identified by the given language_code.
-
#translations_complete? ⇒ Boolean
checks if this instance is translated into all available languages for this model.
Instance Method Details
#available_languages ⇒ Object
list all available languages for this instance
110 111 112 113 |
# File 'lib/dm-is-localizable/is/localizable.rb', line 110 def available_languages ids = translations.map { |t| t.language_id }.uniq ids.empty? ? [] : Language.all(:id => ids) end |
#nr_of_available_languages ⇒ Object
the number of all available languages for this instance
116 117 118 |
# File 'lib/dm-is-localizable/is/localizable.rb', line 116 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
126 127 128 129 130 131 132 133 |
# File 'lib/dm-is-localizable/is/localizable.rb', line 126 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
121 122 123 |
# File 'lib/dm-is-localizable/is/localizable.rb', line 121 def translations_complete? self.class.nr_of_available_languages == translations.size end |