web_translate_it 2.5.2 → 2.6.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 +5 -2
- data/bin/wti +107 -107
- data/generators/webtranslateit/lib/insert_commands.rb +6 -8
- data/generators/webtranslateit/webtranslateit_generator.rb +6 -6
- data/history.md +21 -7
- data/lib/web_translate_it/auto_fetch.rb +2 -4
- data/lib/web_translate_it/command_line.rb +265 -228
- data/lib/web_translate_it/configuration.rb +33 -28
- data/lib/web_translate_it/connection.rb +7 -8
- data/lib/web_translate_it/project.rb +16 -20
- data/lib/web_translate_it/string.rb +79 -78
- data/lib/web_translate_it/term.rb +59 -59
- data/lib/web_translate_it/term_translation.rb +32 -34
- data/lib/web_translate_it/translation.rb +24 -31
- data/lib/web_translate_it/translation_file.rb +105 -102
- data/lib/web_translate_it/util/array_util.rb +8 -8
- data/lib/web_translate_it/util/hash_util.rb +5 -5
- data/lib/web_translate_it/util/string_util.rb +5 -8
- data/lib/web_translate_it/util.rb +47 -50
- data/lib/web_translate_it.rb +5 -7
- data/readme.md +6 -2
- data/spec/spec_helper.rb +2 -3
- data/spec/web_translate_it/auto_fetch_spec.rb +1 -2
- data/spec/web_translate_it/string_spec.rb +61 -62
- data/spec/web_translate_it/term_spec.rb +43 -41
- metadata +47 -12
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
module WebTranslateIt
|
3
2
|
# A TranslationFile is the representation of a master language file
|
4
3
|
# on Web Translate It.
|
@@ -6,15 +5,15 @@ module WebTranslateIt
|
|
6
5
|
# This class allows to manipulate TranslationFiles, more specifically upload and download them.
|
7
6
|
# If you pass a Locale to the master language file you will be able to
|
8
7
|
# manipulate a _target_ language file.
|
9
|
-
class TranslationFile
|
8
|
+
class TranslationFile # rubocop:todo Metrics/ClassLength
|
10
9
|
require 'net/https'
|
11
10
|
require 'net/http/post/multipart'
|
12
11
|
require 'time'
|
13
12
|
require 'fileutils'
|
14
|
-
|
13
|
+
|
15
14
|
attr_accessor :id, :file_path, :locale, :api_key, :updated_at, :remote_checksum, :master_id, :fresh
|
16
|
-
|
17
|
-
def initialize(id, file_path, locale, api_key, updated_at = nil, remote_checksum =
|
15
|
+
|
16
|
+
def initialize(id, file_path, locale, api_key, updated_at = nil, remote_checksum = '', master_id = nil, fresh = nil) # rubocop:todo Metrics/ParameterLists
|
18
17
|
self.id = id
|
19
18
|
self.file_path = file_path
|
20
19
|
self.locale = locale
|
@@ -24,7 +23,7 @@ module WebTranslateIt
|
|
24
23
|
self.master_id = master_id
|
25
24
|
self.fresh = fresh
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
# Fetch a language file.
|
29
28
|
# By default it will make a conditional GET Request, using the `If-Modified-Since` tag.
|
30
29
|
# You can force the method to re-download your file by passing `true` as a second argument
|
@@ -37,27 +36,27 @@ module WebTranslateIt
|
|
37
36
|
# file.fetch # returns nothing, with a status 304 Not Modified
|
38
37
|
# file.fetch(true) # force to re-download the file, will return the content of the file with a 200 OK
|
39
38
|
#
|
40
|
-
def fetch(http_connection, force = false)
|
39
|
+
def fetch(http_connection, force = false) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
41
40
|
success = true
|
42
41
|
tries ||= 3
|
43
42
|
display = []
|
44
|
-
if
|
45
|
-
display.push(
|
43
|
+
if fresh
|
44
|
+
display.push(file_path)
|
46
45
|
else
|
47
|
-
display.push("*#{
|
46
|
+
display.push("*#{file_path}")
|
48
47
|
end
|
49
|
-
display.push "#{StringUtil.checksumify(
|
50
|
-
if !File.exist?(
|
48
|
+
display.push "#{StringUtil.checksumify(local_checksum.to_s)}..#{StringUtil.checksumify(remote_checksum.to_s)}"
|
49
|
+
if !File.exist?(file_path) or force or remote_checksum != local_checksum
|
51
50
|
begin
|
52
51
|
request = Net::HTTP::Get.new(api_url)
|
53
52
|
WebTranslateIt::Util.add_fields(request)
|
54
|
-
FileUtils.mkpath(
|
53
|
+
FileUtils.mkpath(file_path.split('/')[0..-2].join('/')) unless File.exist?(file_path) or file_path.split('/')[0..-2].join('/') == ''
|
55
54
|
begin
|
56
55
|
response = http_connection.request(request)
|
57
|
-
File.open(
|
56
|
+
File.open(file_path, 'wb') { |file| file << response.body } if response.code.to_i == 200
|
58
57
|
display.push Util.handle_response(response)
|
59
58
|
rescue Timeout::Error
|
60
|
-
puts StringUtil.failure(
|
59
|
+
puts StringUtil.failure('Request timeout. Will retry in 5 seconds.')
|
61
60
|
if (tries -= 1) > 0
|
62
61
|
sleep(5)
|
63
62
|
retry
|
@@ -70,12 +69,12 @@ module WebTranslateIt
|
|
70
69
|
end
|
71
70
|
end
|
72
71
|
else
|
73
|
-
display.push StringUtil.success(
|
72
|
+
display.push StringUtil.success('Skipped')
|
74
73
|
end
|
75
74
|
print ArrayUtil.to_columns(display)
|
76
|
-
|
75
|
+
success
|
77
76
|
end
|
78
|
-
|
77
|
+
|
79
78
|
# Update a language file to Web Translate It by performing a PUT Request.
|
80
79
|
#
|
81
80
|
# Example of implementation:
|
@@ -87,45 +86,51 @@ module WebTranslateIt
|
|
87
86
|
#
|
88
87
|
# Note that the request might or might not eventually be acted upon, as it might be disallowed when processing
|
89
88
|
# actually takes place. This is due to the fact that language file imports are handled by background processing.
|
90
|
-
|
89
|
+
# rubocop:todo Metrics/PerceivedComplexity
|
90
|
+
# rubocop:todo Metrics/ParameterLists
|
91
|
+
# rubocop:todo Metrics/MethodLength
|
92
|
+
# rubocop:todo Metrics/AbcSize
|
93
|
+
def upload(http_connection, merge = false, ignore_missing = false, label = nil, low_priority = false, minor_changes = false, force = false, rename_others = false, destination_path = nil) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/ParameterLists, Metrics/PerceivedComplexity
|
91
94
|
success = true
|
92
95
|
tries ||= 3
|
93
96
|
display = []
|
94
|
-
display.push(
|
95
|
-
display.push "#{StringUtil.checksumify(
|
96
|
-
if File.
|
97
|
-
|
98
|
-
File.open(
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
else
|
112
|
-
success = false
|
113
|
-
end
|
114
|
-
rescue
|
115
|
-
display.push StringUtil.failure("An error occured: #{$!}")
|
97
|
+
display.push(file_path)
|
98
|
+
display.push "#{StringUtil.checksumify(local_checksum.to_s)}..#{StringUtil.checksumify(remote_checksum.to_s)}"
|
99
|
+
if File.exist?(file_path)
|
100
|
+
if force or remote_checksum != local_checksum
|
101
|
+
File.open(file_path) do |file|
|
102
|
+
params = { 'file' => UploadIO.new(file, 'text/plain', file.path), 'merge' => merge, 'ignore_missing' => ignore_missing, 'label' => label, 'low_priority' => low_priority, 'minor_changes' => minor_changes }
|
103
|
+
params['name'] = destination_path unless destination_path.nil?
|
104
|
+
params['rename_others'] = rename_others
|
105
|
+
request = Net::HTTP::Put::Multipart.new(api_url, params)
|
106
|
+
WebTranslateIt::Util.add_fields(request)
|
107
|
+
display.push Util.handle_response(http_connection.request(request))
|
108
|
+
rescue Timeout::Error
|
109
|
+
puts StringUtil.failure('Request timeout. Will retry in 5 seconds.')
|
110
|
+
if (tries -= 1) > 0 # rubocop:todo Metrics/BlockNesting
|
111
|
+
sleep(5)
|
112
|
+
retry
|
113
|
+
else
|
116
114
|
success = false
|
117
115
|
end
|
116
|
+
rescue
|
117
|
+
display.push StringUtil.failure("An error occured: #{$!}")
|
118
|
+
success = false
|
118
119
|
end
|
119
120
|
else
|
120
|
-
display.push StringUtil.success(
|
121
|
+
display.push StringUtil.success('Skipped')
|
121
122
|
end
|
122
123
|
puts ArrayUtil.to_columns(display)
|
123
124
|
else
|
124
|
-
puts StringUtil.failure("Can't push #{
|
125
|
+
puts StringUtil.failure("Can't push #{file_path}. File doesn't exist locally.")
|
125
126
|
end
|
126
|
-
|
127
|
+
success
|
127
128
|
end
|
128
|
-
|
129
|
+
# rubocop:enable Metrics/AbcSize
|
130
|
+
# rubocop:enable Metrics/MethodLength
|
131
|
+
# rubocop:enable Metrics/ParameterLists
|
132
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
133
|
+
|
129
134
|
# Create a master language file to Web Translate It by performing a POST Request.
|
130
135
|
#
|
131
136
|
# Example of implementation:
|
@@ -137,53 +142,51 @@ module WebTranslateIt
|
|
137
142
|
# Note that the request might or might not eventually be acted upon, as it might be disallowed when processing
|
138
143
|
# actually takes place. This is due to the fact that language file imports are handled by background processing.
|
139
144
|
#
|
140
|
-
def create(http_connection, low_priority=false)
|
145
|
+
def create(http_connection, low_priority = false) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
141
146
|
success = true
|
142
147
|
tries ||= 3
|
143
148
|
display = []
|
144
149
|
display.push file_path
|
145
|
-
display.push "#{StringUtil.checksumify(
|
146
|
-
if File.
|
147
|
-
File.open(
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
else
|
159
|
-
success = false
|
160
|
-
end
|
161
|
-
rescue
|
162
|
-
display.push StringUtil.failure("An error occured: #{$!}")
|
150
|
+
display.push "#{StringUtil.checksumify(local_checksum.to_s)}..[ ]"
|
151
|
+
if File.exist?(file_path)
|
152
|
+
File.open(file_path) do |file|
|
153
|
+
request = Net::HTTP::Post::Multipart.new(api_url_for_create, { 'name' => file_path, 'file' => UploadIO.new(file, 'text/plain', file.path), 'low_priority' => low_priority })
|
154
|
+
WebTranslateIt::Util.add_fields(request)
|
155
|
+
display.push Util.handle_response(http_connection.request(request))
|
156
|
+
puts ArrayUtil.to_columns(display)
|
157
|
+
rescue Timeout::Error
|
158
|
+
puts StringUtil.failure('Request timeout. Will retry in 5 seconds.')
|
159
|
+
if (tries -= 1) > 0
|
160
|
+
sleep(5)
|
161
|
+
retry
|
162
|
+
else
|
163
163
|
success = false
|
164
164
|
end
|
165
|
+
rescue
|
166
|
+
display.push StringUtil.failure("An error occured: #{$!}")
|
167
|
+
success = false
|
165
168
|
end
|
166
169
|
else
|
167
|
-
puts StringUtil.failure("\nFile #{
|
170
|
+
puts StringUtil.failure("\nFile #{file_path} doesn't exist locally!")
|
168
171
|
end
|
169
|
-
|
172
|
+
success
|
170
173
|
end
|
171
|
-
|
174
|
+
|
172
175
|
# Delete a master language file from Web Translate It by performing a DELETE Request.
|
173
176
|
#
|
174
|
-
def delete(http_connection)
|
177
|
+
def delete(http_connection) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
175
178
|
success = true
|
176
179
|
tries ||= 3
|
177
180
|
display = []
|
178
181
|
display.push file_path
|
179
|
-
if File.
|
182
|
+
if File.exist?(file_path)
|
180
183
|
begin
|
181
184
|
request = Net::HTTP::Delete.new(api_url_for_delete)
|
182
185
|
WebTranslateIt::Util.add_fields(request)
|
183
186
|
display.push Util.handle_response(http_connection.request(request))
|
184
187
|
puts ArrayUtil.to_columns(display)
|
185
188
|
rescue Timeout::Error
|
186
|
-
puts StringUtil.failure(
|
189
|
+
puts StringUtil.failure('Request timeout. Will retry in 5 seconds.')
|
187
190
|
if (tries -= 1) > 0
|
188
191
|
sleep(5)
|
189
192
|
retry
|
@@ -195,46 +198,46 @@ module WebTranslateIt
|
|
195
198
|
success = false
|
196
199
|
end
|
197
200
|
else
|
198
|
-
puts StringUtil.failure("\nMaster file #{
|
201
|
+
puts StringUtil.failure("\nMaster file #{file_path} doesn't exist locally!")
|
199
202
|
end
|
200
|
-
|
203
|
+
success
|
201
204
|
end
|
202
205
|
|
203
206
|
def exists?
|
204
|
-
File.
|
207
|
+
File.exist?(file_path)
|
205
208
|
end
|
206
|
-
|
209
|
+
|
207
210
|
def modified_remotely?
|
208
|
-
fetch ==
|
211
|
+
fetch == '200 OK'
|
209
212
|
end
|
210
|
-
|
213
|
+
|
211
214
|
protected
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
end
|
215
|
+
|
216
|
+
# Convenience method which returns the date of last modification of a language file.
|
217
|
+
def last_modification
|
218
|
+
File.mtime(File.new(file_path, 'r'))
|
219
|
+
end
|
220
|
+
|
221
|
+
# Convenience method which returns the URL of the API endpoint for a locale.
|
222
|
+
def api_url
|
223
|
+
"/api/projects/#{api_key}/files/#{id}/locales/#{locale}"
|
224
|
+
end
|
225
|
+
|
226
|
+
def api_url_for_create
|
227
|
+
"/api/projects/#{api_key}/files"
|
228
|
+
end
|
229
|
+
|
230
|
+
def api_url_for_delete
|
231
|
+
"/api/projects/#{api_key}/files/#{id}"
|
232
|
+
end
|
233
|
+
|
234
|
+
def local_checksum
|
235
|
+
require 'digest/sha1'
|
236
|
+
begin
|
237
|
+
Digest::SHA1.hexdigest(File.read(file_path))
|
238
|
+
rescue
|
239
|
+
''
|
238
240
|
end
|
241
|
+
end
|
239
242
|
end
|
240
243
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
class ArrayUtil
|
2
2
|
def self.to_columns(arr)
|
3
|
-
if arr[0][0] ==
|
3
|
+
if arr[0][0] == '*'
|
4
4
|
"*#{StringUtil.backward_truncate(arr[0][1..-1])} | #{arr[1]} #{arr[2]}\n"
|
5
5
|
else
|
6
6
|
" #{StringUtil.backward_truncate(arr[0])} | #{arr[1]} #{arr[2]}\n"
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.chunk(arr, pieces=2)
|
11
|
-
len = arr.length
|
12
|
-
mid = (len/pieces)
|
10
|
+
def self.chunk(arr, pieces = 2) # rubocop:todo Metrics/MethodLength
|
11
|
+
len = arr.length
|
12
|
+
mid = (len / pieces)
|
13
13
|
chunks = []
|
14
14
|
start = 0
|
15
15
|
1.upto(pieces) do |i|
|
16
|
-
last = start+mid
|
17
|
-
last = last-1 unless len%pieces >= i
|
18
|
-
chunks << arr[start..last] || []
|
19
|
-
start = last+1
|
16
|
+
last = start + mid
|
17
|
+
last = last - 1 unless len % pieces >= i
|
18
|
+
chunks << (arr[start..last] || [])
|
19
|
+
start = last + 1
|
20
20
|
end
|
21
21
|
chunks
|
22
22
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
class HashUtil
|
2
|
-
def self.to_params(hash)
|
2
|
+
def self.to_params(hash) # rubocop:todo Metrics/MethodLength
|
3
3
|
params = ''
|
4
4
|
stack = []
|
5
5
|
|
6
6
|
hash.each do |k, v|
|
7
7
|
if v.is_a?(Hash)
|
8
|
-
stack << [k,v]
|
8
|
+
stack << [k, v]
|
9
9
|
else
|
10
10
|
params << "#{k}=#{v}&"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
stack.each do |parent,
|
15
|
-
|
14
|
+
stack.each do |parent, h|
|
15
|
+
h.each do |k, v|
|
16
16
|
if v.is_a?(Hash)
|
17
17
|
stack << ["#{parent}[#{k}]", v]
|
18
18
|
else
|
@@ -34,4 +34,4 @@ class Hash
|
|
34
34
|
end
|
35
35
|
self
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|
@@ -1,13 +1,10 @@
|
|
1
1
|
class StringUtil
|
2
|
-
|
3
2
|
def self.backward_truncate(str)
|
4
|
-
if str.length
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
return "..." << str[str.length-50+3..str.length]
|
10
|
-
end
|
3
|
+
return '...' << str[str.length - 50 + 3..str.length] if str.length > 50
|
4
|
+
|
5
|
+
spaces = ''
|
6
|
+
(50 - str.length).times { spaces << ' ' }
|
7
|
+
str.dup << spaces
|
11
8
|
end
|
12
9
|
|
13
10
|
def self.success(str)
|
@@ -1,55 +1,55 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
module WebTranslateIt
|
3
|
-
|
4
2
|
# A few useful functions
|
5
3
|
class Util
|
6
|
-
|
7
4
|
require 'multi_json'
|
8
|
-
|
5
|
+
|
9
6
|
# Return a string representing the gem version
|
10
7
|
# For example "1.8.3"
|
11
8
|
def self.version
|
12
9
|
Gem.loaded_specs['web_translate_it'].version
|
13
10
|
end
|
14
|
-
|
11
|
+
|
15
12
|
def self.calculate_percentage(processed, total)
|
16
13
|
return 0 if total == 0
|
17
|
-
|
14
|
+
|
15
|
+
((processed * 10) / total).to_f.ceil * 10
|
18
16
|
end
|
19
|
-
|
20
|
-
|
17
|
+
|
18
|
+
# rubocop:todo Metrics/PerceivedComplexity
|
19
|
+
# rubocop:todo Metrics/MethodLength
|
20
|
+
# rubocop:todo Metrics/AbcSize
|
21
|
+
def self.handle_response(response, return_response = false, raise_exception = false) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
21
22
|
if response.code.to_i >= 400 and response.code.to_i < 500
|
22
|
-
if raise_exception
|
23
|
-
|
24
|
-
|
25
|
-
puts StringUtil.failure(MultiJson.load(response.body)['error'])
|
26
|
-
end
|
23
|
+
raise "Error: #{MultiJson.load(response.body)['error']}" if raise_exception
|
24
|
+
|
25
|
+
puts StringUtil.failure(MultiJson.load(response.body)['error'])
|
27
26
|
elsif response.code.to_i == 500
|
28
|
-
if raise_exception
|
29
|
-
|
30
|
-
|
31
|
-
puts StringUtil.failure("Error: Server temporarily unavailable (Error 500).")
|
32
|
-
end
|
27
|
+
raise 'Error: Server temporarily unavailable (Error 500).' if raise_exception
|
28
|
+
|
29
|
+
puts StringUtil.failure('Error: Server temporarily unavailable (Error 500).')
|
33
30
|
else
|
34
31
|
return response.body if return_response
|
35
|
-
return StringUtil.success(
|
36
|
-
return StringUtil.success(
|
37
|
-
return StringUtil.success(
|
38
|
-
return StringUtil.success(
|
32
|
+
return StringUtil.success('OK') if response.code.to_i == 200
|
33
|
+
return StringUtil.success('Created') if response.code.to_i == 201
|
34
|
+
return StringUtil.success('Accepted') if response.code.to_i == 202
|
35
|
+
return StringUtil.success('Not Modified') if response.code.to_i == 304
|
39
36
|
return StringUtil.failure("Locked\n (another import in progress)") if response.code.to_i == 503
|
40
37
|
end
|
41
38
|
end
|
42
|
-
|
39
|
+
# rubocop:enable Metrics/AbcSize
|
40
|
+
# rubocop:enable Metrics/MethodLength
|
41
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
42
|
+
|
43
43
|
def self.add_fields(request)
|
44
|
-
request.add_field(
|
45
|
-
request.add_field(
|
46
|
-
request.add_field(
|
44
|
+
request.add_field('X-Client-Name', 'web_translate_it')
|
45
|
+
request.add_field('X-Client-Version', version)
|
46
|
+
request.add_field('Content-Type', 'application/json')
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
##
|
50
50
|
# Ask a question. Returns a true for yes, false for no, default for nil.
|
51
|
-
|
52
|
-
def self.ask_yes_no(question, default=nil)
|
51
|
+
|
52
|
+
def self.ask_yes_no(question, default = nil) # rubocop:todo Metrics/MethodLength
|
53
53
|
qstr = case default
|
54
54
|
when nil
|
55
55
|
'yn'
|
@@ -64,40 +64,37 @@ module WebTranslateIt
|
|
64
64
|
while result.nil?
|
65
65
|
result = ask("#{question} [#{qstr}]")
|
66
66
|
result = case result
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
else
|
75
|
-
nil
|
76
|
-
end
|
67
|
+
when /^[Yy].*/
|
68
|
+
true
|
69
|
+
when /^[Nn].*/
|
70
|
+
false
|
71
|
+
when '', nil
|
72
|
+
default
|
73
|
+
end
|
77
74
|
end
|
78
75
|
|
79
|
-
|
76
|
+
result
|
80
77
|
end
|
81
|
-
|
78
|
+
|
82
79
|
##
|
83
80
|
# Ask a question. Returns an answer.
|
84
81
|
|
85
|
-
def self.ask(question, default=nil)
|
82
|
+
def self.ask(question, default = nil)
|
86
83
|
question = question + " (Default: #{default})" unless default.nil?
|
87
|
-
print(question
|
88
|
-
|
84
|
+
print("#{question} ")
|
85
|
+
$stdout.flush
|
89
86
|
|
90
|
-
result =
|
91
|
-
result
|
87
|
+
result = $stdin.gets
|
88
|
+
result&.chomp!
|
92
89
|
result = default if result.nil? or result == ''
|
93
90
|
result
|
94
91
|
end
|
95
|
-
|
92
|
+
|
96
93
|
##
|
97
94
|
# Returns whether a terminal can display ansi colors
|
98
|
-
|
95
|
+
|
99
96
|
def self.can_display_colors?
|
100
|
-
!RUBY_PLATFORM.downcase.include?(
|
97
|
+
!RUBY_PLATFORM.downcase.include?('mingw32')
|
101
98
|
end
|
102
99
|
end
|
103
|
-
end
|
100
|
+
end
|
data/lib/web_translate_it.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'web_translate_it/connection'
|
4
2
|
require 'web_translate_it/util'
|
5
3
|
require 'web_translate_it/util/array_util'
|
@@ -16,15 +14,15 @@ require 'web_translate_it/command_line'
|
|
16
14
|
require 'web_translate_it/project'
|
17
15
|
|
18
16
|
module WebTranslateIt
|
19
|
-
|
20
|
-
def self.fetch_translations
|
17
|
+
def self.fetch_translations # rubocop:todo Metrics/AbcSize
|
21
18
|
config = Configuration.new
|
22
19
|
locale = I18n.locale.to_s
|
23
20
|
return if config.ignore_locales.include?(locale)
|
24
|
-
|
21
|
+
|
22
|
+
config.logger&.debug { " Fetching #{locale} language file(s) from WebTranslateIt" }
|
25
23
|
WebTranslateIt::Connection.new(config.api_key) do |http|
|
26
|
-
config.files.find_all{ |file| file.locale.in?([locale, I18n.locale]) }.each do |file|
|
27
|
-
|
24
|
+
config.files.find_all { |file| file.locale.in?([locale, I18n.locale]) }.each do |file|
|
25
|
+
file.fetch(http)
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
data/readme.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
[RubyDoc](https://rubydoc.info/github/webtranslateit/webtranslateit/master) |
|
4
4
|
[Report a bug](https://github.com/webtranslateit/webtranslateit/issues) |
|
5
|
-
[Support](https://webtranslateit.com/
|
6
|
-
[WebTranslateIt.com Homepage](https://webtranslateit.com
|
5
|
+
[Support](https://webtranslateit.com/support) |
|
6
|
+
[WebTranslateIt.com Homepage](https://webtranslateit.com)
|
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
|
|
@@ -74,6 +74,10 @@ If you’d like to specify another path for your configuration file, you can use
|
|
74
74
|
|
75
75
|
Now you’re all set and you can use the `wti` commands on your project.
|
76
76
|
|
77
|
+
## Using on multiple projects
|
78
|
+
|
79
|
+
Please refer to [our documentation about syncing multiple projects](https://github.com/webtranslateit/webtranslateit/wiki/Using-wti-with-multiple-projects).
|
80
|
+
|
77
81
|
## Usage
|
78
82
|
|
79
83
|
Execute `wti --help` to see the usage:
|
data/spec/spec_helper.rb
CHANGED
@@ -3,10 +3,9 @@ if ENV['COVERAGE']
|
|
3
3
|
SimpleCov.start
|
4
4
|
end
|
5
5
|
|
6
|
-
require File.expand_path('
|
6
|
+
require File.expand_path('../lib/web_translate_it', __dir__)
|
7
7
|
require 'rspec'
|
8
8
|
|
9
9
|
class I18n
|
10
|
-
def self.reload
|
11
|
-
end
|
10
|
+
def self.reload!; end
|
12
11
|
end
|