Module | ArkanisDevelopment::SimpleLocalization::LocalizedModels::ClassMethods |
In: |
lib/features/localized_models.rb
|
localized_attribute_names | [RW] | |
localized_model_name | [RW] |
# File lib/features/localized_models.rb, line 68 68: def human_attribute_name(attribute_key_name) 69: self.localized_attribute_names[attribute_key_name.to_sym] || 70: self.localized_attribute_names[attribute_key_name.to_s] || 71: super(attribute_key_name.to_s) 72: end
This method is used to add localization information to a model. As the first parameter the localized model name is expected. The second parameter is a hash of attribute names, each specifying the localized name of the attribute.
This example adds german names to the model and it‘s attributes.
class Computer < ActiveRecord::Base belongs_to :user validates_presence_of :name, :ip_address, :user localized_names 'Der Computer', :name => 'Der Name', :description => 'Die Beschreibung', :ip_address => 'Die IP-Adresse', :user => 'Der Besitzer' end
To access the localized model name use the class method localized_model_name. The human_attribute_name method will also be extended so you‘ll get the localized names from it if available.
# File lib/features/localized_models.rb, line 64 64: def localized_names(model_name, attribute_names = {}) 65: class << self 66: attr_accessor :localized_model_name, :localized_attribute_names 67: 68: def human_attribute_name(attribute_key_name) 69: self.localized_attribute_names[attribute_key_name.to_sym] || 70: self.localized_attribute_names[attribute_key_name.to_s] || 71: super(attribute_key_name.to_s) 72: end 73: end 74: 75: self.localized_model_name = model_name 76: self.localized_attribute_names = attribute_names 77: end