26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/translated_attribute_value/base.rb', line 26
def translated_value_for(*args)
args.each do |attribute_name|
if defined?(ActiveRecord::Base) && self.ancestors.include?(ActiveRecord::Base)
self.send(:define_method, "#{attribute_name}_translated") do
attribute_value = self.send(attribute_name)
I18n.t("activerecord.attributes.#{self.class.to_s.underscore}.#{attribute_name}_translation.#{attribute_value}")
end
elsif defined?(Mongoid::Document) && self.ancestors.include?(Mongoid::Document)
self.send(:define_method, "#{attribute_name}_translated") do
attribute_value = self.send(attribute_name)
I18n.t("mongoid.attributes.#{self.class.to_s.underscore}.#{attribute_name}_translation.#{attribute_value}")
end
else
self.send(:define_method, "#{attribute_name}_translated") do
attribute_value = self.send(attribute_name)
I18n.t("translated_attribute_value.#{self.class.to_s.underscore}.#{attribute_name}_translation.#{attribute_value}")
end
end
end
end
|