Module: Kuhsaft::Translatable::ClassMethods

Defined in:
lib/kuhsaft/translatable.rb

Instance Method Summary collapse

Instance Method Details

#locale_attr(attr_name) ⇒ Object



29
30
31
# File 'lib/kuhsaft/translatable.rb', line 29

def locale_attr attr_name
  "#{attr_name}_#{I18n.locale}"
end

#translate(*args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kuhsaft/translatable.rb', line 9

def translate *args
  args.each do |attr_name|
    define_method attr_name do
      send "#{attr_name}_#{I18n.locale}"
    end

    define_method "#{attr_name}?" do
      send "#{attr_name}_#{I18n.locale}?"
    end

    define_method "#{attr_name}=" do |val|
      send "#{attr_name}_#{I18n.locale}=", val
    end

    define_singleton_method "find_by_#{attr_name}" do |val|
      send "find_by_#{attr_name}_#{I18n.locale}", val
    end
  end
end