Class: I18n::Tasks::Translators::OpenAiTranslator
- Inherits:
-
BaseTranslator
- Object
- BaseTranslator
- I18n::Tasks::Translators::OpenAiTranslator
- Defined in:
- lib/i18n/tasks/translators/openai_translator.rb
Constant Summary collapse
- BATCH_SIZE =
max allowed texts per request
50
- DEFAULT_SYSTEM_PROMPT =
<<~PROMPT.squish You are a professional translator that translates content from the %{from} locale to the %{to} locale in an i18n locale array. The array has a structured format and contains multiple strings. Your task is to translate each of these strings and create a new array with the translated strings. HTML markups (enclosed in < and > characters) must not be changed under any circumstance. Variables (starting with %%{ and ending with }) must not be changed under any circumstance. Keep in mind the context of all the strings for a more accurate translation. PROMPT
Constants included from Logging
Logging::MUTEX, Logging::PROGRAM_NAME
Instance Method Summary collapse
-
#initialize ⇒ OpenAiTranslator
constructor
A new instance of OpenAiTranslator.
- #no_results_error_message ⇒ Object
- #options_for_html ⇒ Object
- #options_for_plain ⇒ Object
- #options_for_translate_values(from:, to:, **options) ⇒ Object
Methods inherited from BaseTranslator
Methods included from Logging
log_error, log_stderr, log_verbose, log_warn, program_name, warn_deprecated
Constructor Details
#initialize ⇒ OpenAiTranslator
Returns a new instance of OpenAiTranslator.
23 24 25 26 27 28 29 30 |
# File 'lib/i18n/tasks/translators/openai_translator.rb', line 23 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_message ⇒ Object
47 48 49 |
# File 'lib/i18n/tasks/translators/openai_translator.rb', line 47 def I18n.t('i18n_tasks.openai_translate.errors.no_results') end |
#options_for_html ⇒ Object
39 40 41 |
# File 'lib/i18n/tasks/translators/openai_translator.rb', line 39 def {} end |
#options_for_plain ⇒ Object
43 44 45 |
# File 'lib/i18n/tasks/translators/openai_translator.rb', line 43 def {} end |
#options_for_translate_values(from:, to:, **options) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/i18n/tasks/translators/openai_translator.rb', line 32 def (from:, to:, **) .merge( from: from, to: to ) end |