Module: DataMapper::Is::Localizable::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#available_languagesObject

list all available languages for the localizable model



82
83
84
85
# File 'lib/dm-is-localizable/is/localizable.rb', line 82

def available_languages
  ids = translation_model.all.map { |t| t.language_id }.uniq
  ids.empty? ? [] : Language.all(:id => ids)
end

#localizable_propertiesObject

returns a list of symbols reflecting all localizable property names of this resource



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

def localizable_properties
  translation_model.properties.map { |p| p.name }.select do |p|
    # exclude properties that are'nt localizable
    p != :id && p != :language_id && p != ActiveSupport::Inflector.foreign_key(self.name).to_sym
  end
end

#nr_of_available_languagesObject

the number of all available languages for the localizable model



88
89
90
# File 'lib/dm-is-localizable/is/localizable.rb', line 88

def nr_of_available_languages
  available_languages.size
end

#translation_modelObject



77
78
79
# File 'lib/dm-is-localizable/is/localizable.rb', line 77

def translation_model
  @translation_model
end

#translations_complete?Boolean

checks if all localizable resources are translated in all available languages

Returns:

  • (Boolean)


93
94
95
# File 'lib/dm-is-localizable/is/localizable.rb', line 93

def translations_complete?
  available_languages.size * all.size == translation_model.all.size
end