transync 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 826e00df7c16d49a77a3ba40b53df4dae4932b53
4
- data.tar.gz: 3e7e2a8e1d46072b263450ececeadcd29ca29f05
3
+ metadata.gz: f11c17bb6bb01279bc8eadbdddff263cfdd781b7
4
+ data.tar.gz: ba5f4718b72927ad95d3413a70f11004532ddd1e
5
5
  SHA512:
6
- metadata.gz: 45d1d05c2d8e1384138a8fb883514dbdcc96bcd9c8fd507e05381b5b15c28f5141ca615fad9f62b49d3dff713dcbd8d3c2e27458f80241678df857dad364b457
7
- data.tar.gz: dab75e76add54fb2b670446a6f0a1db2895215eeab08db0e36801d1ff9a2b0fb05b7ca78950d3b46f035e063849246c87bdc5c80b809232dd2b127e389552346
6
+ metadata.gz: 92218c53c2be5315c7642f009f4b84c753c05340ceb8e5bdf2b4f338bec33d4e844975bc25b93a64c577820cd7f4422d9fab5c74070d39ed0836a35dd227fcdc
7
+ data.tar.gz: d4a2c10e8576748018de65c6ecf773d426f50bc3ea7080bc281324887e5a98ce285c1ced540405dc1a427907b0d0027ac7cffe67732997634dbc8d7df9ba9cd5
data/.gitignore CHANGED
@@ -17,7 +17,7 @@ test/version_tmp
17
17
  tmp
18
18
 
19
19
 
