transync 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bfe245154c8aada3e726245189aecbfcebe3896
4
- data.tar.gz: de3cd22e1225c0c2afde1535b786f01cf9c99751
3
+ metadata.gz: 34601981f1aed44be61c45090e3c7568a4f64768
4
+ data.tar.gz: 257f29d8a4f7e8a4bfce328a38c0ada09bbcae4d
5
5
  SHA512:
6
- metadata.gz: 8bb9cf85059b1a42ac17182f3ffa03a81bf701a758ef6d7ac5fd8d680ba37a4fac8ee6fcc121d6e861a1baea21d4a3c503b5f9db5567460fc9d2c1a34ce7e72c
7
- data.tar.gz: e46fbeb05285725e066193912aff6e6f8ce72007fae10c88a90cb429663303696e88163193617763c86506f80f6fd02ce1fabb5aafaa63e9822d6db0f15cdbf9
6
+ metadata.gz: 031fdec0240aa2a3a45e8b9808444715d533d82e0b586c94a0a201fffbfe83a7dfaf5fe39015dee18a29a7805bef9a7d0b67863b19bc2523bdd1732fdb30b303
7
+ data.tar.gz: d803d0a53df7ef47f4d724d9aef9ad2d2a50f27e72f6bce259be67cf2fce289422323622f0c49679529308a908203f0c58aca6ca5031c682a2a95f63a809967e
data/README.md CHANGED
@@ -29,9 +29,9 @@ for direction from Gdoc to xliff.
29
29
  ### Running order
30
30
 
31
31
  ```
32
- transync test # test if all keys are set for all the languages: no output means that no key is missing
32
+ transync test # test if all keys are set for all the languages. Also tests if everything in sync with GDoc
33
33
  transync update # will test and add all the missing keys that are not presented for a particular language
34
- transync init # will sync all translations with Google spreadsheet. You need to run update command first, to ensure no keys are missing.
34
+ transync init # will sync all translations with Google spreadsheet. You need to run update command first, to ensure no keys are missing
35
35
 
36
36
  # After init was made you have these two to sync between gdoc and xliff
37
37
  transync x2g
@@ -41,9 +41,13 @@ transync g2x
41
41
  ### Gem development
42
42
 
43
43
  ```
44
- rake install && transync x2g|g2x test
45
44
  ruby g2x_spec.rb
46
45
  ruby x2g_spec.rb
