web_translate_it 2.0.3 → 2.0.4
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.
- data/history.md +6 -0
- data/lib/web_translate_it/command_line.rb +60 -15
- data/readme.md +40 -24
- data/version +1 -1
- metadata +2 -2
data/history.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## Version 2.0.4 / 2012-08-08
|
2
|
+
|
3
|
+
* New: Add a throbber to indicate the project information is loading.
|
4
|
+
* New: Display error message when pushing or pulling a language that doesn’t exist in a project.
|
5
|
+
* Fixed: Compatibility problem with ruby 1.8.6.
|
6
|
+
|
1
7
|
## Version 2.0.3 / 2012-06-07
|
2
8
|
|
3
9
|
* Fix: String#translation_for('xx') should not return an array of all translations. #88
|
@@ -4,12 +4,28 @@ module WebTranslateIt
|
|
4
4
|
require 'fileutils'
|
5
5
|
require 'set'
|
6
6
|
attr_accessor :configuration, :global_options, :command_options, :parameters
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(command, command_options, global_options, parameters, project_path)
|
9
9
|
self.command_options = command_options
|
10
10
|
self.parameters = parameters
|
11
11
|
unless command == 'init'
|
12
|
-
|
12
|
+
case command
|
13
|
+
when 'pull'
|
14
|
+
message = "Pulling files"
|
15
|
+
when 'push'
|
16
|
+
message = "Pushing files"
|
17
|
+
when 'add'
|
18
|
+
message = "Creating master files"
|
19
|
+
when 'rm'
|
20
|
+
message = "Deleting files"
|
21
|
+
when 'addlocale'
|
22
|
+
message = "Adding locale"
|
23
|
+
when 'rmlocale'
|
24
|
+
message = "Deleting locale"
|
25
|
+
else
|
26
|
+
message = "Gathering information"
|
27
|
+
end
|
28
|
+
throb { print " #{message}"; self.configuration = WebTranslateIt::Configuration.new(project_path, configuration_file_path) }
|
13
29
|
end
|
14
30
|
self.send(command)
|
15
31
|
end
|
@@ -22,14 +38,13 @@ module WebTranslateIt
|
|
22
38
|
fetch_locales_to_pull.each do |locale|
|
23
39
|
files.concat configuration.files.find_all{ |file| file.locale == locale }
|
24
40
|
end
|
25
|
-
if files.
|
41
|
+
if files.size == 0
|
26
42
|
puts "No files to pull."
|
27
43
|
else
|
28
44
|
# Now actually pulling files
|
29
|
-
puts "# Pulling files"
|
30
45
|
time = Time.now
|
31
46
|
threads = []
|
32
|
-
n_threads = (files.
|
47
|
+
n_threads = (files.size.to_f/3).ceil >= 20 ? 20 : (files.size.to_f/3).ceil
|
33
48
|
ArrayUtil.chunk(files, n_threads).each do |file_array|
|
34
49
|
unless file_array.empty?
|
35
50
|
threads << Thread.new(file_array) do |file_array|
|
@@ -43,7 +58,7 @@ module WebTranslateIt
|
|
43
58
|
end
|
44
59
|
threads.each { |thread| thread.join }
|
45
60
|
time = Time.now - time
|
46
|
-
puts "Pulled #{files.
|
61
|
+
puts "Pulled #{files.size} files at #{(files.size/time).round} files/sec, using #{n_threads} threads."
|
47
62
|
`#{configuration.after_pull}` if configuration.after_pull
|
48
63
|
end
|
49
64
|
end
|
@@ -51,11 +66,15 @@ module WebTranslateIt
|
|
51
66
|
def push
|
52
67
|
STDOUT.sync = true
|
53
68
|
`#{configuration.before_push}` if configuration.before_push
|
54
|
-
puts "# Pushing files"
|
55
69
|
WebTranslateIt::Connection.new(configuration.api_key) do |http|
|
56
70
|
fetch_locales_to_push(configuration).each do |locale|
|
57
|
-
configuration.files.find_all{ |file| file.locale == locale }.sort{|a,b| a.file_path <=> b.file_path}
|
58
|
-
|
71
|
+
files = configuration.files.find_all{ |file| file.locale == locale }.sort{|a,b| a.file_path <=> b.file_path}
|
72
|
+
if files.size == 0
|
73
|
+
puts "No files to push."
|
74
|
+
else
|
75
|
+
files.each do |file|
|
76
|
+
file.upload(http, command_options[:merge], command_options.ignore_missing, command_options.label, command_options.low_priority, command_options[:minor], command_options.force)
|
77
|
+
end
|
59
78
|
end
|
60
79
|
end
|
61
80
|
end
|
@@ -64,7 +83,6 @@ module WebTranslateIt
|
|
64
83
|
|
65
84
|
def add
|
66
85
|
STDOUT.sync = true
|
67
|
-
puts "# Creating master files"
|
68
86
|
if parameters == []
|
69
87
|
puts StringUtil.failure("Error: You must provide the path to the master file to add.")
|
70
88
|
puts "Usage: wti add path/to/master_file_1 path/to/master_file_2 ..."
|
@@ -146,7 +164,7 @@ module WebTranslateIt
|
|
146
164
|
puts "# Initializing project"
|
147
165
|
api_key = Util.ask(" Project API Key:")
|
148
166
|
path = Util.ask(" Path to configuration file:", '.wti')
|
149
|
-
FileUtils.mkpath(path.split('/')[0..path.split('/').size-2].join('/')) unless path.split('/').
|
167
|
+
FileUtils.mkpath(path.split('/')[0..path.split('/').size-2].join('/')) unless path.split('/').size == 1
|
150
168
|
project = YAML.load WebTranslateIt::Project.fetch_info(api_key)
|
151
169
|
project_info = project['project']
|
152
170
|
if File.exists?(path) && !File.writable?(path)
|
@@ -156,7 +174,7 @@ module WebTranslateIt
|
|
156
174
|
File.open(path, 'w'){ |file| file << generate_configuration(api_key, project_info) }
|
157
175
|
puts ""
|
158
176
|
puts " Your project was successfully initialized."
|
159
|
-
if project_info["source_locale"]["code"].nil? || project_info["target_locales"].
|
177
|
+
if project_info["source_locale"]["code"].nil? || project_info["target_locales"].size <= 1 || project_info["project_files"].none?
|
160
178
|
puts ""
|
161
179
|
puts " There are a few more things to set up:"
|
162
180
|
puts ""
|
@@ -166,7 +184,7 @@ module WebTranslateIt
|
|
166
184
|
puts " Add the source locale with: `wti addlocale <locale_code>`"
|
167
185
|
puts ""
|
168
186
|
end
|
169
|
-
if project_info["target_locales"].
|
187
|
+
if project_info["target_locales"].size <= 1
|
170
188
|
puts " *) You don't have a target locale setup."
|
171
189
|
puts " Add the first target locale with: `wti addlocale <locale_code>`"
|
172
190
|
puts ""
|
@@ -213,6 +231,9 @@ module WebTranslateIt
|
|
213
231
|
|
214
232
|
def fetch_locales_to_pull
|
215
233
|
if command_options.locale
|
234
|
+
command_options.locale.split.each do |locale|
|
235
|
+
puts "Locale #{locale} doesn't exist -- `wti addlocale #{locale}` to add it." unless configuration.target_locales.include?(locale)
|
236
|
+
end
|
216
237
|
locales = command_options.locale.split
|
217
238
|
else
|
218
239
|
locales = configuration.target_locales
|
@@ -224,6 +245,9 @@ module WebTranslateIt
|
|
224
245
|
|
225
246
|
def fetch_locales_to_push(configuration)
|
226
247
|
if command_options.locale
|
248
|
+
command_options.locale.split.each do |locale|
|
249
|
+
puts "Locale #{locale} doesn't exist -- `wti addlocale #{locale}` to add it." unless configuration.target_locales.include?(locale)
|
250
|
+
end
|
227
251
|
locales = command_options.locale.split
|
228
252
|
else
|
229
253
|
locales = [configuration.source_locale]
|
@@ -273,6 +297,27 @@ api_key: #{api_key}
|
|
273
297
|
|
274
298
|
FILE
|
275
299
|
return file
|
276
|
-
end
|
277
|
-
|
300
|
+
end
|
301
|
+
|
302
|
+
def throb
|
303
|
+
throb = %w(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏)
|
304
|
+
throb.reverse! if rand > 0.5
|
305
|
+
i = rand throb.length
|
306
|
+
|
307
|
+
thread = Thread.new do
|
308
|
+
dot = lambda do
|
309
|
+
print "\r#{throb[i]}\e[?25l"
|
310
|
+
i = (i + 1) % throb.length
|
311
|
+
sleep 0.1 and dot.call
|
312
|
+
end
|
313
|
+
dot.call
|
314
|
+
end
|
315
|
+
yield
|
316
|
+
ensure
|
317
|
+
if thread
|
318
|
+
thread.kill
|
319
|
+
puts "\r\e[0G#\e[?25h"
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
278
323
|
end
|
data/readme.md
CHANGED
@@ -1,46 +1,62 @@
|
|
1
|
-
#
|
1
|
+
# WebTranslateIt Synchronization Tool
|
2
2
|
|
3
|
-
[
|
4
|
-
[RDoc](http://yardoc.org/docs/AtelierConvivialite-webtranslateit) |
|
3
|
+
[RubyDoc](http://rubydoc.info/github/AtelierConvivialite/webtranslateit/) |
|
5
4
|
[Example app](http://github.com/AtelierConvivialite/rails_example_app) |
|
6
5
|
[Report a bug](http://github.com/AtelierConvivialite/webtranslateit/issues) |
|
7
|
-
[Support](
|
6
|
+
[Support](https://webtranslateit.com/support) |
|
7
|
+
[WebTranslateIt.com Homepage](https://webtranslateit.com)
|
8
8
|
|
9
|
-
`web_translate_it` is a tool to sync your language files with [WebTranslateIt.com](https://webtranslateit.com), a web-based translation software.
|
9
|
+
`web_translate_it` is a tool to sync your language files with [WebTranslateIt.com](https://webtranslateit.com), a web-based tool to translation software.
|
10
10
|
|
11
|
-

|
12
12
|
|
13
13
|
## This rubygem provides:
|
14
14
|
|
15
|
-
1. A
|
16
|
-
2. A synchronisation server
|
17
|
-
3.
|
18
|
-
4. A rack middleware you can use in your Rails app to automatically fetch new translations from
|
19
|
-
|
20
|
-
This readme focusses on the most commonly used functionality of this rubygem: the `wti` command-line executable.
|
15
|
+
1. A Command-Line Interface, `wti`, to sync files between your computer/server and WebTranslateIt.com. It is cross-platform and runs in a terminal (Linux, MacOS X) or in cmd.exe (Windows).
|
16
|
+
2. A synchronisation server which provides a web interface for your translation team to update your language files. [Learn more on the web_translate_it_server project page](https://github.com/AtelierConvivialite/web_translate_it_server).
|
17
|
+
3. A library to help write programs to connect to WebTranslateIt.com’s API. See [Extras](https://github.com/AtelierConvivialite/webtranslateit/wiki/Extras).
|
18
|
+
4. A rack middleware you can use in your Rails app to automatically fetch new translations from WebTranslateIt.
|
21
19
|
|
22
20
|
---
|
23
21
|
|
24
22
|
## Installation
|
25
23
|
|
26
|
-
A dependency of wti needs gcc
|
24
|
+
A dependency of `wti` needs gcc, so you will need it. With Linux, `apt-get install build-essential` or `yum install gcc` should do it.
|
27
25
|
|
28
|
-
You will also need ruby to run wti
|
26
|
+
You will also need ruby to run `wti`. On Linux or a Mac, it’s already installed. Install [RubyInstaller](http://rubyinstaller.org/) if you’re using Windows. [See detailed installation instructions for Windows users](https://github.com/AtelierConvivialite/webtranslateit/wiki/Install-wti-on-Windows).
|
29
27
|
|
30
|
-
|
28
|
+
``` bash
|
29
|
+
$ gem install web_translate_it
|
30
|
+
Fetching: web_translate_it-2.0.3.gem (100%)
|
31
|
+
Successfully installed web_translate_it-2.0.3
|
32
|
+
1 gem installed
|
33
|
+
```
|
31
34
|
|
32
|
-
At this point you should have the `wti` executable working
|
35
|
+
At this point you should have the `wti` executable working:
|
36
|
+
|
37
|
+
``` bash
|
38
|
+
$ wti -v
|
39
|
+
wti version 2.0.3
|
40
|
+
```
|
33
41
|
|
34
42
|
## Configuration
|
35
43
|
|
36
|
-
Now that the tool is installed, you’ll have to configure your project
|
44
|
+
Now that the tool is installed, you’ll have to configure your project. Basically, `wti` is to be run on a project root directory, and looks for a `.wti` file containing your project information. The command `wti init` lets your create your `.wti` file.
|
45
|
+
|
46
|
+
``` bash
|
47
|
+
$ wti init
|
48
|
+
# Initializing project
|
49
|
+
Project API Key: 55555abc1235555
|
50
|
+
Path to configuration file: (Default: .wti)
|
37
51
|
|
38
|
-
|
52
|
+
Your project was successfully initialized.
|
53
|
+
You can now use `wti` to push and pull your language files.
|
54
|
+
Check `wti --help` for help.
|
55
|
+
```
|
39
56
|
|
40
|
-
The command
|
57
|
+
The command asks you to enter your project API key (you can find it in your project settings) and where to save the configuration file (by default it will create a `.wti` in your project root directory).
|
41
58
|
|
42
|
-
|
43
|
-
* Where to save the configuration file (by default it will create a `.wti` in your project root directory).
|
59
|
+
Now you’re all set and you can use the `wti` commands on your project.
|
44
60
|
|
45
61
|
## Usage
|
46
62
|
|
@@ -128,7 +144,7 @@ Append `--help` for each command for more information. For instance:
|
|
128
144
|
</tr>
|
129
145
|
<tr>
|
130
146
|
<td>wti pull --force</td>
|
131
|
-
<td>Force pull (to bypass
|
147
|
+
<td>Force pull (to bypass WebTranslateIt’s HTTP caching)</td>
|
132
148
|
</tr>
|
133
149
|
<tr>
|
134
150
|
<td>wti addlocale fr</td>
|
@@ -144,7 +160,7 @@ Append `--help` for each command for more information. For instance:
|
|
144
160
|
</tr>
|
145
161
|
<tr>
|
146
162
|
<td>wti match</td>
|
147
|
-
<td>Show matching between files on local computer and the ones in
|
163
|
+
<td>Show matching between files on local computer and the ones in WebTranslateIt’s File Manager</td>
|
148
164
|
</tr>
|
149
165
|
</table>
|
150
166
|
|
@@ -161,7 +177,7 @@ There are 4 hooks:
|
|
161
177
|
|
162
178
|
Check the [sample `.wti`](https://github.com/AtelierConvivialite/webtranslateit/blob/master/examples/.wti#L9..L13) file for implementation.
|
163
179
|
|
164
|
-
##
|
180
|
+
## WebTranslateIt Server
|
165
181
|
|
166
182
|
This feature was extracted out to a separate gem. See [web_translate_it_server](https://github.com/AtelierConvivialite/web_translate_it_server).
|
167
183
|
|
data/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.4
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_translate_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multipart-post
|