Class: Konjak::Translator
- Inherits:
-
Object
- Object
- Konjak::Translator
- Includes:
- Mem
- Defined in:
- lib/konjak/translator.rb,
lib/konjak/translator/translated_string.rb
Defined Under Namespace
Classes: TranslatedString
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#src_lang ⇒ Object
readonly
Returns the value of attribute src_lang.
-
#target_lang ⇒ Object
readonly
Returns the value of attribute target_lang.
-
#tmx ⇒ Object
readonly
Returns the value of attribute tmx.
Instance Method Summary collapse
-
#initialize(tmx, src_lang, target_lang, **options) ⇒ Translator
constructor
A new instance of Translator.
- #translate(content) ⇒ Object
Constructor Details
#initialize(tmx, src_lang, target_lang, **options) ⇒ Translator
Returns a new instance of Translator.
12 13 14 15 16 17 |
# File 'lib/konjak/translator.rb', line 12 def initialize(tmx, src_lang, target_lang, **) @tmx = tmx @src_lang = src_lang @target_lang = target_lang = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/konjak/translator.rb', line 10 def end |
#src_lang ⇒ Object (readonly)
Returns the value of attribute src_lang.
10 11 12 |
# File 'lib/konjak/translator.rb', line 10 def src_lang @src_lang end |
#target_lang ⇒ Object (readonly)
Returns the value of attribute target_lang.
10 11 12 |
# File 'lib/konjak/translator.rb', line 10 def target_lang @target_lang end |
#tmx ⇒ Object (readonly)
Returns the value of attribute tmx.
10 11 12 |
# File 'lib/konjak/translator.rb', line 10 def tmx @tmx end |
Instance Method Details
#translate(content) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/konjak/translator.rb', line 19 def translate(content) segmentor(content).segments.map do |text| next text unless text.is_a?(TmxSegmentor::SegmentString) source_segment = text.segment target_segment = source_segment.translation_unit.variant(target_lang).segment if format == :gtt_html = source_segment.(text) translated_string = target_segment.() TranslatedString.new(translated_string, text) else TranslatedString.new(target_segment.text, text) end end end |