Class: ItemTranslationWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/workers/item_translation_worker.rb

Overview

Sidekiq worker: item translation.

Instance Method Summary collapse

Instance Method Details

#perform(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

    job options (string keys)

Options Hash (options):

  • item_id (Integer)
  • locales (Array<String>)

    locales to translate into (default: all)

  • reset_previous_values (Boolean)

    discard existing translations and retranslate

  • specs (Boolean)

    translate product specifications

  • attributes (Boolean)

    translate attributes



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/workers/item_translation_worker.rb', line 15

def perform(options = {})
  item_id = options['item_id']
  locales = options['locales'].presence
  reset_previous_values = options['reset_previous_values'].to_b
  if item_id && (item = Item.find(item_id))
    if options['specs'].to_b
      item.auto_translate_product_specifications(reset_previous_values: reset_previous_values, locales: locales)
      item.update_rendered_product_specifications
    end
    item.auto_translate_attributes(reset_previous_values: reset_previous_values, locales: locales) if options['attributes'].to_b
  end
end