Class: GdocToXliff

Inherits:
Object
  • Object
show all
Defined in:
lib/transync/sync/gdoc_to_xliff.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  self.xliff_translations = options[:xliff_translations]
  self.gdoc_trans_reader = options[:gdoc_trans_reader]
  self.language = options[:language]
end

Instance Attribute Details

#gdoc_trans_readerObject

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

#languageObject

Returns the value of attribute language.



4
5
6
# File 'lib/transync/sync/gdoc_to_xliff.rb', line 4

def language
  @language
end

#xliff_translationsObject

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

#syncObject



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