Class: Decidim::Dev::DummyTranslator

Inherits:
Object
  • Object
show all
Defined in:
decidim-dev/lib/decidim/dev/dummy_translator.rb

Overview

This Dummy translator recieves the field value and the locale of the field which has to be translated. It returns the appended value for both. This is for testing only.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, field_name, text, target_locale, source_locale) ⇒ DummyTranslator

Returns a new instance of DummyTranslator.



12
13
14
15
16
17
18
# File 'decidim-dev/lib/decidim/dev/dummy_translator.rb', line 12

def initialize(resource, field_name, text, target_locale, source_locale)
  @resource = resource
  @field_name = field_name
  @text = text
  @target_locale = target_locale
  @source_locale = source_locale
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



10
11
12
# File 'decidim-dev/lib/decidim/dev/dummy_translator.rb', line 10

def field_name
  @field_name
end

#resourceObject (readonly)

Returns the value of attribute resource.



10
11
12
# File 'decidim-dev/lib/decidim/dev/dummy_translator.rb', line 10

def resource
  @resource
end

#source_localeObject (readonly)

Returns the value of attribute source_locale.



10
11
12
# File 'decidim-dev/lib/decidim/dev/dummy_translator.rb', line 10

def source_locale
  @source_locale
end

#target_localeObject (readonly)

Returns the value of attribute target_locale.



10
11
12
# File 'decidim-dev/lib/decidim/dev/dummy_translator.rb', line 10

def target_locale
  @target_locale
end

#textObject (readonly)

Returns the value of attribute text.



10
11
12
# File 'decidim-dev/lib/decidim/dev/dummy_translator.rb', line 10

def text
  @text
end

Instance Method Details

#translateObject



20
21
22
23
24
25
26
27
28
29
# File 'decidim-dev/lib/decidim/dev/dummy_translator.rb', line 20

def translate
  translated_text = "#{target_locale} - #{text}"

  MachineTranslationSaveJob.perform_later(
    resource,
    field_name,
    target_locale,
    translated_text
  )
end