class TranslationSync
Public Class Methods
new(path, direction, file = nil)
click to toggle source
# File lib/transync/sync/translation_sync.rb, line 8 def initialize(path, direction, file = nil) @path = path @file = file @config = TransyncConfig::CONFIG SyncUtil.create_logger(direction) end
Public Instance Methods
diff(language)
click to toggle source
# File lib/transync/sync/translation_sync.rb, line 58 def diff(language) gdoc_trans_reader = GdocTransReader.new(@file) xliff_trans_reader = XliffTransReader.new(@path, @file, nil) g_trans_hash = gdoc_trans_reader.translations(language) x_trans_hash = xliff_trans_reader.translations(language) diff = x_trans_hash[:translations].diff(g_trans_hash[:translations]) SyncUtil.info_diff(@file, language, diff, true) diff end
run(direction)
click to toggle source
# File lib/transync/sync/translation_sync.rb, line 15 def run(direction) @config['FILES'].each do |file| xliff_files = XliffTransReader.new(@path, file, @config['LANGUAGES']) abort('Fix your Xliff translations by hand or run transync update!') unless xliff_files.valid? gdoc_trans_reader = GdocTransReader.new(file) gdoc_trans_writer = GdocTransWriter.new(gdoc_trans_reader.worksheet) xliff_trans_writer = XliffTransWriter.new(@path, file) @config['LANGUAGES'].each do |language| trans_sync = TranslationSync.new(@path, direction, file) trans_hash = trans_sync.sync(language, direction) if direction == 'x2g' gdoc_trans_writer.write(trans_hash) else xliff_trans_writer.write(trans_hash) end end end end
sync(language, direction)
click to toggle source
# File lib/transync/sync/translation_sync.rb, line 37 def sync(language, direction) gdoc_trans_reader = GdocTransReader.new(@file) xliff_trans_reader = XliffTransReader.new(@path, @file, nil) # we dont need languages for translations method g_trans_hash = gdoc_trans_reader.translations(language) x_trans_hash = xliff_trans_reader.translations(language) # We need to merge on translations hash, not whole hash since it will only merge first level if direction == 'x2g' merged_translations = g_trans_hash[:translations].merge(x_trans_hash[:translations]) diff = x_trans_hash[:translations].diff(g_trans_hash[:translations]) SyncUtil.info_diff(@file, language, diff) else merged_translations = x_trans_hash[:translations].merge(g_trans_hash[:translations]) diff = g_trans_hash[:translations].diff(x_trans_hash[:translations]) SyncUtil.info_diff(@file, language, diff) end {file: @file, language: language, translations: merged_translations} end