Class: I18nUno::Translator

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_uno/translator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sot_file, target_file) ⇒ Translator

Returns a new instance of Translator.



10
11
12
13
14
# File 'lib/i18n_uno/translator.rb', line 10

def initialize(sot_file, target_file)
  @source_file  = sot_file
  @target_file  = target_file
  @target_file_yaml = YAML.load_file(target_file.file_path)
end

Instance Attribute Details

#source_fileObject (readonly)

Returns the value of attribute source_file.



8
9
10
# File 'lib/i18n_uno/translator.rb', line 8

def source_file
  @source_file
end

#target_fileObject (readonly)

Returns the value of attribute target_file.



8
9
10
# File 'lib/i18n_uno/translator.rb', line 8

def target_file
  @target_file
end

Instance Method Details

#process(delta) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/i18n_uno/translator.rb', line 16

def process(delta)
  delta.values_from!(@source_file)

  if delta.anything_to_translate?
    delta = send_to_chatgpt_api(delta)

    target_file.add_missing_keys_to_target_file!(delta)
    target_file.match_order_as_file!(source_file)
    target_file.set_values_from_delta!(delta)
    target_file.save!
  else
    puts 'Missing keys are all null, nothing to translate'
  end
end