transync 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -16
- data/bin/transync +1 -1
- data/lib/hash.rb +12 -0
- data/lib/transync.rb +2 -2
- data/lib/transync/sync/sync_util.rb +25 -4
- data/lib/transync/sync/translation_sync.rb +13 -4
- data/lib/transync/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90302f66b201067dffbb9b3e55eded34a9d2bac1
|
4
|
+
data.tar.gz: 7a921bf6c24b68d4b5f94dbf472b9986d5d01c18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b3107c28d578555752291db1afe9023052c9e55e01407f51252b1eca986be2605a17d11e527508948dc31f01bb9394b5540687798407f82ca91e2de77697411
|
7
|
+
data.tar.gz: 60f2a4823fc51abd6b8855e16801ecc49ec2ce7529e0795566afa40aec9f2c090124a7b0a125666a9c8f8864ba4424e8bab630bcc0a924c958d51ce2238b57cc
|
data/README.md
CHANGED
@@ -7,6 +7,16 @@ gem install transync
|
|
7
7
|
You need settings file to be named `transync.yml` and to be in same directory from which we are running `transync` command.
|
8
8
|
For example see `transync.SAMPLE.yml`.
|
9
9
|
|
10
|
+
## Assumptions
|
11
|
+
|
12
|
+
You have xliff files in one directory, named like: common.en.xliff where common is name of the file and also google doc
|
13
|
+
spreadsheet tab. en is language and you have google doc with structure where first row is key, language 1, language 2
|
14
|
+
|
15
|
+
## How does it work?
|
16
|
+
|
17
|
+
Updating GDoc from our xliff files. It won't delete any key, it will only add new or change existing ones. Same
|
18
|
+
for direction from Gdoc to xliff.
|
19
|
+
|
10
20
|
### Process
|
11
21
|
|
12
22
|
- Create new Google Doc Spreadsheet
|
@@ -28,27 +38,16 @@ transync x2g
|
|
28
38
|
transync g2x
|
29
39
|
```
|
30
40
|
|
31
|
-
###
|
41
|
+
### Gem development
|
32
42
|
|
33
43
|
```
|
34
|
-
rake install && transync test
|
44
|
+
rake install && transync x2g|g2x test
|
45
|
+
ruby g2x_spec.rb
|
46
|
+
ruby x2g_spec.rb
|
35
47
|
```
|
36
48
|
|
37
|
-
|
38
|
-
|
39
|
-
You have xliff files in one directory, named like: common.en.xliff where common is name of the file and also google doc
|
40
|
-
spreadsheet tab. en is language and you have google doc with structure where first row is key, language 1, language 2
|
41
|
-
|
42
|
-
# Features
|
43
|
-
|
44
|
-
Updating GDoc from our xliff files. It won't delete any key, it will only add new or change existing ones.
|
45
|
-
|
46
|
-
# Source
|
47
|
-
|
48
|
-
Gem docs available at http://gimite.net/doc/google-drive-ruby
|
49
|
+
When running with test as second argument, changes won't be written to files or spreadsheet.
|
49
50
|
|
50
51
|
# TODO
|
51
52
|
|
52
|
-
- more tests, edge cases
|
53
|
-
- more OOP
|
54
53
|
- update for more than 2 languages
|
data/bin/transync
CHANGED
data/lib/hash.rb
ADDED
data/lib/transync.rb
CHANGED
@@ -4,13 +4,13 @@ require_relative 'transync/sync/sync_util'
|
|
4
4
|
|
5
5
|
module Transync
|
6
6
|
|
7
|
-
def self.run(mode)
|
7
|
+
def self.run(mode, test = nil)
|
8
8
|
FileUtils.mkdir('.transync_log') unless Dir.exist?('.transync_log')
|
9
9
|
path = TransyncConfig::CONFIG['XLIFF_FILES_PATH']
|
10
10
|
|
11
11
|
if mode == 'x2g' or mode == 'g2x'
|
12
12
|
sync = TranslationSync.new(path, mode)
|
13
|
-
sync.run(mode)
|
13
|
+
sync.run(mode, test)
|
14
14
|
end
|
15
15
|
|
16
16
|
if mode == 'init'
|
@@ -26,14 +26,35 @@ module SyncUtil
|
|
26
26
|
SyncUtil.log_and_puts(msg)
|
27
27
|
end
|
28
28
|
|
29
|
-
def self.info_diff(file, language,
|
30
|
-
msg = "#{file} (#{language})
|
31
|
-
|
29
|
+
def self.info_diff(file, language, diff)
|
30
|
+
msg = "#{file} (#{language})"
|
31
|
+
if diff.empty?
|
32
|
+
msg += ' already has same keys and values'
|
33
|
+
else
|
34
|
+
msg = build_diff_print(diff, msg)
|
35
|
+
end
|
32
36
|
SyncUtil.log_and_puts(msg)
|
33
37
|
end
|
34
38
|
|
39
|
+
def self.build_diff_print(diff, msg)
|
40
|
+
begin
|
41
|
+
# get longest key and value
|
42
|
+
max_key_length = diff.keys.max { |a, b| a.length <=> b.length }.length
|
43
|
+
max_val_length = diff.values.max { |a, b| a[1].to_s.length <=> b[1].to_s.length }[1].length
|
44
|
+
rescue
|
45
|
+
max_key_length = 0
|
46
|
+
max_val_length = 0
|
47
|
+
end
|
48
|
+
|
49
|
+
diff.keys.each do |key|
|
50
|
+
operation = diff[key][1].nil? ? 'Adding' : 'Changing'
|
51
|
+
msg += "\n #{operation.ljust(8)} - #{key.ljust(max_key_length)}: '#{diff[key][1].to_s.ljust(max_val_length)}' => '#{diff[key][0]}' "
|
52
|
+
end
|
53
|
+
msg
|
54
|
+
end
|
55
|
+
|
35
56
|
def self.log_and_puts(msg)
|
36
|
-
|
57
|
+
puts msg
|
37
58
|
@logger.info msg
|
38
59
|
end
|
39
60
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative '../gdoc_trans/gdoc_trans_reader'
|
2
2
|
require_relative '../gdoc_trans/gdoc_trans_writer'
|
3
3
|
require_relative '../xliff_trans/xliff_trans_writer'
|
4
|
+
require_relative '../../hash'
|
4
5
|
|
5
6
|
class TranslationSync
|
6
7
|
|
@@ -11,7 +12,7 @@ class TranslationSync
|
|
11
12
|
SyncUtil.create_logger(direction)
|
12
13
|
end
|
13
14
|
|
14
|
-
def run(direction)
|
15
|
+
def run(direction, test)
|
15
16
|
@config['FILES'].each do |file|
|
16
17
|
valid, _ = SyncUtil::check_and_get_xliff_files(@config['LANGUAGES'], @path, file)
|
17
18
|
abort('Fix your Xliff translations first!') unless valid
|
@@ -20,6 +21,8 @@ class TranslationSync
|
|
20
21
|
trans_sync = TranslationSync.new(@path, direction, file)
|
21
22
|
trans_hash = trans_sync.sync(language, direction)
|
22
23
|
|
24
|
+
next if test == 'test' # if testing don't write to files or google doc
|
25
|
+
|
23
26
|
if direction == 'x2g'
|
24
27
|
gdoc_trans_reader = GdocTransReader.new(file)
|
25
28
|
gdoc_trans_writer = GdocTransWriter.new(gdoc_trans_reader.worksheet)
|
@@ -40,10 +43,16 @@ class TranslationSync
|
|
40
43
|
x_trans_hash = xliff_trans_reader.translations(language)
|
41
44
|
|
42
45
|
# We need to merge on translations hash, not whole hash since it will only merge first level
|
43
|
-
|
44
|
-
|
46
|
+
if direction == 'x2g'
|
47
|
+
merged_translations = g_trans_hash[:translations].merge(x_trans_hash[:translations])
|
48
|
+
diff = x_trans_hash[:translations].diff(g_trans_hash[:translations])
|
49
|
+
SyncUtil.info_diff(@file, language, diff)
|
50
|
+
else
|
51
|
+
merged_translations = x_trans_hash[:translations].merge(g_trans_hash[:translations])
|
52
|
+
diff = g_trans_hash[:translations].diff(x_trans_hash[:translations])
|
53
|
+
SyncUtil.info_diff(@file, language, diff)
|
54
|
+
end
|
45
55
|
|
46
|
-
merged_translations = direction == 'x2g' ? x2g_merged_translations : g2x_merged_translations
|
47
56
|
{file: @file, language: language, translations: merged_translations}
|
48
57
|
end
|
49
58
|
|
data/lib/transync/version.rb
CHANGED
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
|
+
version: 1.0.2
|
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-
|
11
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google_drive
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- bin/transync
|
84
|
+
- lib/hash.rb
|
84
85
|
- lib/transync.rb
|
85
86
|
- lib/transync/gdoc_trans/gdoc_trans_reader.rb
|
86
87
|
- lib/transync/gdoc_trans/gdoc_trans_writer.rb
|