Module: GlobalizeAccessorsWithLocaleSuffix

Defined in:
lib/ab_admin/hooks/globalize_locale_suffix_accessors.rb

Overview

add accessors with locale suffix like `title_en`, `title_de`

Instance Method Summary collapse

Instance Method Details

#define_translated_attr_reader(name) ⇒ Object


3
4
5
6
7
8
9
10
11
12
# File 'lib/ab_admin/hooks/globalize_locale_suffix_accessors.rb', line 3

def define_translated_attr_reader(name)
  super

  Globalize.available_locales.each do |locale|
    method_name = "#{name}_#{locale}"
    define_method method_name.to_sym do
      Globalize::Interpolation.interpolate(name, self, [locale])
    end
  end
end

#define_translated_attr_writer(name) ⇒ Object


14
15
16
17
18
19
20
21
22
# File 'lib/ab_admin/hooks/globalize_locale_suffix_accessors.rb', line 14

def define_translated_attr_writer(name)
  super

  Globalize.available_locales.each do |locale|
    define_method :"#{name}_#{locale}=" do |value|
      write_attribute(name, value, {locale: locale})
    end
  end
end