Class: BetterTranslate::Strategies::DeepStrategy
- Inherits:
-
BaseStrategy
- Object
- BaseStrategy
- BetterTranslate::Strategies::DeepStrategy
- Defined in:
- lib/better_translate/strategies/deep_strategy.rb
Overview
Deep translation strategy
Translates each string individually with detailed progress tracking. Used for smaller files (< 50 strings) to provide more granular progress.
Instance Attribute Summary
Attributes inherited from BaseStrategy
#config, #progress_tracker, #provider
Instance Method Summary collapse
-
#translate(strings, target_lang_code, target_lang_name) ⇒ Hash
Translate strings individually.
Methods inherited from BaseStrategy
Constructor Details
This class inherits a constructor from BetterTranslate::Strategies::BaseStrategy
Instance Method Details
#translate(strings, target_lang_code, target_lang_name) ⇒ Hash
Translate strings individually
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/better_translate/strategies/deep_strategy.rb', line 26 def translate(strings, target_lang_code, target_lang_name) # @type var translated: Hash[String, String] translated = {} total = strings.size strings.each_with_index do |(key, value), index| progress_tracker.update( language: target_lang_name, current_key: key, progress: ((index + 1).to_f / total * 100.0).round(1).to_f ) translated[key] = provider.translate_text(value, target_lang_code, target_lang_name) end translated end |