transync 0.0.1 → 0.1.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 +4 -4
- data/.ruby-version +1 -1
- data/README.md +27 -20
- data/bin/transync +3 -1
- data/lib/transync/gdoc_trans/gdoc_trans.rb +15 -2
- data/lib/transync/sync/gdoc_2_xliff_main.rb +2 -3
- data/lib/transync/sync/init.rb +39 -0
- data/lib/transync/sync/sync_util.rb +8 -4
- data/lib/transync/sync/xliff_2_gdoc_main.rb +2 -3
- data/lib/transync/version.rb +1 -1
- data/lib/transync/xliff_trans/xliff_trans_reader.rb +22 -4
- data/lib/transync/xliff_trans/xliff_trans_writer.rb +1 -1
- data/lib/transync.rb +21 -1
- data/settings.SAMPLE.yml +4 -8
- data/test/fixtures/test.de.xliff +19 -0
- data/test/fixtures/test.en.xliff +3 -27
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14ddaefea87d79fa54969295284ba7f048567d7b
|
4
|
+
data.tar.gz: 5f4e9e49694aafeab4a66ae6b850ff23c62c9d14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc8ee6a94f7ba1628db70c53760deaaa7b947c3dbdff2cdff73abdf07db01de8b8a035eba617a8fca8d1877239650305bfcd36d89e5e74d8f77fb7cc57f63b93
|
7
|
+
data.tar.gz: ed6b943d8c8564142d3654234110ee3431585f1c21272d5206736d2a31c455796081344bd15cf6d9cda6a34c5dab49edfcff23ad2641f1e7f062638fac309aaa
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0-
|
1
|
+
2.0.0-p247
|
data/README.md
CHANGED
@@ -1,31 +1,42 @@
|
|
1
1
|
# Install
|
2
2
|
|
3
|
-
|
3
|
+
```bash
|
4
|
+
gem install transync
|
5
|
+
```
|
4
6
|
|
5
|
-
You need settings file
|
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`.
|
6
9
|
|
7
|
-
###
|
10
|
+
### Process
|
8
11
|
|
9
|
-
|
10
|
-
|
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`).
|
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
|
+
- run these commands respectively
|
11
17
|
|
12
|
-
###
|
18
|
+
### Running order
|
13
19
|
|
14
|
-
|
20
|
+
```
|
21
|
+
transync test # test if all keys are set for all the languages: no output means that no key is missing
|
22
|
+
transync update # will test and add all the missing keys that are not presented for a particular language
|
23
|
+
transync init # will sync all translations with Google spreadsheet. You need to run update command first, to ensure no keys are missing.
|
15
24
|
|
16
|
-
#
|
25
|
+
# After init was made you have these two to sync between gdoc and xliff
|
26
|
+
transync x2g
|
27
|
+
transync g2x
|
28
|
+
```
|
17
29
|
|
18
|
-
|
19
|
-
spreadsheet tab. en is language and you have google doc with structure where first row is key, language 1, language 2
|
30
|
+
### Development on this gem
|
20
31
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
https://docs.google.com/a/astina.ch/spreadsheet/ccc?key=0ApAHdLDpSUFudHhuWU9vQ0ZPaWNoV3VxU045cXhHLWc#gid=3
|
25
|
-
key = 0ApAHdLDpSUFudHhuWU9vQ0ZPaWNoV3VxU045cXhHLWc
|
32
|
+
```
|
33
|
+
rake install && transync test
|
34
|
+
```
|
26
35
|
|
36
|
+
# Assumptions:
|
27
37
|
|
28
|
-
|
38
|
+
You have xliff files in one directory, named like: common.en.xliff where common is name of the file and also google doc
|
39
|
+
spreadsheet tab. en is language and you have google doc with structure where first row is key, language 1, language 2
|
29
40
|
|
30
41
|
# Features
|
31
42
|
|
@@ -38,7 +49,3 @@ Gem docs available at http://gimite.net/doc/google-drive-ruby
|
|
38
49
|
# Known issues
|
39
50
|
|
40
51
|
It won't add keys as it should if not all languages are set in settings.yml
|
41
|
-
|
42
|
-
# TODO
|
43
|
-
|
44
|
-
- support for yaml files
|
data/bin/transync
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
-
# TODO move also to yml file
|
2
1
|
module GdocTrans
|
3
|
-
WORKSHEET_COLUMNS = { key: 1
|
2
|
+
WORKSHEET_COLUMNS = { key: 1 }
|
4
3
|
START_ROW = 2
|
4
|
+
|
5
|
+
CONFIG = YAML.load(File.open('settings.yml'))
|
6
|
+
|
7
|
+
# populate languages dynamically from settings.yml
|
8
|
+
CONFIG['LANGUAGES'].each_with_index do |language, index|
|
9
|
+
key = language
|
10
|
+
value = index + 2 #
|
11
|
+
|
12
|
+
WORKSHEET_COLUMNS[key.to_sym] = value
|
13
|
+
end
|
14
|
+
|
15
|
+
# Result of WORKSHEET_COLUMNS should be something like this
|
16
|
+
# depends on LANGUAGES set in settings.yml
|
17
|
+
# WORKSHEET_COLUMNS = { key: 1, en: 2, de: 3 }
|
5
18
|
end
|
@@ -6,19 +6,18 @@ require_relative 'gdoc_to_xliff'
|
|
6
6
|
require_relative 'sync_util'
|
7
7
|
|
8
8
|
class Gdoc2XliffMain
|
9
|
-
include SyncUtil
|
10
9
|
attr_reader :path, :config
|
11
10
|
|
12
11
|
def initialize(path)
|
13
12
|
@path = path
|
14
|
-
@config =
|
13
|
+
@config = GdocTrans::CONFIG
|
15
14
|
end
|
16
15
|
|
17
16
|
def run
|
18
17
|
logger = Logger.new('.transync_log/gdoc2xliff.log', 'monthly')
|
19
18
|
|
20
19
|
@config['FILES'].each do |file|
|
21
|
-
xliff_translations = check_and_get_xliff_files(@config['LANGUAGES'], path, file)
|
20
|
+
xliff_translations = SyncUtil::check_and_get_xliff_files(@config['LANGUAGES'], path, file)
|
22
21
|
gdoc_trans_reader = GdocTransReader.new(@config['GDOC'], file)
|
23
22
|
|
24
23
|
@config['LANGUAGES'].each do |language|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'logger'
|
3
|
+
require_relative '../gdoc_trans/gdoc_trans_writer'
|
4
|
+
require_relative 'xliff_to_gdoc'
|
5
|
+
|
6
|
+
class Init
|
7
|
+
attr_reader :path, :config
|
8
|
+
|
9
|
+
def initialize(path)
|
10
|
+
@path = path
|
11
|
+
@config = GdocTrans::CONFIG
|
12
|
+
@gdoc_access = @config['GDOC']
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
# first we want to add all the files to spreadsheet as worksheets (tabs)
|
17
|
+
# add_worksheet(title, max_rows = 100, max_cols = 20)
|
18
|
+
session = GoogleDrive.login(@gdoc_access['email'], @gdoc_access['password'])
|
19
|
+
spreadsheet = session.spreadsheet_by_key(@gdoc_access['key'])
|
20
|
+
|
21
|
+
@config['FILES'].each do |file|
|
22
|
+
worksheet = spreadsheet.add_worksheet(file)
|
23
|
+
p "Adding #{file} worksheet to spreadsheet with first row (key and languages)"
|
24
|
+
|
25
|
+
worksheet[1, 1] = 'Key'
|
26
|
+
@config['LANGUAGES'].each_with_index do |language, index|
|
27
|
+
worksheet[1, index + 2] = language.upcase
|
28
|
+
end
|
29
|
+
worksheet.save
|
30
|
+
end
|
31
|
+
|
32
|
+
# now sync all our keys and translations to gdoc
|
33
|
+
# this won't work if local files are not 'clean'.
|
34
|
+
# to make them clean run test and update first!
|
35
|
+
x2g = Xliff2GdocMain.new(path)
|
36
|
+
x2g.run
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -2,19 +2,23 @@ require_relative '../xliff_trans/xliff_trans_reader'
|
|
2
2
|
|
3
3
|
module SyncUtil
|
4
4
|
|
5
|
-
def check_and_get_xliff_files(languages, path, file)
|
5
|
+
def self.check_and_get_xliff_files(languages, path, file, create = false)
|
6
6
|
xliff_translations = []
|
7
|
+
added = false
|
7
8
|
|
8
9
|
languages.each do |language|
|
9
10
|
xliff_reader = XliffTransReader.new(path, file, language, languages)
|
10
|
-
if xliff_reader.valid?
|
11
|
+
if xliff_reader.valid?(create)
|
11
12
|
xliff_translations << xliff_reader.get_translations
|
12
13
|
else
|
13
|
-
|
14
|
+
added = true if create
|
15
|
+
abort('Fix your Xliff translations first!') unless create
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
19
|
+
p 'Missing translations were added!' if create and added
|
20
|
+
|
17
21
|
xliff_translations
|
18
22
|
end
|
19
23
|
|
20
|
-
end
|
24
|
+
end
|
@@ -6,19 +6,18 @@ require_relative 'xliff_to_gdoc'
|
|
6
6
|
require_relative 'sync_util'
|
7
7
|
|
8
8
|
class Xliff2GdocMain
|
9
|
-
include SyncUtil
|
10
9
|
attr_reader :path, :config
|
11
10
|
|
12
11
|
def initialize(path)
|
13
12
|
@path = path
|
14
|
-
@config =
|
13
|
+
@config = GdocTrans::CONFIG
|
15
14
|
end
|
16
15
|
|
17
16
|
def run
|
18
17
|
logger = Logger.new('.transync_log/xliff2gdoc.log', 'monthly')
|
19
18
|
|
20
19
|
@config['FILES'].each do |file|
|
21
|
-
xliff_translations = check_and_get_xliff_files(@config['LANGUAGES'], path, file)
|
20
|
+
xliff_translations = SyncUtil::check_and_get_xliff_files(@config['LANGUAGES'], path, file)
|
22
21
|
|
23
22
|
gdoc_trans_reader = GdocTransReader.new(@config['GDOC'], file)
|
24
23
|
gdoc_trans_writer = GdocTransWriter.new(gdoc_trans_reader.worksheet)
|
data/lib/transync/version.rb
CHANGED
@@ -31,7 +31,11 @@ class XliffTransReader
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# will go through each and find if any xliff is missing keys for translations
|
34
|
-
def valid?
|
34
|
+
def valid?(create = false)
|
35
|
+
missing = 0
|
36
|
+
|
37
|
+
all_translations_for_language = {language: nil, translations: []}
|
38
|
+
|
35
39
|
self.get_translations[:translations].each do |x_trans|
|
36
40
|
self.languages.each do |key_lang|
|
37
41
|
next if key_lang == language
|
@@ -39,14 +43,28 @@ class XliffTransReader
|
|
39
43
|
xliff_reader = XliffTransReader.new(self.dir, self.file, key_lang, self.languages)
|
40
44
|
xliff_lang = xliff_reader.get_translations[:translations]
|
41
45
|
xliff_lang_value = xliff_lang.detect{ |xt| xt[:key] == x_trans[:key] }
|
46
|
+
|
47
|
+
all_translations_for_language[:language] = key_lang
|
48
|
+
|
42
49
|
if xliff_lang_value.nil?
|
43
|
-
p "#{file}.#{key_lang} is missing translation for key '#{x_trans[:key]}'"
|
44
|
-
return false
|
50
|
+
p "#{file}.#{key_lang} is missing translation for key '#{x_trans[:key]}'" unless create
|
51
|
+
return false unless create
|
52
|
+
|
53
|
+
p "#{missing + 1}. #{file}.#{key_lang} was missing translation for key '#{x_trans[:key]}'."
|
54
|
+
all_translations_for_language[:translations] << { key: x_trans[:key], value: 'Missing translation' }
|
55
|
+
missing += 1
|
56
|
+
else
|
57
|
+
all_translations_for_language[:translations] << xliff_lang_value
|
45
58
|
end
|
46
59
|
end
|
47
60
|
end
|
48
61
|
|
49
|
-
|
62
|
+
if missing > 0 and create
|
63
|
+
xliff_trans_writer = XliffTransWriter.new(dir, file, all_translations_for_language)
|
64
|
+
xliff_trans_writer.save
|
65
|
+
end
|
66
|
+
|
67
|
+
missing == 0
|
50
68
|
end
|
51
69
|
|
52
70
|
# Reading from source tags in xliff
|
data/lib/transync.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require_relative 'transync/sync/xliff_2_gdoc_main'
|
2
2
|
require_relative 'transync/sync/gdoc_2_xliff_main'
|
3
|
+
require_relative 'transync/sync/init'
|
4
|
+
require_relative 'transync/sync/sync_util'
|
3
5
|
|
4
6
|
module Transync
|
5
7
|
|
6
|
-
def self.run(mode
|
8
|
+
def self.run(mode)
|
7
9
|
FileUtils.mkdir('.transync_log') unless Dir.exist?('.transync_log')
|
10
|
+
path = GdocTrans::CONFIG['XLIFF_FILES_PATH']
|
8
11
|
|
9
12
|
if mode == 'x2g'
|
10
13
|
x2g = Xliff2GdocMain.new(path)
|
@@ -15,6 +18,23 @@ module Transync
|
|
15
18
|
g2x = Gdoc2XliffMain.new(path)
|
16
19
|
g2x.run
|
17
20
|
end
|
21
|
+
|
22
|
+
if mode == 'init'
|
23
|
+
init = Init.new(path)
|
24
|
+
init.run
|
25
|
+
end
|
26
|
+
|
27
|
+
if mode == 'test'
|
28
|
+
GdocTrans::CONFIG['FILES'].each do |file|
|
29
|
+
SyncUtil::check_and_get_xliff_files(GdocTrans::CONFIG['LANGUAGES'], path, file)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if mode == 'update'
|
34
|
+
GdocTrans::CONFIG['FILES'].each do |file|
|
35
|
+
SyncUtil::check_and_get_xliff_files(GdocTrans::CONFIG['LANGUAGES'], path, file, true)
|
36
|
+
end
|
37
|
+
end
|
18
38
|
end
|
19
39
|
|
20
40
|
end
|
data/settings.SAMPLE.yml
CHANGED
@@ -5,15 +5,11 @@ GDOC:
|
|
5
5
|
email: "user@example.com"
|
6
6
|
password: "secret"
|
7
7
|
|
8
|
+
XLIFF_FILES_PATH: test/fixtures
|
9
|
+
|
8
10
|
FILES: # xliff files <=> gdoc tabs
|
9
|
-
- "
|
10
|
-
- "
|
11
|
-
- "desktop"
|
12
|
-
- "error-msg"
|
13
|
-
- "FOSUserBundle"
|
14
|
-
- "home"
|
15
|
-
- "learn"
|
16
|
-
- "validators"
|
11
|
+
# - "messages"
|
12
|
+
# - "validators"
|
17
13
|
- "test"
|
18
14
|
|
19
15
|
LANGUAGES:
|
@@ -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>
|
data/test/fixtures/test.en.xliff
CHANGED
@@ -4,39 +4,15 @@
|
|
4
4
|
<body>
|
5
5
|
<trans-unit id="title">
|
6
6
|
<source>title</source>
|
7
|
-
<target>
|
7
|
+
<target>Title</target>
|
8
8
|
</trans-unit>
|
9
9
|
<trans-unit id="round">
|
10
10
|
<source>round</source>
|
11
|
-
<target>
|
11
|
+
<target>Round</target>
|
12
12
|
</trans-unit>
|
13
13
|
<trans-unit id="end_test">
|
14
14
|
<source>end_test</source>
|
15
|
-
<target>
|
16
|
-
</trans-unit>
|
17
|
-
<trans-unit id="statistics.summary">
|
18
|
-
<source>statistics.summary</source>
|
19
|
-
<target>Summary of this session</target>
|
20
|
-
</trans-unit>
|
21
|
-
<trans-unit id="statistics.time.spent">
|
22
|
-
<source>statistics.time.spent</source>
|
23
|
-
<target>Time Spent</target>
|
24
|
-
</trans-unit>
|
25
|
-
<trans-unit id="statistics.time.left">
|
26
|
-
<source>statistics.time.left</source>
|
27
|
-
<target>Time Left</target>
|
28
|
-
</trans-unit>
|
29
|
-
<trans-unit id="time.up">
|
30
|
-
<source>time.up</source>
|
31
|
-
<target>Your time is up</target>
|
32
|
-
</trans-unit>
|
33
|
-
<trans-unit id="last_card_title">
|
34
|
-
<source>last_card_title</source>
|
35
|
-
<target>Click END TEST button to save your results.</target>
|
36
|
-
</trans-unit>
|
37
|
-
<trans-unit id="repeat">
|
38
|
-
<source>repeat</source>
|
39
|
-
<target>Repeat</target>
|
15
|
+
<target>End test</target>
|
40
16
|
</trans-unit>
|
41
17
|
</body>
|
42
18
|
</file>
|
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.0
|
4
|
+
version: 0.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-
|
11
|
+
date: 2013-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google_drive
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/transync/gdoc_trans/gdoc_trans_writer.rb
|
88
88
|
- lib/transync/sync/gdoc_2_xliff_main.rb
|
89
89
|
- lib/transync/sync/gdoc_to_xliff.rb
|
90
|
+
- lib/transync/sync/init.rb
|
90
91
|
- lib/transync/sync/sync_util.rb
|
91
92
|
- lib/transync/sync/xliff_2_gdoc_main.rb
|
92
93
|
- lib/transync/sync/xliff_to_gdoc.rb
|
@@ -94,6 +95,7 @@ files:
|
|
94
95
|
- lib/transync/xliff_trans/xliff_trans_reader.rb
|
95
96
|
- lib/transync/xliff_trans/xliff_trans_writer.rb
|
96
97
|
- settings.SAMPLE.yml
|
98
|
+
- test/fixtures/test.de.xliff
|
97
99
|
- test/fixtures/test.en.xliff
|
98
100
|
- transync.gemspec
|
99
101
|
homepage: ''
|
@@ -116,9 +118,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
118
|
version: '0'
|
117
119
|
requirements: []
|
118
120
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.0.
|
121
|
+
rubygems_version: 2.0.3
|
120
122
|
signing_key:
|
121
123
|
specification_version: 4
|
122
124
|
summary: Synchronize XLIFF translations with Google Drive document
|
123
125
|
test_files:
|
126
|
+
- test/fixtures/test.de.xliff
|
124
127
|
- test/fixtures/test.en.xliff
|
128
|
+
has_rdoc:
|