Class: Translated::TranslatedTextField
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Translated::TranslatedTextField
- Defined in:
- app/models/translated/translated_text_field.rb
Instance Method Summary collapse
Instance Method Details
#for_locale(locale) ⇒ Object
17 18 19 |
# File 'app/models/translated/translated_text_field.rb', line 17 def for_locale(locale) content.fetch(locale.to_s, nil) end |
#set_locale(locale, value) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/translated/translated_text_field.rb', line 21 def set_locale(locale, value) locale = locale.to_s self.language = locale self.content ||= {} self.content[locale] = value @_needs_translations = content_changed? value end |
#update_translations ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/translated/translated_text_field.rb', line 32 def update_translations source = content[language] I18n.available_locales.each do |locale| next if locale == language.to_sym content[locale.to_s] = source.presence && Translator.new.translate(source, from: language, to: locale.to_s) end save! end |