web_translate_it 2.3.4 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/history.md +5 -0
- data/lib/web_translate_it/command_line.rb +24 -8
- data/lib/web_translate_it/project.rb +40 -12
- data/lib/web_translate_it/string.rb +61 -19
- data/lib/web_translate_it/term.rb +60 -18
- data/lib/web_translate_it/term_translation.rb +20 -6
- data/lib/web_translate_it/translation.rb +8 -3
- data/lib/web_translate_it/translation_file.rb +46 -9
- data/readme.md +44 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d27a853eb6927377b553c9a81e358fd956e1ccea
|
4
|
+
data.tar.gz: 9fd90672cc4afcc3296d0d181afd1a78d8d4ccac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 809906846a45331f7145c20fcc0cd1c916bc01ecf4298c46c0c12f49ad6152dbde2241284c8ea4838c9121be887aecc4b9f438958f1210a40b1885fed736b50f
|
7
|
+
data.tar.gz: d78d3d6f11aba5f46c0c0e811cbd0c15763bf7844deebb509bf9955cf7889208df40e406e1185bf2363386f24f590e51d6c8977a97241df39f6da20077eb82c1
|
data/history.md
CHANGED
@@ -27,10 +27,12 @@ module WebTranslateIt
|
|
27
27
|
end
|
28
28
|
throb { print " #{message}"; self.configuration = WebTranslateIt::Configuration.new(project_path, configuration_file_path); print " #{message} on #{self.configuration.project_name}"; }
|
29
29
|
end
|
30
|
-
self.send(command)
|
30
|
+
success = self.send(command)
|
31
|
+
exit 1 if !success
|
31
32
|
end
|
32
33
|
|
33
34
|
def pull
|
35
|
+
complete_success = true
|
34
36
|
STDOUT.sync = true
|
35
37
|
`#{configuration.before_pull}` if configuration.before_pull
|
36
38
|
# Selecting files to pull
|
@@ -54,7 +56,8 @@ module WebTranslateIt
|
|
54
56
|
threads << Thread.new(file_array) do |file_array|
|
55
57
|
WebTranslateIt::Connection.new(configuration.api_key) do |http|
|
56
58
|
file_array.each do |file|
|
57
|
-
file.fetch(http, command_options.force)
|
59
|
+
success = file.fetch(http, command_options.force)
|
60
|
+
complete_success = false if !success
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
@@ -64,10 +67,12 @@ module WebTranslateIt
|
|
64
67
|
time = Time.now - time
|
65
68
|
puts "Pulled #{files.size} files at #{(files.size/time).round} files/sec, using #{n_threads} threads."
|
66
69
|
`#{configuration.after_pull}` if configuration.after_pull
|
70
|
+
complete_success
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
70
74
|
def push
|
75
|
+
complete_success = true
|
71
76
|
STDOUT.sync = true
|
72
77
|
`#{configuration.before_push}` if configuration.before_push
|
73
78
|
WebTranslateIt::Connection.new(configuration.api_key) do |http|
|
@@ -81,15 +86,18 @@ module WebTranslateIt
|
|
81
86
|
puts "No files to push."
|
82
87
|
else
|
83
88
|
files.each do |file|
|
84
|
-
file.upload(http, command_options[:merge], command_options.ignore_missing, command_options.label, command_options.low_priority, command_options[:minor], command_options.force)
|
89
|
+
success = file.upload(http, command_options[:merge], command_options.ignore_missing, command_options.label, command_options.low_priority, command_options[:minor], command_options.force)
|
90
|
+
complete_success = false if !success
|
85
91
|
end
|
86
92
|
end
|
87
93
|
end
|
88
94
|
end
|
89
95
|
`#{configuration.after_push}` if configuration.after_push
|
96
|
+
complete_success
|
90
97
|
end
|
91
98
|
|
92
99
|
def add
|
100
|
+
complete_success = true
|
93
101
|
STDOUT.sync = true
|
94
102
|
if parameters == []
|
95
103
|
puts StringUtil.failure("Error: You must provide the path to the master file to add.")
|
@@ -102,15 +110,18 @@ module WebTranslateIt
|
|
102
110
|
if to_add.any?
|
103
111
|
to_add.each do |param|
|
104
112
|
file = TranslationFile.new(nil, param, nil, configuration.api_key)
|
105
|
-
file.create(http, command_options.low_priority)
|
113
|
+
success = file.create(http, command_options.low_priority)
|
114
|
+
complete_success = false if !success
|
106
115
|
end
|
107
116
|
else
|
108
117
|
puts "No new master file to add."
|
109
118
|
end
|
110
119
|
end
|
120
|
+
complete_success
|
111
121
|
end
|
112
122
|
|
113
123
|
def rm
|
124
|
+
complete_success = true
|
114
125
|
STDOUT.sync = true
|
115
126
|
if parameters == []
|
116
127
|
puts StringUtil.failure("Error: You must provide the path to the master file to remove.")
|
@@ -123,15 +134,18 @@ module WebTranslateIt
|
|
123
134
|
configuration.files.find_all{ |file| file.file_path == param }.each do |master_file|
|
124
135
|
master_file.delete(http)
|
125
136
|
# delete files
|
126
|
-
File.delete(master_file.file_path) if File.exists?(master_file.file_path)
|
137
|
+
success = File.delete(master_file.file_path) if File.exists?(master_file.file_path)
|
138
|
+
complete_success = false if !success
|
127
139
|
configuration.files.find_all{ |file| file.master_id == master_file.id }.each do |target_file|
|
128
|
-
File.delete(target_file.file_path) if File.exists?(target_file.file_path)
|
140
|
+
success = File.delete(target_file.file_path) if File.exists?(target_file.file_path)
|
141
|
+
complete_success = false if !success
|
129
142
|
end
|
130
143
|
end
|
131
144
|
end
|
132
145
|
end
|
133
146
|
end
|
134
147
|
puts StringUtil.success("Master file deleted.")
|
148
|
+
complete_success
|
135
149
|
end
|
136
150
|
|
137
151
|
def addlocale
|
@@ -139,7 +153,7 @@ module WebTranslateIt
|
|
139
153
|
if parameters == []
|
140
154
|
puts StringUtil.failure("Locale code missing.")
|
141
155
|
puts "Usage: wti addlocale fr es ..."
|
142
|
-
exit
|
156
|
+
exit 1
|
143
157
|
end
|
144
158
|
parameters.each do |param|
|
145
159
|
print StringUtil.success("Adding locale #{param.upcase}... ")
|
@@ -155,7 +169,7 @@ module WebTranslateIt
|
|
155
169
|
if parameters == []
|
156
170
|
puts StringUtil.failure("Error: You must provide the locale code to remove.")
|
157
171
|
puts "Usage: wti rmlocale fr es ..."
|
158
|
-
exit
|
172
|
+
exit 1
|
159
173
|
end
|
160
174
|
parameters.each do |param|
|
161
175
|
if Util.ask_yes_no("Are you certain you want to delete the locale #{param.upcase}?\nThis will also delete its files and translations.", false)
|
@@ -227,6 +241,7 @@ module WebTranslateIt
|
|
227
241
|
end
|
228
242
|
end
|
229
243
|
end
|
244
|
+
return true
|
230
245
|
end
|
231
246
|
|
232
247
|
def status
|
@@ -237,6 +252,7 @@ module WebTranslateIt
|
|
237
252
|
percent_completed = Util.calculate_percentage(values['count_strings_done'].to_i, values['count_strings'].to_i)
|
238
253
|
puts "#{locale}: #{percent_translated}% translated, #{percent_completed}% completed."
|
239
254
|
end
|
255
|
+
return true
|
240
256
|
end
|
241
257
|
|
242
258
|
def fetch_locales_to_pull
|
@@ -3,6 +3,8 @@ module WebTranslateIt
|
|
3
3
|
class Project
|
4
4
|
|
5
5
|
def self.fetch_info(api_key)
|
6
|
+
success = true
|
7
|
+
tries ||= 3
|
6
8
|
begin
|
7
9
|
WebTranslateIt::Connection.new(api_key) do |http|
|
8
10
|
request = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml")
|
@@ -18,15 +20,22 @@ module WebTranslateIt
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
rescue Timeout::Error
|
21
|
-
puts "
|
22
|
-
|
23
|
-
|
23
|
+
puts "Request timeout. Will retry in 5 seconds."
|
24
|
+
if (tries -= 1) > 0
|
25
|
+
sleep(5)
|
26
|
+
retry
|
27
|
+
else
|
28
|
+
success = false
|
29
|
+
end
|
24
30
|
rescue
|
25
31
|
puts $!.inspect
|
26
32
|
end
|
33
|
+
success
|
27
34
|
end
|
28
35
|
|
29
36
|
def self.fetch_stats(api_key)
|
37
|
+
success = true
|
38
|
+
tries ||= 3
|
30
39
|
begin
|
31
40
|
WebTranslateIt::Connection.new(api_key) do |http|
|
32
41
|
request = Net::HTTP::Get.new("/api/projects/#{api_key}/stats.yaml")
|
@@ -35,13 +44,20 @@ module WebTranslateIt
|
|
35
44
|
return Util.handle_response(http.request(request), true)
|
36
45
|
end
|
37
46
|
rescue Timeout::Error
|
38
|
-
puts "
|
39
|
-
|
40
|
-
|
47
|
+
puts "Request timeout. Will retry in 5 seconds."
|
48
|
+
if (tries -= 1) > 0
|
49
|
+
sleep(5)
|
50
|
+
retry
|
51
|
+
else
|
52
|
+
success = false
|
53
|
+
end
|
41
54
|
end
|
55
|
+
success
|
42
56
|
end
|
43
57
|
|
44
58
|
def self.create_locale(locale_code)
|
59
|
+
success = true
|
60
|
+
tries ||= 3
|
45
61
|
begin
|
46
62
|
request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/locales")
|
47
63
|
request.add_field("X-Client-Name", "web_translate_it")
|
@@ -49,23 +65,35 @@ module WebTranslateIt
|
|
49
65
|
request.set_form_data({ 'id' => locale_code }, ';')
|
50
66
|
Util.handle_response(Connection.http_connection.request(request), true)
|
51
67
|
rescue Timeout::Error
|
52
|
-
puts "
|
53
|
-
|
54
|
-
|
68
|
+
puts "Request timeout. Will retry in 5 seconds."
|
69
|
+
if (tries -= 1) > 0
|
70
|
+
sleep(5)
|
71
|
+
retry
|
72
|
+
else
|
73
|
+
success = false
|
74
|
+
end
|
55
75
|
end
|
76
|
+
success
|
56
77
|
end
|
57
78
|
|
58
79
|
def self.delete_locale(locale_code)
|
80
|
+
success = true
|
81
|
+
tries ||= 3
|
59
82
|
begin
|
60
83
|
request = Net::HTTP::Delete.new("/api/projects/#{Connection.api_key}/locales/#{locale_code}")
|
61
84
|
request.add_field("X-Client-Name", "web_translate_it")
|
62
85
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
63
86
|
Util.handle_response(Connection.http_connection.request(request), true)
|
64
87
|
rescue Timeout::Error
|
65
|
-
puts "
|
66
|
-
|
67
|
-
|
88
|
+
puts "Request timeout. Will retry in 5 seconds."
|
89
|
+
if (tries -= 1) > 0
|
90
|
+
sleep(5)
|
91
|
+
retry
|
92
|
+
else
|
93
|
+
success = false
|
94
|
+
end
|
68
95
|
end
|
96
|
+
success
|
69
97
|
end
|
70
98
|
end
|
71
99
|
end
|
@@ -51,6 +51,8 @@ module WebTranslateIt
|
|
51
51
|
# to find and instantiate an array of String which key is like `product_name_123`.
|
52
52
|
|
53
53
|
def self.find_all(params = {})
|
54
|
+
success = true
|
55
|
+
tries ||= 3
|
54
56
|
params.stringify_keys!
|
55
57
|
url = "/api/projects/#{Connection.api_key}/strings.yaml"
|
56
58
|
url += '?' + HashUtil.to_params("filters" => params) unless params.empty?
|
@@ -79,10 +81,15 @@ module WebTranslateIt
|
|
79
81
|
end
|
80
82
|
return strings
|
81
83
|
rescue Timeout::Error
|
82
|
-
puts "
|
83
|
-
|
84
|
-
|
84
|
+
puts "Request timeout. Will retry in 5 seconds."
|
85
|
+
if (tries -= 1) > 0
|
86
|
+
sleep(5)
|
87
|
+
retry
|
88
|
+
else
|
89
|
+
success = false
|
90
|
+
end
|
85
91
|
end
|
92
|
+
success
|
86
93
|
end
|
87
94
|
|
88
95
|
# Find a String based on its ID
|
@@ -100,6 +107,8 @@ module WebTranslateIt
|
|
100
107
|
#
|
101
108
|
|
102
109
|
def self.find(id)
|
110
|
+
success = true
|
111
|
+
tries ||= 3
|
103
112
|
request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/strings/#{id}.yaml")
|
104
113
|
request.add_field("X-Client-Name", "web_translate_it")
|
105
114
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
@@ -111,10 +120,15 @@ module WebTranslateIt
|
|
111
120
|
string.new_record = false
|
112
121
|
return string
|
113
122
|
rescue Timeout::Error
|
114
|
-
puts "
|
115
|
-
|
116
|
-
|
123
|
+
puts "Request timeout. Will retry in 5 seconds."
|
124
|
+
if (tries -= 1) > 0
|
125
|
+
sleep(5)
|
126
|
+
retry
|
127
|
+
else
|
128
|
+
success = false
|
129
|
+
end
|
117
130
|
end
|
131
|
+
success
|
118
132
|
end
|
119
133
|
|
120
134
|
# Update or create a String to WebTranslateIt.com
|
@@ -143,6 +157,8 @@ module WebTranslateIt
|
|
143
157
|
#
|
144
158
|
|
145
159
|
def delete
|
160
|
+
success = true
|
161
|
+
tries ||= 3
|
146
162
|
request = Net::HTTP::Delete.new("/api/projects/#{Connection.api_key}/strings/#{self.id}")
|
147
163
|
request.add_field("X-Client-Name", "web_translate_it")
|
148
164
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
@@ -150,10 +166,15 @@ module WebTranslateIt
|
|
150
166
|
begin
|
151
167
|
Util.handle_response(Connection.http_connection.request(request), true, true)
|
152
168
|
rescue Timeout::Error
|
153
|
-
puts "
|
154
|
-
|
155
|
-
|
169
|
+
puts "Request timeout. Will retry in 5 seconds."
|
170
|
+
if (tries -= 1) > 0
|
171
|
+
sleep(5)
|
172
|
+
retry
|
173
|
+
else
|
174
|
+
success = false
|
175
|
+
end
|
156
176
|
end
|
177
|
+
success
|
157
178
|
end
|
158
179
|
|
159
180
|
# Gets a Translation for a String
|
@@ -167,6 +188,8 @@ module WebTranslateIt
|
|
167
188
|
#
|
168
189
|
|
169
190
|
def translation_for(locale)
|
191
|
+
success = true
|
192
|
+
tries ||= 3
|
170
193
|
translation = self.translations.detect{ |t| t.locale == locale }
|
171
194
|
return translation if translation
|
172
195
|
return nil if self.new_record
|
@@ -182,10 +205,15 @@ module WebTranslateIt
|
|
182
205
|
return translation
|
183
206
|
|
184
207
|
rescue Timeout::Error
|
185
|
-
puts "
|
186
|
-
|
187
|
-
|
188
|
-
|
208
|
+
puts "Request timeout. Will retry in 5 seconds."
|
209
|
+
if (tries -= 1) > 0
|
210
|
+
sleep(5)
|
211
|
+
retry
|
212
|
+
else
|
213
|
+
success = false
|
214
|
+
end
|
215
|
+
end
|
216
|
+
success
|
189
217
|
end
|
190
218
|
|
191
219
|
protected
|
@@ -194,6 +222,8 @@ module WebTranslateIt
|
|
194
222
|
#
|
195
223
|
|
196
224
|
def update
|
225
|
+
success = true
|
226
|
+
tries ||= 3
|
197
227
|
request = Net::HTTP::Put.new("/api/projects/#{Connection.api_key}/strings/#{self.id}.yaml")
|
198
228
|
request.add_field("X-Client-Name", "web_translate_it")
|
199
229
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
@@ -208,16 +238,23 @@ module WebTranslateIt
|
|
208
238
|
begin
|
209
239
|
Util.handle_response(Connection.http_connection.request(request), true, true)
|
210
240
|
rescue Timeout::Error
|
211
|
-
puts "
|
212
|
-
|
213
|
-
|
241
|
+
puts "Request timeout. Will retry in 5 seconds."
|
242
|
+
if (tries -= 1) > 0
|
243
|
+
sleep(5)
|
244
|
+
retry
|
245
|
+
else
|
246
|
+
success = false
|
247
|
+
end
|
214
248
|
end
|
249
|
+
success
|
215
250
|
end
|
216
251
|
|
217
252
|
# Create a new String to WebTranslateIt.com
|
218
253
|
#
|
219
254
|
|
220
255
|
def create
|
256
|
+
success = true
|
257
|
+
tries ||= 3
|
221
258
|
request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/strings")
|
222
259
|
request.add_field("X-Client-Name", "web_translate_it")
|
223
260
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
@@ -230,10 +267,15 @@ module WebTranslateIt
|
|
230
267
|
self.new_record = false
|
231
268
|
return true
|
232
269
|
rescue Timeout::Error
|
233
|
-
puts "
|
234
|
-
|
235
|
-
|
270
|
+
puts "Request timeout. Will retry in 5 seconds."
|
271
|
+
if (tries -= 1) > 0
|
272
|
+
sleep(5)
|
273
|
+
retry
|
274
|
+
else
|
275
|
+
success = false
|
276
|
+
end
|
236
277
|
end
|
278
|
+
success
|
237
279
|
end
|
238
280
|
|
239
281
|
def to_json(with_translations = false)
|
@@ -42,6 +42,8 @@ module WebTranslateIt
|
|
42
42
|
# puts terms.inspect #=> An array of WebTranslateIt::Term objects
|
43
43
|
|
44
44
|
def self.find_all(params = {})
|
45
|
+
success = true
|
46
|
+
tries ||= 3
|
45
47
|
params.stringify_keys!
|
46
48
|
url = "/api/projects/#{Connection.api_key}/terms.yaml"
|
47
49
|
url += '?' + HashUtil.to_params(params) unless params.empty?
|
@@ -70,10 +72,15 @@ module WebTranslateIt
|
|
70
72
|
end
|
71
73
|
return terms
|
72
74
|
rescue Timeout::Error
|
73
|
-
puts "
|
74
|
-
|
75
|
-
|
75
|
+
puts "Request timeout. Will retry in 5 seconds."
|
76
|
+
if (tries -= 1) > 0
|
77
|
+
sleep(5)
|
78
|
+
retry
|
79
|
+
else
|
80
|
+
success = false
|
81
|
+
end
|
76
82
|
end
|
83
|
+
success
|
77
84
|
end
|
78
85
|
|
79
86
|
# Find a Term based on its ID
|
@@ -91,6 +98,8 @@ module WebTranslateIt
|
|
91
98
|
#
|
92
99
|
|
93
100
|
def self.find(term_id)
|
101
|
+
success = true
|
102
|
+
tries ||= 3
|
94
103
|
request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/terms/#{term_id}.yaml")
|
95
104
|
request.add_field("X-Client-Name", "web_translate_it")
|
96
105
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
@@ -102,10 +111,15 @@ module WebTranslateIt
|
|
102
111
|
term.new_record = false
|
103
112
|
return term
|
104
113
|
rescue Timeout::Error
|
105
|
-
puts "
|
106
|
-
|
107
|
-
|
114
|
+
puts "Request timeout. Will retry in 5 seconds."
|
115
|
+
if (tries -= 1) > 0
|
116
|
+
sleep(5)
|
117
|
+
retry
|
118
|
+
else
|
119
|
+
success = false
|
120
|
+
end
|
108
121
|
end
|
122
|
+
success
|
109
123
|
end
|
110
124
|
|
111
125
|
# Update or create a Term to WebTranslateIt.com
|
@@ -134,6 +148,8 @@ module WebTranslateIt
|
|
134
148
|
#
|
135
149
|
|
136
150
|
def delete
|
151
|
+
success = true
|
152
|
+
tries ||= 3
|
137
153
|
request = Net::HTTP::Delete.new("/api/projects/#{Connection.api_key}/terms/#{self.id}")
|
138
154
|
request.add_field("X-Client-Name", "web_translate_it")
|
139
155
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
@@ -141,10 +157,15 @@ module WebTranslateIt
|
|
141
157
|
begin
|
142
158
|
Util.handle_response(Connection.http_connection.request(request), true, true)
|
143
159
|
rescue Timeout::Error
|
144
|
-
puts "
|
145
|
-
|
146
|
-
|
160
|
+
puts "Request timeout. Will retry in 5 seconds."
|
161
|
+
if (tries -= 1) > 0
|
162
|
+
sleep(5)
|
163
|
+
retry
|
164
|
+
else
|
165
|
+
success = false
|
166
|
+
end
|
147
167
|
end
|
168
|
+
success
|
148
169
|
end
|
149
170
|
|
150
171
|
# Gets a Translation for a Term
|
@@ -158,6 +179,8 @@ module WebTranslateIt
|
|
158
179
|
#
|
159
180
|
|
160
181
|
def translation_for(locale)
|
182
|
+
success = true
|
183
|
+
tries ||= 3
|
161
184
|
translation = self.translations.detect{ |t| t.locale == locale }
|
162
185
|
return translation if translation
|
163
186
|
return nil if self.new_record
|
@@ -177,15 +200,22 @@ module WebTranslateIt
|
|
177
200
|
return translations
|
178
201
|
|
179
202
|
rescue Timeout::Error
|
180
|
-
puts "
|
181
|
-
|
182
|
-
|
203
|
+
puts "Request timeout. Will retry in 5 seconds."
|
204
|
+
if (tries -= 1) > 0
|
205
|
+
sleep(5)
|
206
|
+
retry
|
207
|
+
else
|
208
|
+
success = false
|
209
|
+
end
|
183
210
|
end
|
211
|
+
success
|
184
212
|
end
|
185
213
|
|
186
214
|
protected
|
187
215
|
|
188
216
|
def update
|
217
|
+
success = true
|
218
|
+
tries ||= 3
|
189
219
|
request = Net::HTTP::Put.new("/api/projects/#{Connection.api_key}/terms/#{self.id}.yaml")
|
190
220
|
request.add_field("X-Client-Name", "web_translate_it")
|
191
221
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
@@ -201,13 +231,20 @@ module WebTranslateIt
|
|
201
231
|
begin
|
202
232
|
Util.handle_response(Connection.http_connection.request(request), true, true)
|
203
233
|
rescue Timeout::Error
|
204
|
-
puts "
|
205
|
-
|
206
|
-
|
234
|
+
puts "Request timeout. Will retry in 5 seconds."
|
235
|
+
if (tries -= 1) > 0
|
236
|
+
sleep(5)
|
237
|
+
retry
|
238
|
+
else
|
239
|
+
success = false
|
240
|
+
end
|
207
241
|
end
|
242
|
+
success
|
208
243
|
end
|
209
244
|
|
210
245
|
def create
|
246
|
+
success = true
|
247
|
+
tries ||= 3
|
211
248
|
request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/terms")
|
212
249
|
request.add_field("X-Client-Name", "web_translate_it")
|
213
250
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
@@ -222,10 +259,15 @@ module WebTranslateIt
|
|
222
259
|
return true
|
223
260
|
|
224
261
|
rescue Timeout::Error
|
225
|
-
puts "
|
226
|
-
|
227
|
-
|
262
|
+
puts "Request timeout. Will retry in 5 seconds."
|
263
|
+
if (tries -= 1) > 0
|
264
|
+
sleep(5)
|
265
|
+
retry
|
266
|
+
else
|
267
|
+
success = false
|
268
|
+
end
|
228
269
|
end
|
270
|
+
success
|
229
271
|
end
|
230
272
|
|
231
273
|
def to_json(with_translations = false)
|
@@ -57,6 +57,8 @@ module WebTranslateIt
|
|
57
57
|
protected
|
58
58
|
|
59
59
|
def create
|
60
|
+
success = true
|
61
|
+
tries ||= 3
|
60
62
|
request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/terms/#{self.term_id}/locales/#{self.locale}/translations")
|
61
63
|
request.add_field("X-Client-Name", "web_translate_it")
|
62
64
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
@@ -71,13 +73,20 @@ module WebTranslateIt
|
|
71
73
|
return true
|
72
74
|
|
73
75
|
rescue Timeout::Error
|
74
|
-
puts "
|
75
|
-
|
76
|
-
|
76
|
+
puts "Request timeout. Will retry in 5 seconds."
|
77
|
+
if (tries -= 1) > 0
|
78
|
+
sleep(5)
|
79
|
+
retry
|
80
|
+
else
|
81
|
+
success = false
|
82
|
+
end
|
77
83
|
end
|
84
|
+
success
|
78
85
|
end
|
79
86
|
|
80
87
|
def update
|
88
|
+
success = true
|
89
|
+
tries ||= 3
|
81
90
|
request = Net::HTTP::Put.new("/api/projects/#{Connection.api_key}/terms/#{self.id}/locales/#{self.locale}/translations/#{self.id}")
|
82
91
|
request.add_field("X-Client-Name", "web_translate_it")
|
83
92
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
@@ -88,10 +97,15 @@ module WebTranslateIt
|
|
88
97
|
begin
|
89
98
|
Util.handle_response(Connection.http_connection.request(request), true, true)
|
90
99
|
rescue Timeout::Error
|
91
|
-
puts "
|
92
|
-
|
93
|
-
|
100
|
+
puts "Request timeout. Will retry in 5 seconds."
|
101
|
+
if (tries -= 1) > 0
|
102
|
+
sleep(5)
|
103
|
+
retry
|
104
|
+
else
|
105
|
+
success = false
|
106
|
+
end
|
94
107
|
end
|
108
|
+
success
|
95
109
|
end
|
96
110
|
end
|
97
111
|
end
|
@@ -42,6 +42,7 @@ module WebTranslateIt
|
|
42
42
|
#
|
43
43
|
|
44
44
|
def save
|
45
|
+
tries ||= 3
|
45
46
|
request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/strings/#{self.string_id}/locales/#{self.locale}/translations")
|
46
47
|
request.add_field("X-Client-Name", "web_translate_it")
|
47
48
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
@@ -51,9 +52,13 @@ module WebTranslateIt
|
|
51
52
|
begin
|
52
53
|
Util.handle_response(Connection.http_connection.request(request), true, true)
|
53
54
|
rescue Timeout::Error
|
54
|
-
puts "
|
55
|
-
|
56
|
-
|
55
|
+
puts "Request timeout. Will retry in 5 seconds."
|
56
|
+
if (tries -= 1) > 0
|
57
|
+
sleep(5)
|
58
|
+
retry
|
59
|
+
else
|
60
|
+
success = false
|
61
|
+
end
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
@@ -37,6 +37,8 @@ module WebTranslateIt
|
|
37
37
|
# file.fetch(true) # force to re-download the file, will return the content of the file with a 200 OK
|
38
38
|
#
|
39
39
|
def fetch(http_connection, force = false)
|
40
|
+
success = true
|
41
|
+
tries ||= 3
|
40
42
|
display = []
|
41
43
|
display.push(self.file_path)
|
42
44
|
display.push "#{StringUtil.checksumify(self.local_checksum.to_s)}..#{StringUtil.checksumify(self.remote_checksum.to_s)}"
|
@@ -52,16 +54,22 @@ module WebTranslateIt
|
|
52
54
|
display.push Util.handle_response(response)
|
53
55
|
rescue Timeout::Error
|
54
56
|
puts StringUtil.failure("Request timeout. Will retry in 5 seconds.")
|
55
|
-
|
56
|
-
|
57
|
+
if (tries -= 1) > 0
|
58
|
+
sleep(5)
|
59
|
+
retry
|
60
|
+
else
|
61
|
+
success = false
|
62
|
+
end
|
57
63
|
rescue
|
58
64
|
display.push StringUtil.failure("An error occured: #{$!}")
|
65
|
+
success = false
|
59
66
|
end
|
60
67
|
end
|
61
68
|
else
|
62
69
|
display.push StringUtil.success("Skipped")
|
63
70
|
end
|
64
71
|
print ArrayUtil.to_columns(display)
|
72
|
+
return success
|
65
73
|
end
|
66
74
|
|
67
75
|
# Update a language file to Web Translate It by performing a PUT Request.
|
@@ -76,6 +84,8 @@ module WebTranslateIt
|
|
76
84
|
# Note that the request might or might not eventually be acted upon, as it might be disallowed when processing
|
77
85
|
# actually takes place. This is due to the fact that language file imports are handled by background processing.
|
78
86
|
def upload(http_connection, merge=false, ignore_missing=false, label=nil, low_priority=false, minor_changes=false, force=false)
|
87
|
+
success = true
|
88
|
+
tries ||= 3
|
79
89
|
display = []
|
80
90
|
display.push(self.file_path)
|
81
91
|
display.push "#{StringUtil.checksumify(self.local_checksum.to_s)}..#{StringUtil.checksumify(self.remote_checksum.to_s)}"
|
@@ -89,8 +99,15 @@ module WebTranslateIt
|
|
89
99
|
display.push Util.handle_response(http_connection.request(request))
|
90
100
|
rescue Timeout::Error
|
91
101
|
puts StringUtil.failure("Request timeout. Will retry in 5 seconds.")
|
92
|
-
|
93
|
-
|
102
|
+
if (tries -= 1) > 0
|
103
|
+
sleep(5)
|
104
|
+
retry
|
105
|
+
else
|
106
|
+
success = false
|
107
|
+
end
|
108
|
+
rescue
|
109
|
+
display.push StringUtil.failure("An error occured: #{$!}")
|
110
|
+
success = false
|
94
111
|
end
|
95
112
|
end
|
96
113
|
else
|
@@ -100,6 +117,7 @@ module WebTranslateIt
|
|
100
117
|
else
|
101
118
|
puts StringUtil.failure("Can't push #{self.file_path}. File doesn't exist.")
|
102
119
|
end
|
120
|
+
return success
|
103
121
|
end
|
104
122
|
|
105
123
|
# Create a master language file to Web Translate It by performing a POST Request.
|
@@ -114,6 +132,8 @@ module WebTranslateIt
|
|
114
132
|
# actually takes place. This is due to the fact that language file imports are handled by background processing.
|
115
133
|
#
|
116
134
|
def create(http_connection, low_priority=false)
|
135
|
+
success = true
|
136
|
+
tries ||= 3
|
117
137
|
display = []
|
118
138
|
display.push file_path
|
119
139
|
display.push "#{StringUtil.checksumify(self.local_checksum.to_s)}..[ ]"
|
@@ -127,21 +147,30 @@ module WebTranslateIt
|
|
127
147
|
puts ArrayUtil.to_columns(display)
|
128
148
|
rescue Timeout::Error
|
129
149
|
puts StringUtil.failure("Request timeout. Will retry in 5 seconds.")
|
130
|
-
|
131
|
-
|
150
|
+
if (tries -= 1) > 0
|
151
|
+
sleep(5)
|
152
|
+
retry
|
153
|
+
else
|
154
|
+
success = false
|
155
|
+
end
|
156
|
+
rescue
|
157
|
+
display.push StringUtil.failure("An error occured: #{$!}")
|
158
|
+
success = false
|
132
159
|
end
|
133
160
|
end
|
134
161
|
else
|
135
162
|
puts StringUtil.failure("\nFile #{self.file_path} doesn't exist!")
|
136
163
|
end
|
164
|
+
return success
|
137
165
|
end
|
138
166
|
|
139
167
|
# Delete a master language file from Web Translate It by performing a DELETE Request.
|
140
168
|
#
|
141
169
|
def delete(http_connection)
|
170
|
+
success = true
|
171
|
+
tries ||= 3
|
142
172
|
display = []
|
143
173
|
display.push file_path
|
144
|
-
# display.push "#{StringUtil.checksumify(self.local_checksum.to_s)}..[ ]"
|
145
174
|
if File.exists?(self.file_path)
|
146
175
|
File.open(self.file_path) do |file|
|
147
176
|
begin
|
@@ -152,13 +181,21 @@ module WebTranslateIt
|
|
152
181
|
puts ArrayUtil.to_columns(display)
|
153
182
|
rescue Timeout::Error
|
154
183
|
puts StringUtil.failure("Request timeout. Will retry in 5 seconds.")
|
155
|
-
|
156
|
-
|
184
|
+
if (tries -= 1) > 0
|
185
|
+
sleep(5)
|
186
|
+
retry
|
187
|
+
else
|
188
|
+
success = false
|
189
|
+
end
|
190
|
+
rescue
|
191
|
+
display.push StringUtil.failure("An error occured: #{$!}")
|
192
|
+
success = false
|
157
193
|
end
|
158
194
|
end
|
159
195
|
else
|
160
196
|
puts StringUtil.failure("\nFile #{self.file_path} doesn't exist!")
|
161
197
|
end
|
198
|
+
return success
|
162
199
|
end
|
163
200
|
|
164
201
|
def exists?
|
data/readme.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
wti lets you easily sync your language files with [WebTranslateIt.com](https://webtranslateit.com), a web-based tool to translation software.
|
9
9
|
|
10
|
-
|
10
|
+
<img src="https://s3.amazonaws.com/f.cl.ly/items/27192V1K263K2O433h2g/webtranslateit_com_%E2%80%94_edouard_Edouards-MacBook-Pro-2____code_webtranslateit_com_%E2%80%94___anslateit_com_%E2%80%94_zsh_%E2%80%94_80%C3%9740.png" alt="WebTranslateIt Synchronization Tool" width="500px">
|
11
11
|
|
12
12
|
### wti...
|
13
13
|
|
@@ -40,6 +40,20 @@ $ wti -v
|
|
40
40
|
wti version 2.2.1
|
41
41
|
```
|
42
42
|
|
43
|
+
On some Linux distributions you may get the following error:
|
44
|
+
|
45
|
+
``` bash
|
46
|
+
$ wti
|
47
|
+
If 'wti' is not a typo you can use command-not-found to lookup the package that contains it, like this:
|
48
|
+
cnf wti
|
49
|
+
```
|
50
|
+
|
51
|
+
The reason is that the wti file is named in another way: `/usr/bin/wti.ruby2.1` so you will have to create a symlink to make wti run.
|
52
|
+
|
53
|
+
``` bash
|
54
|
+
$ ln -s /usr/bin/wti.ruby2.1 wti
|
55
|
+
```
|
56
|
+
|
43
57
|
## Configuration
|
44
58
|
|
45
59
|
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.
|
@@ -182,6 +196,34 @@ There are 4 hooks:
|
|
182
196
|
|
183
197
|
Check the [sample `.wti`](https://github.com/AtelierConvivialite/webtranslateit/blob/master/examples/.wti#L9..L13) file for implementation.
|
184
198
|
|
199
|
+
## Exit codes
|
200
|
+
|
201
|
+
Since version 1.4.0 `wti` returns exit codes on failure. The exit code is `0` if the command executed successfully and `1` if the command executed but encountered at least one error. This is useful to act upon errors if you use `wti` to pull files in an automated build process.
|
202
|
+
|
203
|
+
``` zsh
|
204
|
+
~/code/webtranslateit.com[master]% wti pull
|
205
|
+
# Pulling files on WebTranslateIt
|
206
|
+
config/locales/translation_validator/en.yml | e82e044..e82e044 Skipped
|
207
|
+
config/locales/app/en.yml | f2ca86c..f2ca86c Skipped
|
208
|
+
config/locales/defaults/en.yml | 2fcb61f..2fcb61f Skipped
|
209
|
+
config/locales/js/en.yml | ee6589d..ee6589d Skipped
|
210
|
+
config/locales/js/fr.yml | 2f8bb0e..2f8bb0e Skipped
|
211
|
+
config/locales/translation_validator/fr.yml | 534af2c..534af2c Skipped
|
212
|
+
config/locales/app/fr.yml | 29f8c9d..da39a3e OK
|
213
|
+
config/locales/defaults/fr.yml | aca123e..aca123e Skipped
|
214
|
+
Pulled 8 files at 7 files/sec, using 3 threads.
|
215
|
+
~/code/webtranslateit.com[master]% echo $!
|
216
|
+
0
|
217
|
+
~/code/webtranslateit.com[master]% wti pull
|
218
|
+
# Pulling files on WebTranslateIt
|
219
|
+
config/locales/translation_validator/en.yml | e82e044..e82e044 Error
|
220
|
+
config/locales/app/en.yml | f2ca86c..f2ca86c Skipped
|
221
|
+
config/locales/defaults/fr.yml | aca123e..aca123e Skipped
|
222
|
+
Pulled 3 files at 3 files/sec, using 3 threads.
|
223
|
+
~/code/webtranslateit.com[master]% echo $!
|
224
|
+
1
|
225
|
+
```
|
226
|
+
|
185
227
|
# License
|
186
228
|
|
187
|
-
Copyright (c) 2009-
|
229
|
+
Copyright (c) 2009-2015 Atelier Convivialité, released under the MIT License.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_translate_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edouard Briere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: '0'
|
144
144
|
requirements: []
|
145
145
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.
|
146
|
+
rubygems_version: 2.4.8
|
147
147
|
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: A CLI to sync locale files with WebTranslateIt.com.
|