Class: Alchemy::Translations::EssenceBodyUpdater

Inherits:
Object
  • Object
show all
Defined in:
app/models/alchemy/translations/essence_body_updater.rb

Instance Method Summary collapse

Instance Method Details

#update_bodies(translations) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/alchemy/translations/essence_body_updater.rb', line 5

def update_bodies(translations)
  binding.pry
  Rails.logger.info "Updating essences with #{translations}"

  locales = translations.keys

  locales.each do |locale|
    all_translated_content.each do |content|
      begin
        next unless locale == content.essence.element.page.language.language_code
        # do we have a translation for this alchemy essence?
        if translation = translations[locale][TRANSLATION_PREFIX][content.name]
          Rails.logger.info "Updating essence: #{content.name}"
          content.essence.update_attributes(body: translation)
        else
          Rails.logger.info "Skipping essence: #{content.name} b/c no new translation"
          next
        end

      rescue => e
        Rails.logger.error "Error in Alchemy update_bodies for content: #{content}: #{e}"
      end
    end
  end
end