Module: Netfira::WebConnect::Model::Record::Translations
- Defined in:
- lib/netfira/web_connect/model/record/translations.rb
Overview
This module is mixed into records that have translations.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#get_translated_string(key) ⇒ Object
Called when getting a translated string, e.g.
- #locale ⇒ Object
-
#set_translated_string(key, value) ⇒ Object
Called when assigning a translated string, e.g.
Instance Method Details
#[](key) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/netfira/web_connect/model/record/translations.rb', line 25 def [](key) if translated_attribute_names.include? key.to_s get_translated_string key.to_sym else super key end end |
#[]=(key, value) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/netfira/web_connect/model/record/translations.rb', line 33 def []=(key, value) if translated_attribute_names.include? key.to_s set_translated_string key.to_sym, value else super key, value end end |
#get_translated_string(key) ⇒ Object
Called when getting a translated string, e.g. product.description
8 9 10 |
# File 'lib/netfira/web_connect/model/record/translations.rb', line 8 def get_translated_string(key) translated_string_for key end |
#locale ⇒ Object
21 22 23 |
# File 'lib/netfira/web_connect/model/record/translations.rb', line 21 def locale shop.locale end |
#set_translated_string(key, value) ⇒ Object
Called when assigning a translated string, e.g. product.description = ‘Stuff’
13 14 15 16 17 18 19 |
# File 'lib/netfira/web_connect/model/record/translations.rb', line 13 def set_translated_string(key, value) if Hash === value replace_translations_for key, value else translated_string_for(key)[nil] = value end end |