Class: Jekyll::L10n::LibreTranslator
- Inherits:
-
Object
- Object
- Jekyll::L10n::LibreTranslator
- Defined in:
- lib/jekyll-l10n/translation/libre_translator.rb
Overview
Translates compendium entries using the LibreTranslate API.
LibreTranslator integrates with the LibreTranslate API to automatically translate untranslated entries in compendium PO files. It handles batching, retries with exponential backoff, progress logging, and API error handling. Translations are written directly to POEntry objects in-place.
Key responsibilities:
-
Send translation requests to LibreTranslate API
-
Batch translations for efficiency
-
Handle API timeouts and failures with retries
-
Log translation progress at configurable intervals
-
Update POEntry msgstr with translated text
-
Parse JSON API responses
Defined Under Namespace
Classes: TranslationError
Instance Method Summary collapse
-
#initialize(config) ⇒ LibreTranslator
constructor
Initialize a new LibreTranslator.
-
#translate_compendium(po_entries, target_locale) ⇒ void
Translate a compendium to a target locale.
Constructor Details
#initialize(config) ⇒ LibreTranslator
Initialize a new LibreTranslator.
45 46 47 |
# File 'lib/jekyll-l10n/translation/libre_translator.rb', line 45 def initialize(config) @config = config end |
Instance Method Details
#translate_compendium(po_entries, target_locale) ⇒ void
This method returns an undefined value.
Translate a compendium to a target locale.
Identifies untranslated entries (empty msgstr) and sends them to LibreTranslate API for translation. Updates POEntry objects in-place with translated text. Handles batching, retries, and progress logging.
60 61 62 63 64 65 66 67 68 |
# File 'lib/jekyll-l10n/translation/libre_translator.rb', line 60 def translate_compendium(po_entries, target_locale) translatable_count, empty_entries = count_translatable_entries(po_entries) return if empty_entries.empty? log_translation_progress(empty_entries.length, translatable_count, target_locale) start_time = Time.now process_translation_batches(empty_entries, target_locale, start_time) log_translation_complete(empty_entries.length, target_locale, start_time) end |