web_translate_it 2.5.4 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +13 -7
- data/lib/web_translate_it/auto_fetch.rb +2 -4
- data/lib/web_translate_it/command_line.rb +244 -251
- data/lib/web_translate_it/configuration.rb +32 -27
- 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 +40 -41
- metadata +45 -10
@@ -1,119 +1,122 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
module WebTranslateIt
|
3
|
-
class CommandLine
|
2
|
+
class CommandLine # rubocop:todo Metrics/ClassLength
|
4
3
|
require 'fileutils'
|
5
4
|
require 'set'
|
6
5
|
attr_accessor :configuration, :global_options, :command_options, :parameters
|
7
6
|
|
8
|
-
def initialize(command, command_options, global_options, parameters, project_path)
|
7
|
+
def initialize(command, command_options, global_options, parameters, project_path) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/MethodLength
|
9
8
|
self.command_options = command_options
|
10
9
|
self.parameters = parameters
|
11
10
|
unless command == 'init'
|
12
|
-
case command
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
11
|
+
message = case command
|
12
|
+
when 'pull'
|
13
|
+
'Pulling files'
|
14
|
+
when 'push'
|
15
|
+
'Pushing files'
|
16
|
+
when 'add'
|
17
|
+
'Creating master files'
|
18
|
+
when 'rm'
|
19
|
+
'Deleting files'
|
20
|
+
when 'mv'
|
21
|
+
'Moving files'
|
22
|
+
when 'addlocale'
|
23
|
+
'Adding locale'
|
24
|
+
when 'rmlocale'
|
25
|
+
'Deleting locale'
|
26
|
+
else
|
27
|
+
'Gathering information'
|
28
|
+
end
|
29
|
+
throb do
|
30
|
+
print " #{message}"
|
31
|
+
self.configuration = WebTranslateIt::Configuration.new(project_path, configuration_file_path)
|
32
|
+
print " #{message} on #{configuration.project_name}"
|
29
33
|
end
|
30
|
-
throb { print " #{message}"; self.configuration = WebTranslateIt::Configuration.new(project_path, configuration_file_path); print " #{message} on #{self.configuration.project_name}"; }
|
31
34
|
end
|
32
|
-
success =
|
33
|
-
exit 1
|
35
|
+
success = send(command)
|
36
|
+
exit 1 unless success
|
34
37
|
end
|
35
|
-
|
36
|
-
def pull
|
38
|
+
|
39
|
+
def pull # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
37
40
|
complete_success = true
|
38
|
-
|
41
|
+
$stdout.sync = true
|
39
42
|
before_pull_hook
|
40
43
|
# Selecting files to pull
|
41
44
|
files = []
|
42
45
|
fetch_locales_to_pull.each do |locale|
|
43
|
-
files |= configuration.files.find_all{ |file| file.locale == locale }
|
46
|
+
files |= configuration.files.find_all { |file| file.locale == locale }
|
44
47
|
end
|
45
48
|
found_files = []
|
46
49
|
parameters.each do |parameter|
|
47
|
-
found_files += files.find_all{ |file| File.fnmatch(parameter, file.file_path) }
|
50
|
+
found_files += files.find_all { |file| File.fnmatch(parameter, file.file_path) }
|
48
51
|
end
|
49
52
|
files = found_files if parameters.any?
|
50
|
-
files = files.uniq.sort{ |a,b| a.file_path <=> b.file_path }
|
53
|
+
files = files.uniq.sort { |a, b| a.file_path <=> b.file_path }
|
51
54
|
if files.size == 0
|
52
|
-
puts
|
55
|
+
puts 'No files to pull.'
|
53
56
|
else
|
54
57
|
# Now actually pulling files
|
55
58
|
time = Time.now
|
56
59
|
threads = []
|
57
|
-
n_threads = (files.size.to_f/3).ceil >= 10 ? 10 : (files.size.to_f/3).ceil
|
60
|
+
n_threads = (files.size.to_f / 3).ceil >= 10 ? 10 : (files.size.to_f / 3).ceil
|
58
61
|
ArrayUtil.chunk(files, n_threads).each do |file_array|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
next if file_array.empty?
|
63
|
+
|
64
|
+
threads << Thread.new(file_array) do |f_array|
|
65
|
+
WebTranslateIt::Connection.new(configuration.api_key) do |http|
|
66
|
+
f_array.each do |file|
|
67
|
+
success = file.fetch(http, command_options.force)
|
68
|
+
complete_success = false unless success
|
66
69
|
end
|
67
70
|
end
|
68
71
|
end
|
69
72
|
end
|
70
|
-
threads.each
|
73
|
+
threads.each(&:join)
|
71
74
|
time = Time.now - time
|
72
|
-
puts "Pulled #{files.size} files at #{(files.size/time).round} files/sec, using #{n_threads} threads."
|
75
|
+
puts "Pulled #{files.size} files at #{(files.size / time).round} files/sec, using #{n_threads} threads."
|
73
76
|
after_pull_hook
|
74
77
|
complete_success
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
78
81
|
def before_pull_hook
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
return unless configuration.before_pull
|
83
|
+
|
84
|
+
output = `#{configuration.before_pull}`
|
85
|
+
if $?.success?
|
86
|
+
puts output
|
87
|
+
else
|
88
|
+
abort 'Error: exit code for before_pull command is not zero'
|
86
89
|
end
|
87
90
|
end
|
88
91
|
|
89
92
|
def after_pull_hook
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
return unless configuration.after_pull
|
94
|
+
|
95
|
+
output = `#{configuration.after_pull}`
|
96
|
+
if $?.success?
|
97
|
+
puts output
|
98
|
+
else
|
99
|
+
abort 'Error: exit code for after_pull command is not zero'
|
97
100
|
end
|
98
101
|
end
|
99
102
|
|
100
|
-
def push
|
103
|
+
def push # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
101
104
|
complete_success = true
|
102
|
-
|
105
|
+
$stdout.sync = true
|
103
106
|
before_push_hook
|
104
107
|
WebTranslateIt::Connection.new(configuration.api_key) do |http|
|
105
108
|
fetch_locales_to_push(configuration).each do |locale|
|
106
|
-
if parameters.any?
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
109
|
+
files = if parameters.any?
|
110
|
+
configuration.files.find_all { |file| parameters.include?(file.file_path) }.sort { |a, b| a.file_path <=> b.file_path }
|
111
|
+
else
|
112
|
+
configuration.files.find_all { |file| file.locale == locale }.sort { |a, b| a.file_path <=> b.file_path }
|
113
|
+
end
|
111
114
|
if files.size == 0
|
112
115
|
puts "Couldn't find any local files registered on WebTranslateIt to push."
|
113
116
|
else
|
114
117
|
files.each do |file|
|
115
118
|
success = file.upload(http, command_options[:merge], command_options.ignore_missing, command_options.label, command_options.low_priority, command_options[:minor], command_options.force)
|
116
|
-
complete_success = false
|
119
|
+
complete_success = false unless success
|
117
120
|
end
|
118
121
|
end
|
119
122
|
end
|
@@ -123,135 +126,135 @@ module WebTranslateIt
|
|
123
126
|
end
|
124
127
|
|
125
128
|
def before_push_hook
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
return unless configuration.before_push
|
130
|
+
|
131
|
+
output = `#{configuration.before_push}`
|
132
|
+
if $?.success?
|
133
|
+
puts output
|
134
|
+
else
|
135
|
+
abort 'Error: exit code for before_push command is not zero'
|
133
136
|
end
|
134
137
|
end
|
135
138
|
|
136
139
|
def after_push_hook
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
140
|
+
return unless configuration.after_push
|
141
|
+
|
142
|
+
output = `#{configuration.after_push}`
|
143
|
+
if $?.success?
|
144
|
+
puts output
|
145
|
+
else
|
146
|
+
abort 'Error: exit code for after_push command is not zero'
|
144
147
|
end
|
145
148
|
end
|
146
|
-
|
147
|
-
def add
|
149
|
+
|
150
|
+
def add # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
148
151
|
complete_success = true
|
149
|
-
|
152
|
+
$stdout.sync = true
|
150
153
|
if parameters == []
|
151
|
-
puts StringUtil.failure(
|
152
|
-
puts
|
154
|
+
puts StringUtil.failure('Error: You must provide the path to the master file to add.')
|
155
|
+
puts 'Usage: wti add path/to/master_file_1 path/to/master_file_2 ...'
|
153
156
|
exit
|
154
157
|
end
|
155
158
|
WebTranslateIt::Connection.new(configuration.api_key) do |http|
|
156
|
-
|
157
|
-
to_add = parameters.reject{ |param| added.include?(File.expand_path(param))}
|
159
|
+
added = configuration.files.find_all { |file| file.locale == configuration.source_locale }.collect { |file| File.expand_path(file.file_path) }.to_set
|
160
|
+
to_add = parameters.reject { |param| added.include?(File.expand_path(param)) }
|
158
161
|
if to_add.any?
|
159
162
|
to_add.each do |param|
|
160
|
-
file = TranslationFile.new(nil, param.gsub(/ /,
|
163
|
+
file = TranslationFile.new(nil, param.gsub(/ /, '\\ '), nil, configuration.api_key)
|
161
164
|
success = file.create(http, command_options.low_priority)
|
162
|
-
complete_success = false
|
165
|
+
complete_success = false unless success
|
163
166
|
end
|
164
167
|
else
|
165
|
-
puts
|
168
|
+
puts 'No new master file to add.'
|
166
169
|
end
|
167
170
|
end
|
168
171
|
complete_success
|
169
172
|
end
|
170
173
|
|
171
|
-
def rm
|
174
|
+
def rm # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
172
175
|
complete_success = true
|
173
|
-
|
176
|
+
$stdout.sync = true
|
174
177
|
if parameters == []
|
175
|
-
puts StringUtil.failure(
|
176
|
-
puts
|
178
|
+
puts StringUtil.failure('Error: You must provide the path to the master file to remove.')
|
179
|
+
puts 'Usage: wti rm path/to/master_file_1 path/to/master_file_2 ...'
|
177
180
|
exit
|
178
181
|
end
|
179
|
-
WebTranslateIt::Connection.new(configuration.api_key) do |http|
|
182
|
+
WebTranslateIt::Connection.new(configuration.api_key) do |http| # rubocop:todo Metrics/BlockLength
|
180
183
|
parameters.each do |param|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
complete_success = false if !success
|
184
|
+
next unless Util.ask_yes_no("Are you sure you want to delete the master file #{param}?\nThis will also delete its target files and translations.", false)
|
185
|
+
|
186
|
+
files = configuration.files.find_all { |file| file.file_path == param }
|
187
|
+
if files.any?
|
188
|
+
files.each do |master_file|
|
189
|
+
master_file.delete(http)
|
190
|
+
# delete files
|
191
|
+
if File.exist?(master_file.file_path)
|
192
|
+
success = File.delete(master_file.file_path)
|
193
|
+
puts StringUtil.success("Deleted master file #{master_file.file_path}.") if success
|
194
|
+
end
|
195
|
+
complete_success = false unless success
|
196
|
+
configuration.files.find_all { |file| file.master_id == master_file.id }.each do |target_file|
|
197
|
+
if File.exist?(target_file.file_path)
|
198
|
+
success = File.delete(target_file.file_path)
|
199
|
+
puts StringUtil.success("Deleted target file #{target_file.file_path}.") if success
|
200
|
+
else
|
201
|
+
puts StringUtil.failure("Target file #{target_file.file_path} doesn’t exist locally")
|
200
202
|
end
|
203
|
+
complete_success = false unless success
|
201
204
|
end
|
202
|
-
puts StringUtil.success("All done.") if complete_success
|
203
|
-
else
|
204
|
-
puts StringUtil.failure("#{param}: File doesn’t exist on project.")
|
205
205
|
end
|
206
|
+
puts StringUtil.success('All done.') if complete_success
|
207
|
+
else
|
208
|
+
puts StringUtil.failure("#{param}: File doesn’t exist on project.")
|
206
209
|
end
|
207
210
|
end
|
208
211
|
end
|
209
212
|
complete_success
|
210
213
|
end
|
211
|
-
|
212
|
-
def mv
|
214
|
+
|
215
|
+
def mv # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
213
216
|
complete_success = true
|
214
|
-
|
217
|
+
$stdout.sync = true
|
215
218
|
if parameters.count != 2
|
216
|
-
puts StringUtil.failure(
|
217
|
-
puts
|
219
|
+
puts StringUtil.failure('Error: You must provide the source path and destination path of the master file to move.')
|
220
|
+
puts 'Usage: wti mv path/to/master_file_old_path path/to/master_file_new_path ...'
|
218
221
|
exit
|
219
222
|
end
|
220
223
|
source = parameters[0]
|
221
224
|
destination = parameters[1]
|
222
225
|
WebTranslateIt::Connection.new(configuration.api_key) do |http|
|
223
226
|
if Util.ask_yes_no("Are you sure you want to move the master file #{source} and its target files?", true)
|
224
|
-
configuration.files.find_all{ |file| file.file_path == source }.each do |master_file|
|
227
|
+
configuration.files.find_all { |file| file.file_path == source }.each do |master_file|
|
225
228
|
master_file.upload(http, false, false, nil, false, false, true, true, destination)
|
226
229
|
# move master file
|
227
|
-
if File.
|
228
|
-
success = File.rename(source, destination) if File.
|
230
|
+
if File.exist?(source)
|
231
|
+
success = File.rename(source, destination) if File.exist?(source)
|
229
232
|
puts StringUtil.success("Moved master file #{master_file.file_path}.") if success
|
230
233
|
end
|
231
|
-
complete_success = false
|
232
|
-
configuration.files.find_all{ |file| file.master_id == master_file.id }.each do |target_file|
|
233
|
-
if File.
|
234
|
+
complete_success = false unless success
|
235
|
+
configuration.files.find_all { |file| file.master_id == master_file.id }.each do |target_file|
|
236
|
+
if File.exist?(target_file.file_path)
|
234
237
|
success = File.delete(target_file.file_path)
|
235
|
-
complete_success = false
|
238
|
+
complete_success = false unless success
|
236
239
|
end
|
237
240
|
end
|
238
241
|
configuration.reload
|
239
|
-
configuration.files.find_all{ |file| file.master_id == master_file.id }.each do |target_file|
|
242
|
+
configuration.files.find_all { |file| file.master_id == master_file.id }.each do |target_file|
|
240
243
|
success = target_file.fetch(http)
|
241
|
-
complete_success = false
|
244
|
+
complete_success = false unless success
|
242
245
|
end
|
243
|
-
puts StringUtil.success(
|
246
|
+
puts StringUtil.success('All done.') if complete_success
|
244
247
|
end
|
245
248
|
end
|
246
249
|
end
|
247
250
|
complete_success
|
248
251
|
end
|
249
|
-
|
250
|
-
def addlocale
|
251
|
-
|
252
|
+
|
253
|
+
def addlocale # rubocop:todo Metrics/MethodLength
|
254
|
+
$stdout.sync = true
|
252
255
|
if parameters == []
|
253
|
-
puts StringUtil.failure(
|
254
|
-
puts
|
256
|
+
puts StringUtil.failure('Locale code missing.')
|
257
|
+
puts 'Usage: wti addlocale fr es ...'
|
255
258
|
exit 1
|
256
259
|
end
|
257
260
|
parameters.each do |param|
|
@@ -259,94 +262,93 @@ module WebTranslateIt
|
|
259
262
|
WebTranslateIt::Connection.new(configuration.api_key) do
|
260
263
|
WebTranslateIt::Project.create_locale(param)
|
261
264
|
end
|
262
|
-
puts
|
265
|
+
puts 'Done.'
|
263
266
|
end
|
264
267
|
end
|
265
|
-
|
266
|
-
def rmlocale
|
267
|
-
|
268
|
+
|
269
|
+
def rmlocale # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
270
|
+
$stdout.sync = true
|
268
271
|
if parameters == []
|
269
|
-
puts StringUtil.failure(
|
270
|
-
puts
|
272
|
+
puts StringUtil.failure('Error: You must provide the locale code to remove.')
|
273
|
+
puts 'Usage: wti rmlocale fr es ...'
|
271
274
|
exit 1
|
272
275
|
end
|
273
276
|
parameters.each do |param|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
puts "Done."
|
277
|
+
next unless Util.ask_yes_no("Are you certain you want to delete the locale #{param.upcase}?\nThis will also delete its files and translations.", false)
|
278
|
+
|
279
|
+
print StringUtil.success("Deleting locale #{param.upcase}... ")
|
280
|
+
WebTranslateIt::Connection.new(configuration.api_key) do
|
281
|
+
WebTranslateIt::Project.delete_locale(param)
|
280
282
|
end
|
283
|
+
puts 'Done.'
|
281
284
|
end
|
282
285
|
end
|
283
|
-
|
284
|
-
def init
|
285
|
-
puts
|
286
|
+
|
287
|
+
def init # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
288
|
+
puts '# Initializing project'
|
286
289
|
if parameters.any?
|
287
290
|
api_key = parameters[0]
|
288
291
|
path = '.wti'
|
289
292
|
else
|
290
|
-
api_key = Util.ask(
|
291
|
-
path = Util.ask(
|
293
|
+
api_key = Util.ask(' Project API Key:')
|
294
|
+
path = Util.ask(' Path to configuration file:', '.wti')
|
292
295
|
end
|
293
|
-
FileUtils.mkpath(path.split('/')[0..path.split('/').size-2].join('/')) unless path.split('/').size == 1
|
296
|
+
FileUtils.mkpath(path.split('/')[0..path.split('/').size - 2].join('/')) unless path.split('/').size == 1
|
294
297
|
project = YAML.load WebTranslateIt::Project.fetch_info(api_key)
|
295
298
|
project_info = project['project']
|
296
|
-
if File.
|
299
|
+
if File.exist?(path) && !File.writable?(path)
|
297
300
|
puts StringUtil.failure("Error: `#{path}` file is not writable.")
|
298
301
|
exit 1
|
299
302
|
end
|
300
|
-
File.open(path, 'w'){ |file| file << generate_configuration(api_key, project_info) }
|
301
|
-
puts
|
303
|
+
File.open(path, 'w') { |file| file << generate_configuration(api_key, project_info) }
|
304
|
+
puts ''
|
302
305
|
puts " The project #{project_info['name']} was successfully initialized."
|
303
|
-
puts
|
304
|
-
if project_info[
|
305
|
-
puts
|
306
|
-
puts
|
307
|
-
puts
|
306
|
+
puts ''
|
307
|
+
if project_info['source_locale']['code'].nil? || project_info['target_locales'].size <= 1 || project_info['project_files'].none?
|
308
|
+
puts ''
|
309
|
+
puts ' There are a few more things to set up:'
|
310
|
+
puts ''
|
308
311
|
end
|
309
|
-
if project_info[
|
312
|
+
if project_info['source_locale']['code'].nil?
|
310
313
|
puts " *) You don't have a source locale setup."
|
311
|
-
puts
|
312
|
-
puts
|
314
|
+
puts ' Add the source locale with: `wti addlocale <locale_code>`'
|
315
|
+
puts ''
|
313
316
|
end
|
314
|
-
if project_info[
|
317
|
+
if project_info['target_locales'].size <= 1
|
315
318
|
puts " *) You don't have a target locale setup."
|
316
|
-
puts
|
317
|
-
puts
|
319
|
+
puts ' Add the first target locale with: `wti addlocale <locale_code>`'
|
320
|
+
puts ''
|
318
321
|
end
|
319
|
-
if project_info[
|
322
|
+
if project_info['project_files'].none?
|
320
323
|
puts " *) You don't have linguistic files setup."
|
321
|
-
puts
|
322
|
-
puts
|
324
|
+
puts ' Add a master file with: `wti add <path/to/file.xml>`'
|
325
|
+
puts ''
|
323
326
|
end
|
324
|
-
puts
|
325
|
-
puts
|
326
|
-
|
327
|
+
puts 'You can now use `wti` to push and pull your language files.'
|
328
|
+
puts 'Check `wti --help` for help.'
|
329
|
+
true
|
327
330
|
end
|
328
|
-
|
329
|
-
def match
|
330
|
-
configuration.files.find_all{ |mf| mf.locale == configuration.source_locale }.each do |master_file|
|
331
|
-
if
|
332
|
-
puts StringUtil.failure(master_file.file_path) + " (#{master_file.locale})"
|
333
|
-
else
|
331
|
+
|
332
|
+
def match # rubocop:todo Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
333
|
+
configuration.files.find_all { |mf| mf.locale == configuration.source_locale }.each do |master_file|
|
334
|
+
if File.exist?(master_file.file_path)
|
334
335
|
puts StringUtil.important(master_file.file_path) + " (#{master_file.locale})"
|
336
|
+
else
|
337
|
+
puts StringUtil.failure(master_file.file_path) + " (#{master_file.locale})"
|
335
338
|
end
|
336
|
-
configuration.files.find_all{ |f| f.master_id == master_file.id }.each do |file|
|
337
|
-
if
|
338
|
-
puts StringUtil.failure("- #{file.file_path}") + " (#{file.locale})"
|
339
|
-
else
|
339
|
+
configuration.files.find_all { |f| f.master_id == master_file.id }.each do |file|
|
340
|
+
if File.exist?(file.file_path)
|
340
341
|
puts "- #{file.file_path}" + " (#{file.locale})"
|
342
|
+
else
|
343
|
+
puts StringUtil.failure("- #{file.file_path}") + " (#{file.locale})"
|
341
344
|
end
|
342
345
|
end
|
343
346
|
end
|
344
|
-
|
347
|
+
true
|
345
348
|
end
|
346
|
-
|
347
|
-
def status
|
349
|
+
|
350
|
+
def status # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
348
351
|
stats = YAML.load(Project.fetch_stats(configuration.api_key))
|
349
|
-
stale = false
|
350
352
|
completely_translated = true
|
351
353
|
completely_proofread = true
|
352
354
|
stats.each do |locale, values|
|
@@ -356,32 +358,28 @@ module WebTranslateIt
|
|
356
358
|
completely_proofread = false if percent_completed != 100
|
357
359
|
puts "#{locale}: #{percent_translated}% translated, #{percent_completed}% completed."
|
358
360
|
end
|
359
|
-
exit 100
|
360
|
-
exit 101
|
361
|
-
|
361
|
+
exit 100 unless completely_translated
|
362
|
+
exit 101 unless completely_proofread
|
363
|
+
true
|
362
364
|
end
|
363
|
-
|
364
|
-
def fetch_locales_to_pull
|
365
|
+
|
366
|
+
def fetch_locales_to_pull # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
365
367
|
if command_options.locale
|
366
368
|
command_options.locale.split.each do |locale|
|
367
369
|
puts "Locale #{locale} doesn't exist -- `wti addlocale #{locale}` to add it." unless configuration.target_locales.include?(locale)
|
368
370
|
end
|
369
371
|
locales = command_options.locale.split
|
372
|
+
elsif configuration.needed_locales.any?
|
373
|
+
locales = configuration.needed_locales
|
370
374
|
else
|
371
|
-
|
372
|
-
|
373
|
-
else
|
374
|
-
locales = configuration.target_locales
|
375
|
-
if configuration.ignore_locales.any?
|
376
|
-
configuration.ignore_locales.each{ |locale_to_delete| locales.delete(locale_to_delete) }
|
377
|
-
end
|
378
|
-
end
|
375
|
+
locales = configuration.target_locales
|
376
|
+
configuration.ignore_locales.each { |locale_to_delete| locales.delete(locale_to_delete) } if configuration.ignore_locales.any?
|
379
377
|
end
|
380
378
|
locales.push(configuration.source_locale) if command_options.all
|
381
|
-
|
379
|
+
locales.uniq
|
382
380
|
end
|
383
|
-
|
384
|
-
def fetch_locales_to_push(configuration)
|
381
|
+
|
382
|
+
def fetch_locales_to_push(configuration) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
385
383
|
if command_options.locale
|
386
384
|
command_options.locale.split.each do |locale|
|
387
385
|
puts "Locale #{locale} doesn't exist -- `wti addlocale #{locale}` to add it." unless configuration.target_locales.include?(locale)
|
@@ -391,65 +389,60 @@ module WebTranslateIt
|
|
391
389
|
locales = [configuration.source_locale]
|
392
390
|
end
|
393
391
|
if command_options.all
|
394
|
-
puts
|
392
|
+
puts '`wti push --all` was deprecated in wti 2.3. Use `wti push --target` instead.'
|
395
393
|
return []
|
396
394
|
elsif command_options.target
|
397
|
-
locales = configuration.target_locales.reject{ |locale| locale == configuration.source_locale }
|
395
|
+
locales = configuration.target_locales.reject { |locale| locale == configuration.source_locale }
|
398
396
|
end
|
399
|
-
|
397
|
+
locales.uniq
|
400
398
|
end
|
401
|
-
|
399
|
+
|
402
400
|
def configuration_file_path
|
403
|
-
if
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
end
|
416
|
-
else
|
417
|
-
return 'config/translation.yml'
|
418
|
-
end
|
419
|
-
else
|
420
|
-
return '.wti'
|
421
|
-
end
|
422
|
-
end
|
401
|
+
return command_options.config if command_options.config
|
402
|
+
|
403
|
+
return '.wti' unless File.exist?('config/translation.yml')
|
404
|
+
|
405
|
+
puts 'Warning: `config/translation.yml` is deprecated in favour of a `.wti` file.'
|
406
|
+
return 'config/translation.yml' unless Util.ask_yes_no('Would you like to migrate your configuration now?', true)
|
407
|
+
|
408
|
+
require 'fileutils'
|
409
|
+
return '.wti' if FileUtils.mv('config/translation.yml', '.wti')
|
410
|
+
|
411
|
+
puts 'Couldn’t move `config/translation.yml`.'
|
412
|
+
false
|
423
413
|
end
|
424
|
-
|
414
|
+
|
425
415
|
def generate_configuration(api_key, project_info)
|
426
|
-
|
427
|
-
api_key: #{api_key}
|
416
|
+
<<~FILE
|
417
|
+
api_key: #{api_key}
|
428
418
|
|
429
|
-
# Optional: locales not to sync with WebTranslateIt.
|
430
|
-
# Takes a string, a symbol, or an array of string or symbol.
|
431
|
-
# More information here: https://github.com/AtelierConvivialite/webtranslateit/wiki
|
432
|
-
# ignore_locales: '#{project_info[
|
419
|
+
# Optional: locales not to sync with WebTranslateIt.
|
420
|
+
# Takes a string, a symbol, or an array of string or symbol.
|
421
|
+
# More information here: https://github.com/AtelierConvivialite/webtranslateit/wiki
|
422
|
+
# ignore_locales: '#{project_info['source_locale']['code']}'
|
433
423
|
|
434
|
-
# Or if you prefer a list of locales to sync with WebTranslateIt:
|
435
|
-
# needed_locales: #{project_info[
|
424
|
+
# Or if you prefer a list of locales to sync with WebTranslateIt:
|
425
|
+
# needed_locales: #{project_info['target_locales'].map { |locale| locale['code'] }}
|
436
426
|
|
437
|
-
# Optional
|
438
|
-
#
|
439
|
-
#
|
440
|
-
#
|
441
|
-
# before_push: "echo 'some unix command'" # Command executed before pushing files
|
442
|
-
# after_push: "touch tmp/restart.txt" # Command executed after pushing files
|
427
|
+
# Optional: files not to sync with WebTranslateIt.
|
428
|
+
# Takes an array of globs.
|
429
|
+
# ignore_files: ['somefile*.csv']
|
443
430
|
|
444
|
-
#
|
445
|
-
#
|
431
|
+
# Optional
|
432
|
+
# before_pull: "echo 'some unix command'" # Command executed before pulling files
|
433
|
+
# after_pull: "touch tmp/restart.txt" # Command executed after pulling files
|
434
|
+
#
|
435
|
+
# before_push: "echo 'some unix command'" # Command executed before pushing files
|
436
|
+
# after_push: "touch tmp/restart.txt" # Command executed after pushing files
|
446
437
|
|
447
|
-
|
448
|
-
|
438
|
+
# Silence SSL errors
|
439
|
+
# silence_errors: true
|
440
|
+
|
441
|
+
FILE
|
449
442
|
end
|
450
443
|
|
451
|
-
def throb
|
452
|
-
throb = %w
|
444
|
+
def throb # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
445
|
+
throb = %w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏]
|
453
446
|
throb.reverse! if rand > 0.5
|
454
447
|
i = rand throb.length
|
455
448
|
|
@@ -462,11 +455,11 @@ FILE
|
|
462
455
|
dot.call
|
463
456
|
end
|
464
457
|
yield
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
end
|
458
|
+
ensure
|
459
|
+
if thread
|
460
|
+
thread.kill
|
461
|
+
puts "\r\e[0G#\e[?25h"
|
470
462
|
end
|
471
463
|
end
|
464
|
+
end
|
472
465
|
end
|