Module: ActiveData::Model::Localizable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/active_data/model/localizable.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #read_localized_attribute(name, locale = self.class.locale) ⇒ Object (also: #read_localized_attribute_before_type_cast)
- #write_localized_attribute(name, value, locale = self.class.locale) ⇒ Object
Instance Method Details
#read_localized_attribute(name, locale = self.class.locale) ⇒ Object Also known as: read_localized_attribute_before_type_cast
19 20 21 22 |
# File 'lib/active_data/model/localizable.rb', line 19 def read_localized_attribute name, locale = self.class.locale translations = read_attribute(name.to_s) translations[self.class.fallbacks(locale).detect { |fallback| translations[fallback.to_s] }.to_s] end |
#write_localized_attribute(name, value, locale = self.class.locale) ⇒ Object
25 26 27 28 |
# File 'lib/active_data/model/localizable.rb', line 25 def write_localized_attribute name, value, locale = self.class.locale translations = read_attribute(name.to_s) write_attribute(name, translations.merge(locale.to_s => value)) end |