Module: Rails::Translate::ActsMethods
- Defined in:
- lib/rails-translate.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#translate(*args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rails-translate.rb', line 10 def translate(*args) args.each do |arg| define_method(arg.to_s) do attribute = "#{arg}_#{I18n.locale}" default_attribute = "#{arg}_#{I18n.default_locale}" begin return send(attribute).empty? ? send(default_attribute) : send(attribute) rescue return send(default_attribute) end end define_method(arg.to_s + '=') do |data| attribute = "#{arg}_#{I18n.locale}" write_attribute attribute, data if self.respond_to? attribute end end extend ClassMethods end |