20
- settings.yml
20
+ transync.yml
21
21
  log/*.log*
22
22
  .idea
23
23
  .transync_log
data/README.md CHANGED
@@ -4,14 +4,14 @@
4
4
  gem install transync
5
5
  ```
6
6
 
7
- You need settings file to be named `settings.yml` and to be in same directory from which we are running `transync` command.
8
- For example see `settings.SAMPLE.yml`.
7
+ You need settings file to be named `transync.yml` and to be in same directory from which we are running `transync` command.
8
+ For example see `transync.SAMPLE.yml`.
9
9
 
10
10
  ### Process
11
11
 
12
12
  - Create new Google Doc Spreadsheet
13
- - Copy it's `key` from URL to `settings.yml`
14
- - Set all the languages and `xliff` you want to sync in `settings.yml` (look at `settings.SAMPLE.yml`)
13
+ - Copy it's `key` from URL to `transync.yml`
14
+ - Set all the languages and `xliff` you want to sync in `transync.yml` (look at `transync.SAMPLE.yml`)
15
15
  - set `XLIFF_FILES_PATH` to set path where are your `xliff` files. In project do it with relative path so others can use it
16
16
  - set `MISSING_TRANSLATION_TEXT` to set what text should go to `target` element for translation
17
17
  - run these commands respectively
@@ -49,4 +49,4 @@ Gem docs available at http://gimite.net/doc/google-drive-ruby
49
49
 
50
50
  # Known issues
51
51
 
52
- It won't add keys as it should if not all languages are set in settings.yml
52
+ It won't add keys as it should if not all languages are set in transync.yml
File without changes
@@ -2,17 +2,21 @@ module GdocTrans
2
2
  WORKSHEET_COLUMNS = { key: 1 }
3
3
  START_ROW = 2
4
4
 
5
- CONFIG = YAML.load(File.open('settings.yml'))
5
+ begin
6
+ CONFIG = YAML.load(File.open('transync.yml'))
7
+ rescue
8
+ p 'File transync.yml does not exist'
9
+ exit(1)
10
+ end
6
11
 
7
- # populate languages dynamically from settings.yml
12
+ # populate languages dynamically from settings yaml file
8
13
  CONFIG['LANGUAGES'].each_with_index do |language, index|
9
14
  key = language
10
- value = index + 2 #
11
-
15
+ value = index + 2
12
16
  WORKSHEET_COLUMNS[key.to_sym] = value
13
17
  end
14
18
 
15
19
  # Result of WORKSHEET_COLUMNS should be something like this
16
- # depends on LANGUAGES set in settings.yml
20
+ # depends on LANGUAGES set in settings yaml file
17
21
  # WORKSHEET_COLUMNS = { key: 1, en: 2, de: 3 }
18
22
  end
@@ -1,5 +1,4 @@
1
1
  require 'yaml'
2
- require 'logger'
3
2
  require_relative '../gdoc_trans/gdoc_trans_reader'
4
3
  require_relative '../xliff_trans/xliff_trans_writer'
5
4
  require_relative 'gdoc_to_xliff'
@@ -11,11 +10,10 @@ class Gdoc2XliffMain
11
10
  def initialize(path)
12
11
  @path = path
13
12
  @config = GdocTrans::CONFIG
13
+ SyncUtil.create_logger('gdoc2xliff')
14
14
  end
15
15
 
16
16
  def run
17
- logger = Logger.new('.transync_log/gdoc2xliff.log', 'monthly')
18
-
19
17
  @config['FILES'].each do |file|
20
18
  xliff_translations = SyncUtil::check_and_get_xliff_files(@config['LANGUAGES'], path, file)
21
19
  gdoc_trans_reader = GdocTransReader.new(@config['GDOC'], file)
@@ -24,8 +22,7 @@ class Gdoc2XliffMain
24
22
  options = {
25
23
  xliff_translations: xliff_translations,
26
24
  gdoc_trans_reader: gdoc_trans_reader,
27
- language: language,
28
- logger: logger
25
+ language: language
29
26
  }
30
27
 
31
28
  gdoc_to_xliff = GdocToXliff.new(options)
@@ -33,7 +30,8 @@ class Gdoc2XliffMain
33
30
 
34
31
  xliff_trans_writer = XliffTransWriter.new(path, file, new_xliff_hash)
35
32
  xliff_trans_writer.save if dirty
36
- p "#{file} (#{language}) was clean. Already has same keys and values inside Xliff" unless dirty
33
+
34
+ SyncUtil.info_clean(file, language, 'was clean. Already has same keys and values inside Xliff') unless dirty
37
35
  end
38
36
  end
39
37
  end
@@ -1,14 +1,14 @@
1
+ require_relative 'sync_util'
2
+
1
3
  class GdocToXliff
2
4
  attr_accessor :xliff_translations,
3
5
  :gdoc_trans_reader,
4
- :language,
5
- :logger
6
+ :language
6
7
 
7
8
  def initialize(options = {})
8
9
  self.xliff_translations = options[:xliff_translations]
9
10
  self.gdoc_trans_reader = options[:gdoc_trans_reader]
10
11
  self.language = options[:language]
11
- self.logger = options[:logger]
12
12
  end
13
13
 
14
14
  def sync
@@ -28,14 +28,12 @@ class GdocToXliff
28
28
 
29
29
  # whole key is missing
30
30
  if x_trans.nil?
31
- p "Adding Key: #{gdoc_trans[:key]} to #{file}(#{language}) and value '#{gdoc_trans[:value]}'"
32
- logger.info "Adding Key: #{gdoc_trans[:key]} to #{file}(#{language}) and value '#{gdoc_trans[:value]}'"
31
+ SyncUtil.info_diff(file, language, 'Adding', gdoc_trans)
33
32
 
34
33
  new_xliff_hash[:translations] << gdoc_trans
35
34
  dirty = true
36
35
  elsif gdoc_trans[:value] != x_trans[:value]
37
- p "Changing #{file}(#{language}) #{gdoc_trans[:key]}: '#{x_trans[:value]}' to '#{gdoc_trans[:value]}'"
38
- logger.info "Changing #{file}(#{language}) #{gdoc_trans[:key]}: '#{x_trans[:value]}' to '#{gdoc_trans[:value]}'"
36
+ SyncUtil.info_diff(file, language, 'Changing', gdoc_trans)
39
37
 
40
38
  x_trans[:value] = gdoc_trans[:value]
41
39
  new_xliff_hash[:translations] << x_trans
@@ -1,5 +1,4 @@
1
1
  require 'yaml'
2
- require 'logger'
3
2
  require_relative '../gdoc_trans/gdoc_trans_writer'
4
3
  require_relative 'xliff_to_gdoc'
5
4
 
@@ -19,8 +18,11 @@ class Init
19
18
  spreadsheet = session.spreadsheet_by_key(@gdoc_access['key'])
20
19
 
21
20
  @config['FILES'].each do |file|
22
- worksheet = spreadsheet.add_worksheet(file)
23
- p "Adding #{file} worksheet to spreadsheet with first row (key and languages)"
21
+ worksheet = spreadsheet.worksheets.select { |s| s.title == file }.first
22
+ if worksheet.nil?
23
+ worksheet = spreadsheet.add_worksheet(file)
24
+ p "Adding #{file} worksheet to spreadsheet with first row (key and languages)"
25
+ end
24
26
 
25
27
  worksheet[1, 1] = 'Key'
26
28
  @config['LANGUAGES'].each_with_index do |language, index|
@@ -1,3 +1,4 @@
1
+ require 'logger'
1
2
  require_relative '../xliff_trans/xliff_trans_reader'
2
3
 
3
4
  module SyncUtil
@@ -21,4 +22,24 @@ module SyncUtil
21
22
  xliff_translations
22
23
  end
23
24
 
25
+ def self.info_clean(file, language, message)
26
+ msg = "#{file} (#{language}) - #{message}"
27
+ SyncUtil.log_and_puts(msg)
28
+ end
29
+
30
+ def self.info_diff(file, language, operation, trans)
31
+ msg = "#{file} (#{language}) - #{operation}: '#{trans[:key]}' => '#{trans[:value]}'"
32
+ SyncUtil.log_and_puts(msg)
33
+ end
34
+
35
+ def self.log_and_puts(msg)
36
+ p msg
37
+ @logger.info msg
38
+ end
39
+
40
+ def self.create_logger(direction)
41
+ # gdoc2xliff or xliff2gdoc
42
+ @logger = Logger.new(".transync_log/#{direction}.log", 'monthly')
43
+ end
44
+
24
45
  end
@@ -1,5 +1,4 @@
1
1
  require 'yaml'
2
- require 'logger'
3
2
  require_relative '../gdoc_trans/gdoc_trans_reader'
4
3
  require_relative '../gdoc_trans/gdoc_trans_writer'
5
4
  require_relative 'xliff_to_gdoc'
@@ -11,11 +10,10 @@ class Xliff2GdocMain
11
10
  def initialize(path)
12
11
  @path = path
13
12
  @config = GdocTrans::CONFIG
13
+ SyncUtil.create_logger('xliff2gdoc')
14
14
  end
15
15
 
16
16
  def run
17
- logger = Logger.new('.transync_log/xliff2gdoc.log', 'monthly')
18
-
19
17
  @config['FILES'].each do |file|
20
18
  xliff_translations = SyncUtil::check_and_get_xliff_files(@config['LANGUAGES'], path, file)
21
19
 
@@ -28,15 +26,14 @@ class Xliff2GdocMain
28
26
  gdoc_trans_reader: gdoc_trans_reader,
29
27
  gdoc_trans_writer: gdoc_trans_writer,
30
28
  language: language,
31
- languages: @config['LANGUAGES'],
32
- logger: logger
29
+ languages: @config['LANGUAGES']
33
30
  }
34
31
  xliff_to_gdoc = XliffToGdoc.new(options)
35
32
  dirty = xliff_to_gdoc.sync
36
33
 
37
34
  # save it back on google drive
38
35
  gdoc_trans_writer.worksheet.save if dirty
39
- p "#{file} (#{language}) was clean. Already has same keys and values inside GDoc" unless dirty
36
+ SyncUtil.info_clean(file, language, 'was clean. Already has same keys and values inside GDoc') unless dirty
40
37
  end
41
38
  end
42
39
  end
@@ -1,3 +1,5 @@
1
+ require_relative 'sync_util'
2
+
1
3
  class XliffToGdoc
2
4
  attr_accessor :xliff_translations,
3
5
  :gdoc_trans_reader,
@@ -12,7 +14,6 @@ class XliffToGdoc
12
14
  self.gdoc_trans_writer = options[:gdoc_trans_writer]
13
15
  self.language = options[:language]
14
16
  self.languages = options[:languages]
15
- self.logger = options[:logger]
16
17
  end
17
18
 
18
19
  def sync
@@ -37,8 +38,7 @@ class XliffToGdoc
37
38
  gdoc_trans_writer.write(current_row, 'key', x_trans[:key])
38
39
  gdoc_trans_writer.write(current_row, language, x_trans[:value])
39
40
 
40
- p "#{current_row}) Adding Key: #{x_trans[:key]} to #{file}(#{language}) and value '#{x_trans[:value]}'"
41
- logger.info "#{current_row}) Adding Key: #{x_trans[:key]} to #{file}(#{language}) and value '#{x_trans[:value]}'"
41
+ SyncUtil.info_diff(file, language, 'Adding', x_trans)
42
42
 
43
43
  # Go for all other languages if key was missing
44
44
  languages.each do |key_lang|
@@ -53,9 +53,7 @@ class XliffToGdoc
53
53
  dirty = true
54
54
  elsif gdoc_trans[:value] != x_trans[:value]
55
55
  gdoc_trans_writer.write(current_row, language, x_trans[:value])
56
-
57
- p "#{current_row}) Changing #{file}(#{language}) #{x_trans[:key]}: '#{gdoc_trans[:value]}' to '#{x_trans[:value]}'"
58
- logger.info "#{current_row}) Changing #{file}(#{language}) #{x_trans[:key]}: '#{gdoc_trans[:value]}' to '#{x_trans[:value]}'"
56
+ SyncUtil.info_diff(file, language, 'Changing', x_trans)
59
57
  dirty = true
60
58
  end
61
59
  end
@@ -63,4 +61,4 @@ class XliffToGdoc
63
61
  dirty
64
62
  end
65
63
 
66
- end
64
+ end
@@ -1,3 +1,3 @@
1
1
  module Transync
2
- VERSION = '0.1.1'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -12,7 +12,7 @@
12
12
  </trans-unit>
13
13
  <trans-unit id="end_test">
14
14
  <source>end_test</source>
15
- <target>End-Test</target>
15
+ <target>xxx</target>
16
16
  </trans-unit>
17
17
  </body>
18
18
  </file>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
3
+ <file source-language="de" datatype="plaintext" original="file.ext">
4
+ <body>
5
+ <trans-unit id="title">
6
+ <source>title</source>
7
+ <target>Titel</target>
8
+ </trans-unit>
9
+ <trans-unit id="round">
10
+ <source>round</source>
11
+ <target>Rund</target>
12
+ </trans-unit>
13
+ <trans-unit id="end_test">
14
+ <source>end_test</source>
15
+ <target>End-Test</target>
16
+ </trans-unit>
17
+ </body>
18
+ </file>
19
+ </xliff>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
3
+ <file source-language="de" datatype="plaintext" original="file.ext">
4
+ <body>
5
+ <trans-unit id="title">
6
+ <source>title</source>
7
+ <target>Titel</target>
8
+ </trans-unit>
9
+ <trans-unit id="round">
10
+ <source>round</source>
11
+ <target>Rund</target>
12
+ </trans-unit>
13
+ <trans-unit id="end_test">
14
+ <source>end_test</source>
15
+ <target>End-Test</target>
16
+ </trans-unit>
17
+ </body>
18
+ </file>
19
+ </xliff>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zigomir
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-04 00:00:00.000000000 Z
11
+ date: 2013-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google_drive
@@ -94,9 +94,11 @@ files:
94
94
  - lib/transync/version.rb
95
95
  - lib/transync/xliff_trans/xliff_trans_reader.rb
96
96
  - lib/transync/xliff_trans/xliff_trans_writer.rb
97
- - settings.SAMPLE.yml
98
97
  - test/fixtures/test.de.xliff
99
98
  - test/fixtures/test.en.xliff
99
+ - test/fixtures/validators.de.xliff
100
+ - test/fixtures/validators.en.xliff
101
+ - transync.SAMPLE.yml
100
102
  - transync.gemspec
101
103
  homepage: ''
102
104
  licenses:
@@ -118,11 +120,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
120
  version: '0'
119
121
  requirements: []
120
122
  rubyforge_project:
121
- rubygems_version: 2.0.3
123
+ rubygems_version: 2.0.2
122
124
  signing_key:
123
125
  specification_version: 4
124
126
  summary: Synchronize XLIFF translations with Google Drive document
125
127
  test_files:
126
128
  - test/fixtures/test.de.xliff
127
129
  - test/fixtures/test.en.xliff
128
- has_rdoc:
130
+ - test/fixtures/validators.de.xliff
131
+ - test/fixtures/validators.en.xliff