Module: ModelTranslations::InstanceMethods
- Defined in:
- lib/model_translations.rb
Instance Method Summary collapse
-
#clear_cached_translations ⇒ Object
before_validation.
- #translated_attributes ⇒ Object
-
#update_translations! ⇒ Object
after_save.
Instance Method Details
#clear_cached_translations ⇒ Object
before_validation
51 52 53 54 55 56 |
# File 'lib/model_translations.rb', line 51 def clear_cached_translations # clear related cached translated_attributes.each do |attribute| Rails.cache.delete "#{self.class.to_s.downcase}_translations.#{id}.#{attribute.first}.#{I18n.locale}" end end |
#translated_attributes ⇒ Object
46 47 48 |
# File 'lib/model_translations.rb', line 46 def translated_attributes @translated_attributes ||= {} end |
#update_translations! ⇒ Object
after_save
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/model_translations.rb', line 59 def update_translations! unless translated_attributes.empty? # update or create translation translation = translations.find_or_initialize_by_locale(I18n.locale.to_s) translated_attributes.each do |attribute, translation_string| translation.send("#{attribute}=", translation_string) end translation.save! end end |