transync 0.0.1 → 0.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: 8c6fb462e97a836b1fd3aab65f2cc82fef40a3b9
4
- data.tar.gz: 3a7dae00ef26bd34d28311599dcf06c5fe5b233e
3
+ metadata.gz: 14ddaefea87d79fa54969295284ba7f048567d7b
4
+ data.tar.gz: 5f4e9e49694aafeab4a66ae6b850ff23c62c9d14
5
5
  SHA512:
6
- metadata.gz: 1742efaff0fcd8e34d72376cc58049eb59a7348046f30186e2f48dd3151309aa2f428bd62c0779b000fc87f28a194557af1c60659774606fb572a6309dd89b04
7
- data.tar.gz: 4fb9c221031ac7e94136f798abc317904f1d63293be877aeebc5f78733f8317a5bd2def9d94029bd1d3190ce6cb3f4d7f8c8a04f8bddad7371e0182ce3b4ce37
6
+ metadata.gz: cc8ee6a94f7ba1628db70c53760deaaa7b947c3dbdff2cdff73abdf07db01de8b8a035eba617a8fca8d1877239650305bfcd36d89e5e74d8f77fb7cc57f63b93
7
+ data.tar.gz: ed6b943d8c8564142d3654234110ee3431585f1c21272d5206736d2a31c455796081344bd15cf6d9cda6a34c5dab49edfcff23ad2641f1e7f062638fac309aaa
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0-p195
1
+ 2.0.0-p247
data/README.md CHANGED
@@ -1,31 +1,42 @@
1
1
  # Install
2
2
 
3
- gem install transync
3
+ ```bash
4
+ gem install transync
5
+ ```
4
6
 
5
- You need settings file needs to be named `settings.yml`. For example see `settings.SAMPLE.yml`.
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
- ### Example
10
+ ### Process
8
11
 
9
- transync x2g path/to/your/xliff/files
10
- transync g2x path/to/your/xliff/files
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
- ### Example for testing within this gem
18
+ ### Running order
13
19
 
14
- rake install && transync x2g test/fixtures
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
- # Assumptions:
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
- You have xliff files in one directory, named like: common.en.xliff where common is name of the file and also google doc
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
- # Config
22
-
23
- Google doc
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
- GDOC_KEY = 0ApAHdLDpSUFudHhuWU9vQ0ZPaWNoV3VxU045cXhHLWc
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,2 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require 'transync'
2
- Transync.run ARGV[0], ARGV[1]
4
+ Transync.run ARGV[0]
@@ -1,5 +1,18 @@
1
- # TODO move also to yml file
2
1
  module GdocTrans
3
- WORKSHEET_COLUMNS = { key: 1, en: 2, de: 3 }
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 = YAML.load(File.open('settings.yml'))
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
- abort('Fix your Xliff translations first!')
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 = YAML.load(File.open('settings.yml'))
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)
@@ -1,3 +1,3 @@
1
1
  module Transync
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.0'
3
3
  end
@@ -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
- true
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
@@ -42,4 +42,4 @@ private
42
42
  "#{path}/#{file}.#{language}.xliff"
43
43
  end
44
44
 
45
- end
45
+ end
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, path)
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
- - "cockpit"
10
- - "common"
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>
@@ -4,39 +4,15 @@
4
4
  <body>
5
5
  <trans-unit id="title">
6
6
  <source>title</source>
7
- <target>TEST</target>
7
+ <target>Title</target>
8
8
  </trans-unit>
9
9
  <trans-unit id="round">
10
10
  <source>round</source>
11
- <target>Attempt</target>
11
+ <target>Round</target>
12
12
  </trans-unit>
13
13
  <trans-unit id="end_test">
14
14
  <source>end_test</source>
15
- <target>END TEST</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.1
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-05-26 00:00:00.000000000 Z
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.2
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: