Class: GdocToXliff
- Inherits:
-
Object
- Object
- GdocToXliff
- Defined in:
- lib/transync/sync/gdoc_to_xliff.rb
Instance Attribute Summary collapse
-
#gdoc_trans_reader ⇒ Object
Returns the value of attribute gdoc_trans_reader.
-
#language ⇒ Object
Returns the value of attribute language.
-
#xliff_translations ⇒ Object
Returns the value of attribute xliff_translations.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ GdocToXliff
constructor
A new instance of GdocToXliff.
- #sync ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ GdocToXliff
Returns a new instance of GdocToXliff.
8 9 10 11 12 |
# File 'lib/transync/sync/gdoc_to_xliff.rb', line 8 def initialize( = {}) self.xliff_translations = [:xliff_translations] self.gdoc_trans_reader = [:gdoc_trans_reader] self.language = [:language] end |
Instance Attribute Details
#gdoc_trans_reader ⇒ Object
Returns the value of attribute gdoc_trans_reader.
4 5 6 |
# File 'lib/transync/sync/gdoc_to_xliff.rb', line 4 def gdoc_trans_reader @gdoc_trans_reader end |
#language ⇒ Object
Returns the value of attribute language.
4 5 6 |
# File 'lib/transync/sync/gdoc_to_xliff.rb', line 4 def language @language end |
#xliff_translations ⇒ Object
Returns the value of attribute xliff_translations.
4 5 6 |
# File 'lib/transync/sync/gdoc_to_xliff.rb', line 4 def xliff_translations @xliff_translations end |
Instance Method Details
#sync ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/transync/sync/gdoc_to_xliff.rb', line 14 def sync dirty = false gdoc_tab_language = gdoc_trans_reader.build_trans_hash(language) file = gdoc_tab_language[:title] new_xliff_hash = { language: language, file: file, translations: [] } xliff_for_language = xliff_translations.detect{ |x| x[:language] == language }[:translations] gdoc_tab_language[:translations].each do |gdoc_trans| x_trans = xliff_for_language.detect{ |x| x[:key] == gdoc_trans[:key] } # whole key is missing if x_trans.nil? SyncUtil.info_diff(file, language, 'Adding', gdoc_trans) new_xliff_hash[:translations] << gdoc_trans dirty = true elsif gdoc_trans[:value] != x_trans[:value] SyncUtil.info_diff(file, language, 'Changing', gdoc_trans) x_trans[:value] = gdoc_trans[:value] new_xliff_hash[:translations] << x_trans dirty = true else # nothing new new_xliff_hash[:translations] << gdoc_trans end end return dirty, new_xliff_hash end |