Class: Translatomatic::TranslationResult
- Inherits:
-
Object
- Object
- Translatomatic::TranslationResult
- Includes:
- Util
- Defined in:
- lib/translatomatic/translation_result.rb
Overview
Stores results of a translation
Instance Attribute Summary collapse
-
#file ⇒ Translatomatic::ResourceFile::Base
readonly
The resource file.
-
#from_locale ⇒ Locale
readonly
The locale of the original strings.
-
#properties ⇒ Hash<String,String>
readonly
Translation results.
-
#to_locale ⇒ Locale
readonly
The target locale.
-
#untranslated ⇒ Set<String>
readonly
Untranslated strings.
Instance Method Summary collapse
-
#initialize(file, to_locale) ⇒ TranslationResult
constructor
Create a translation result.
-
#update_strings(translations) ⇒ void
Update result with a list of translated strings.
Constructor Details
#initialize(file, to_locale) ⇒ TranslationResult
Create a translation result
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/translatomatic/translation_result.rb', line 25 def initialize(file, to_locale) @file = file @value_to_keys = {} @untranslated = Set.new @from_locale = file.locale @to_locale = to_locale # duplicate strings @properties = file.properties.transform_values { |i| i.dup } @properties.each do |key, value| # split property value into sentences string = string(value, from_locale) string.sentences.each do |sentence| @untranslated << sentence keylist = (@value_to_keys[sentence.to_s] ||= []) keylist << key end end end |
Instance Attribute Details
#file ⇒ Translatomatic::ResourceFile::Base (readonly)
Returns The resource file.
8 9 10 |
# File 'lib/translatomatic/translation_result.rb', line 8 def file @file end |
#from_locale ⇒ Locale (readonly)
Returns The locale of the original strings.
14 15 16 |
# File 'lib/translatomatic/translation_result.rb', line 14 def from_locale @from_locale end |
#properties ⇒ Hash<String,String> (readonly)
Returns Translation results.
11 12 13 |
# File 'lib/translatomatic/translation_result.rb', line 11 def properties @properties end |
#to_locale ⇒ Locale (readonly)
Returns The target locale.
17 18 19 |
# File 'lib/translatomatic/translation_result.rb', line 17 def to_locale @to_locale end |
#untranslated ⇒ Set<String> (readonly)
Returns Untranslated strings.
20 21 22 |
# File 'lib/translatomatic/translation_result.rb', line 20 def untranslated @untranslated end |
Instance Method Details
#update_strings(translations) ⇒ void
This method returns an undefined value.
Update result with a list of translated strings.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/translatomatic/translation_result.rb', line 49 def update_strings(translations) # sort translation list by largest offset first so that we replace # from the end of the string to the front, so substring offsets # are correct in the target string. #translations.sort_by! do |translation| # t1 = translation.original # t1.respond_to?(:offset) ? -t1.offset : 0 #end translations.sort_by! { |t| -t.original.offset } translations.each do |translation| update(translation.original, translation.result) end end |