47
46
  ```
48
47
 
49
- When running with `test` as second argument, changes won't be written to files or spreadsheet.
48
+ ## TODO
49
+
50
+ - use ruby's 2.0 named parameters (more clear method calls)
51
+ - better tests (move out network dependency -> maybe try VCR)
52
+ - add to travis / code climate
53
+ - don't allow empty keys?
data/bin/transync CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'transync'
4
- Transync.run ARGV[0], ARGV[1]
4
+
5
+ FileUtils.mkdir('.transync_log') unless Dir.exist?('.transync_log')
6
+ Transync.run ARGV[0]
data/lib/transync.rb CHANGED
@@ -1,35 +1,16 @@
1
1
  require_relative 'transync/sync/translation_sync'
2
2
  require_relative 'transync/sync/init'
3
3
  require_relative 'transync/sync/sync_util'
4
+ require_relative 'transync/runner'
4
5
 
5
6
  module Transync
6
7
 
7
- def self.run(mode, test = nil)
8
- FileUtils.mkdir('.transync_log') unless Dir.exist?('.transync_log')
9
- path = TransyncConfig::CONFIG['XLIFF_FILES_PATH']
10
-
8
+ def self.run(mode)
11
9
  if mode == 'x2g' or mode == 'g2x'
12
- sync = TranslationSync.new(path, mode)
13
- sync.run(mode, test)
14
- end
15
-
16
- if mode == 'init'
17
- init = Init.new(path)
18
- init.run
19
- end
20
-
21
- if mode == 'test'
22
- TransyncConfig::CONFIG['FILES'].each do |file|
23
- xliff_files = XliffTransReader.new(path, file, TransyncConfig::CONFIG['LANGUAGES'])
24
- p "#{file} have all the keys for all languages." if xliff_files.valid?
25
- end
26
- end
27
-
28
- if mode == 'update'
29
- TransyncConfig::CONFIG['FILES'].each do |file|
30
- xliff_files = XliffTransReader.new(path, file, TransyncConfig::CONFIG['LANGUAGES'])
31
- xliff_files.fill_with_missing_keys
32
- end
10
+ Transync::Runner.sync(mode)
11
+ else
12
+ # will send message to (call) init, test, update
13
+ Transync::Runner.send(mode)
33
14
  end
34
15
  end
35
16
 
@@ -1,4 +1,5 @@
1
1
  require 'google_drive'
2
+ require 'colorize'
2
3
 
3
4
  class GdocTransWriter
4
5
 
@@ -9,7 +10,7 @@ class GdocTransWriter
9
10
  def write(trans_hash)
10
11
  language = trans_hash[:language]
11
12
  lang_column = get_language_column_index(language)
12
- abort("Language (#{language}) not found in worksheet (#{@worksheet.title})!") if lang_column == 0
13
+ abort("\u{2717} Language (#{language}) not found in worksheet '#{@worksheet.title}'!".colorize(:red)) if lang_column == 0
13
14
 
14
15
  row = 2
15
16
 
@@ -0,0 +1,54 @@
1
+ require 'colorize'
2
+
3
+ module Transync
4
+
5
+ # 2713 = unicode check mark
6
+ # 2717 = unicode cross mark
7
+ module Runner
8
+
9
+ PATH = TransyncConfig::CONFIG['XLIFF_FILES_PATH']
10
+
11
+ def self.sync(mode)
12
+ sync = TranslationSync.new(PATH, mode)
13
+ sync.run(mode)
14
+ end
15
+
16
+ def self.init
17
+ init = Init.new(PATH)
18
+ init.run
19
+ end
20
+
21
+ def self.test
22
+ TransyncConfig::CONFIG['FILES'].each do |file|
23
+ xliff_files = XliffTransReader.new(PATH, file, TransyncConfig::CONFIG['LANGUAGES'])
24
+ puts "\u{2713} '#{file}' have all the keys for all languages in XLIFF files.".colorize(:green) if xliff_files.valid?
25
+
26
+ TransyncConfig::CONFIG['LANGUAGES'].each do |language|
27
+ trans_sync = TranslationSync.new(PATH, 'test', file)
28
+
29
+ if trans_sync.diff(language).keys.length == 0
30
+ puts "\u{2713} '#{file}' is in sync for '#{language}' language with GDoc.".colorize(:green)
31
+ else
32
+ puts "\u{2717} '#{file}' is NOT in sync for '#{language}' language with GDoc. See diff!".colorize(:red)
33
+ end
34
+ end
35
+
36
+ puts '----------'
37
+ end
38
+ end
39
+
40
+ def self.update
41
+ TransyncConfig::CONFIG['FILES'].each do |file|
42
+ xliff_files = XliffTransReader.new(PATH, file, TransyncConfig::CONFIG['LANGUAGES'])
43
+ clean = xliff_files.fill_with_missing_keys
44
+
45
+ if clean
46
+ puts "\u{2713} '#{file}' already have all the keys in all the XLIFF files".colorize(:green)
47
+ else
48
+ puts "\u{2717} '#{file}' already DID NOT have all the keys in all the XLIFF files. But they were added automatically for you.".colorize(:red)
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+ end
@@ -8,17 +8,17 @@ module SyncUtil
8
8
  SyncUtil.log_and_puts(msg)
9
9
  end
10
10
 
11
- def self.info_diff(file, language, diff)
12
- msg = "#{file} (#{language})"
13
- if diff.empty?
14
- msg += ' already has same keys and values'
15
- else
16
- msg = build_diff_print(diff, msg)
11
+ def self.info_diff(file, language, diff, diff_only = nil)
12
+ msg = ''
13
+
14
+ unless diff.empty?
15
+ msg = "#{file} (#{language})\n" if not diff_only
16
+ msg = build_diff_print(diff, msg, diff_only)
17
17
  end
18
18
  SyncUtil.log_and_puts(msg)
19
19
  end
20
20
 
21
- def self.build_diff_print(diff, msg)
21
+ def self.build_diff_print(diff, msg, diff_only = nil)
22
22
  begin
23
23
  # get longest key and value
24
24
  max_key_length = diff.keys.max { |a, b| a.length <=> b.length }.length
@@ -28,15 +28,26 @@ module SyncUtil
28
28
  max_val_length = 0
29
29
  end
30
30
 
31
+ newline = ''
31
32
  diff.keys.each do |key|
32
- operation = diff[key][1].nil? ? 'Adding' : 'Changing'
33
- msg += "\n #{operation.ljust(8)} - #{key.ljust(max_key_length)}: '#{diff[key][1].to_s.ljust(max_val_length)}' => '#{diff[key][0]}' "
33
+ change_mark = ' => '
34
+ operation = diff[key][1].nil? ? 'adding' : 'changing'
35
+ ljust = 8
36
+
37
+ if diff_only
38
+ operation = 'diff'
39
+ change_mark = ' <=> '
40
+ ljust = 4
41
+ end
42
+
43
+ msg += "#{newline}[#{operation.ljust(ljust)}] #{key.ljust(max_key_length)}: '#{diff[key][1].to_s.ljust(max_val_length)}'#{change_mark}'#{diff[key][0]}' "
44
+ newline = "\n"
34
45
  end
35
46
  msg
36
47
  end
37
48
 
38
49
  def self.log_and_puts(msg)
39
- puts msg
50
+ puts msg unless msg.length == 0
40
51
  @logger.info msg
41
52
  end
42
53
 
@@ -12,7 +12,7 @@ class TranslationSync
12
12
  SyncUtil.create_logger(direction)
13
13
  end
14
14
 
15
- def run(direction, test)
15
+ def run(direction)
16
16
  @config['FILES'].each do |file|
17
17
  xliff_files = XliffTransReader.new(@path, file, @config['LANGUAGES'])
18
18
  abort('Fix your Xliff translations by hand or run transync update!') unless xliff_files.valid?
@@ -21,8 +21,6 @@ class TranslationSync
21
21
  trans_sync = TranslationSync.new(@path, direction, file)
22
22
  trans_hash = trans_sync.sync(language, direction)
23
23
 
24
- next if test == 'test' # if testing don't write to files or google doc
25
-
26
24
  if direction == 'x2g'
27
25
  gdoc_trans_reader = GdocTransReader.new(file)
28
26
  gdoc_trans_writer = GdocTransWriter.new(gdoc_trans_reader.worksheet)
@@ -56,4 +54,16 @@ class TranslationSync
56
54
  {file: @file, language: language, translations: merged_translations}
57
55
  end
58
56
 
57
+ def diff(language)
58
+ gdoc_trans_reader = GdocTransReader.new(@file)
59
+ xliff_trans_reader = XliffTransReader.new(@path, @file, nil)
60
+
61
+ g_trans_hash = gdoc_trans_reader.translations(language)
62
+ x_trans_hash = xliff_trans_reader.translations(language)
63
+
64
+ diff = x_trans_hash[:translations].diff(g_trans_hash[:translations])
65
+ SyncUtil.info_diff(@file, language, diff, true)
66
+ diff
67
+ end
68
+
59
69
  end
@@ -1,3 +1,3 @@
1
1
  module Transync
2
- VERSION = '1.0.4'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -44,6 +44,7 @@ class XliffTransReader
44
44
  missing_translation_text = TransyncConfig::CONFIG['MISSING_TRANSLATION_TEXT'] || '#MISSING-TRANS#'
45
45
  all_translations_for_language = {file: file, language: nil, translations: {}}
46
46
  added = false
47
+ clean = true
47
48
 
48
49
  check_all do |lang_a, lang_b, xliff_lang_value, x_trans_key, translations_lang_b, last| # x_trans_key comes from lang_a translations
49
50
  all_translations_for_language[:language] = lang_b
@@ -53,6 +54,7 @@ class XliffTransReader
53
54
  "was missing translation for key '#{x_trans_key}' => setting value: '#{missing_translation_text} - #{x_trans_key}'"
54
55
  all_translations_for_language[:translations][x_trans_key] = "#{missing_translation_text} - #{x_trans_key}"
55
56
  added = true
57
+ clean = false
56
58
  else
57
59
  all_translations_for_language[:translations][x_trans_key] = xliff_lang_value
58
60
  end
@@ -69,6 +71,9 @@ class XliffTransReader
69
71
  added = false
70
72
  end
71
73
  end
74
+
75
+ # return if any key was added
76
+ clean
72
77
  end
73
78
 
74
79
  def check_all
data/transync.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency 'google_drive'
22
22
  spec.add_runtime_dependency 'builder'
23
+ spec.add_runtime_dependency 'colorize'
23
24
 
24
25
  spec.add_development_dependency 'bundler', '~> 1.3'
25
26
  spec.add_development_dependency 'rake'
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: 1.0.4
4
+ version: 1.1.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-10-14 00:00:00.000000000 Z
11
+ date: 2013-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google_drive
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -85,6 +99,7 @@ files:
85
99
  - lib/transync.rb
86
100
  - lib/transync/gdoc_trans/gdoc_trans_reader.rb
87
101
  - lib/transync/gdoc_trans/gdoc_trans_writer.rb
102
+ - lib/transync/runner.rb
88
103
  - lib/transync/sync/init.rb
89
104
  - lib/transync/sync/sync_util.rb
90
105
  - lib/transync/sync/translation_sync.rb