Class: I18n::Tasks::Translators::OpenAiTranslator

Inherits:
BaseTranslator show all
Defined in:
lib/i18n/tasks/translators/openai_translator.rb

Constant Summary collapse

BATCH_SIZE =

max allowed texts per request

50

Constants included from Logging

Logging::MUTEX, Logging::PROGRAM_NAME

Instance Method Summary collapse

Methods inherited from BaseTranslator

#translate_forest

Methods included from Logging

log_error, log_stderr, log_verbose, log_warn, program_name, warn_deprecated

Constructor Details

#initializeOpenAiTranslator

Returns a new instance of OpenAiTranslator.



10
11
12
13
14
15
16
17
# File 'lib/i18n/tasks/translators/openai_translator.rb', line 10

def initialize(*)
  begin
    require 'openai'
  rescue LoadError
    raise ::I18n::Tasks::CommandError, "Add gem 'ruby-openai' to your Gemfile to use this command"
  end
  super
end

Instance Method Details

#no_results_error_messageObject



34
35
36
# File 'lib/i18n/tasks/translators/openai_translator.rb', line 34

def no_results_error_message
  I18n.t('i18n_tasks.openai_translate.errors.no_results')
end

#options_for_htmlObject



26
27
28
# File 'lib/i18n/tasks/translators/openai_translator.rb', line 26

def options_for_html
  {}
end

#options_for_plainObject



30
31
32
# File 'lib/i18n/tasks/translators/openai_translator.rb', line 30

def options_for_plain
  {}
end

#options_for_translate_values(from:, to:, **options) ⇒ Object



19
20
21
22
23
24
# File 'lib/i18n/tasks/translators/openai_translator.rb', line 19

def options_for_translate_values(from:, to:, **options)
  options.merge(
    from: from,
    to: to
  )
end