Class: XliffToGdoc
- Inherits:
-
Object
- Object
- XliffToGdoc
- Defined in:
- lib/transync/sync/xliff_to_gdoc.rb
Instance Attribute Summary collapse
-
#gdoc_trans_reader ⇒ Object
Returns the value of attribute gdoc_trans_reader.
-
#gdoc_trans_writer ⇒ Object
Returns the value of attribute gdoc_trans_writer.
-
#language ⇒ Object
Returns the value of attribute language.
-
#languages ⇒ Object
Returns the value of attribute languages.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#xliff_translations ⇒ Object
Returns the value of attribute xliff_translations.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ XliffToGdoc
constructor
A new instance of XliffToGdoc.
- #sync ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ XliffToGdoc
Returns a new instance of XliffToGdoc.
11 12 13 14 15 16 17 |
# File 'lib/transync/sync/xliff_to_gdoc.rb', line 11 def initialize( = {}) self.xliff_translations = [:xliff_translations] self.gdoc_trans_reader = [:gdoc_trans_reader] self.gdoc_trans_writer = [:gdoc_trans_writer] self.language = [:language] self.languages = [:languages] end |
Instance Attribute Details
#gdoc_trans_reader ⇒ Object
Returns the value of attribute gdoc_trans_reader.
4 5 6 |
# File 'lib/transync/sync/xliff_to_gdoc.rb', line 4 def gdoc_trans_reader @gdoc_trans_reader end |
#gdoc_trans_writer ⇒ Object
Returns the value of attribute gdoc_trans_writer.
4 5 6 |
# File 'lib/transync/sync/xliff_to_gdoc.rb', line 4 def gdoc_trans_writer @gdoc_trans_writer end |
#language ⇒ Object
Returns the value of attribute language.
4 5 6 |
# File 'lib/transync/sync/xliff_to_gdoc.rb', line 4 def language @language end |
#languages ⇒ Object
Returns the value of attribute languages.
4 5 6 |
# File 'lib/transync/sync/xliff_to_gdoc.rb', line 4 def languages @languages end |
#logger ⇒ Object
Returns the value of attribute logger.
4 5 6 |
# File 'lib/transync/sync/xliff_to_gdoc.rb', line 4 def logger @logger end |
#xliff_translations ⇒ Object
Returns the value of attribute xliff_translations.
4 5 6 |
# File 'lib/transync/sync/xliff_to_gdoc.rb', line 4 def xliff_translations @xliff_translations end |
Instance Method Details
#sync ⇒ Object
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/transync/sync/xliff_to_gdoc.rb', line 19 def sync gdoc_tab_language = gdoc_trans_reader.build_trans_hash(language) dirty = false file = gdoc_tab_language[:title] xliff_for_language = xliff_translations.detect{ |x| x[:language] == language } xliff_for_language[:translations].each_with_index do |x_trans, index| # for current xliff translation find the same trans key in google doc gdoc_trans = gdoc_tab_language[:translations].detect{ |g_trans| g_trans[:key] == x_trans[:key] } current_row = index + GdocTrans::START_ROW # whole key is missing if gdoc_trans.nil? # heavy coupling gdoc_trans_reader.worksheet = gdoc_trans_writer.shift_up(current_row, xliff_for_language[:translations].length) # recalculate hashes after shift gdoc_tab_language = gdoc_trans_reader.build_trans_hash(language) gdoc_trans_writer.write(current_row, 'key', x_trans[:key]) gdoc_trans_writer.write(current_row, language, x_trans[:value]) SyncUtil.info_diff(file, language, 'Adding', x_trans) # Go for all other languages if key was missing languages.each do |key_lang| next if key_lang == language xliff_lang = xliff_translations.detect{ |xt| xt[:language] == key_lang } xliff_lang_value = xliff_lang[:translations].detect{ |xt| xt[:key] == x_trans[:key] } gdoc_trans_writer.write(current_row, key_lang, xliff_lang_value[:value]) end dirty = true elsif gdoc_trans[:value] != x_trans[:value] gdoc_trans_writer.write(current_row, language, x_trans[:value]) SyncUtil.info_diff(file, language, 'Changing', x_trans) dirty = true end end dirty end |