web_translate_it 2.5.4 → 2.6.2
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 +22 -7
- data/lib/web_translate_it/auto_fetch.rb +2 -4
- data/lib/web_translate_it/command_line.rb +257 -255
- data/lib/web_translate_it/configuration.rb +32 -29
- data/lib/web_translate_it/connection.rb +22 -34
- data/lib/web_translate_it/project.rb +22 -25
- data/lib/web_translate_it/string.rb +85 -84
- data/lib/web_translate_it/term.rb +65 -65
- data/lib/web_translate_it/term_translation.rb +34 -36
- data/lib/web_translate_it/translation.rb +25 -32
- data/lib/web_translate_it/translation_file.rb +109 -106
- 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 +51 -54
- data/lib/web_translate_it.rb +7 -7
- data/readme.md +13 -9
- 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 +51 -16
@@ -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 }
|
51
|
-
if files.
|
52
|
-
puts
|
53
|
+
files = files.uniq.sort { |a, b| a.file_path <=> b.file_path }
|
54
|
+
if files.empty?
|
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 $CHILD_STATUS.success?
|
86
|
+
puts output
|
87
|
+
else
|
88
|
+
abort "Error: before_pull command exited with: #{output}"
|
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 $CHILD_STATUS.success?
|
97
|
+
puts output
|
98
|
+
else
|
99
|
+
abort "Error: after_pull command exited with: #{output}"
|
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
|
-
|
111
|
-
if files.
|
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
|
114
|
+
if files.empty?
|
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 $CHILD_STATUS.success?
|
133
|
+
puts output
|
134
|
+
else
|
135
|
+
abort "Error: before_push command exited with: #{output}"
|
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 $CHILD_STATUS.success?
|
144
|
+
puts output
|
145
|
+
else
|
146
|
+
abort "Error: after_push command exited with: #{output}"
|
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,97 @@ 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(
|
292
|
-
end
|
293
|
-
FileUtils.mkpath(path.split('/')[0..path.split('/').size-2].join('/')) unless path.split('/').size == 1
|
294
|
-
project =
|
293
|
+
api_key = Util.ask(' Project API Key:')
|
294
|
+
path = Util.ask(' Path to configuration file:', '.wti')
|
295
|
+
end
|
296
|
+
FileUtils.mkpath(path.split('/')[0..path.split('/').size - 2].join('/')) unless path.split('/').size == 1
|
297
|
+
project = if RUBY_VERSION >= '3.1'
|
298
|
+
YAML.safe_load WebTranslateIt::Project.fetch_info(api_key), permitted_classes: [Time]
|
299
|
+
else
|
300
|
+
YAML.load WebTranslateIt::Project.fetch_info(api_key)
|
301
|
+
end
|
295
302
|
project_info = project['project']
|
296
|
-
if File.
|
303
|
+
if File.exist?(path) && !File.writable?(path)
|
297
304
|
puts StringUtil.failure("Error: `#{path}` file is not writable.")
|
298
305
|
exit 1
|
299
306
|
end
|
300
|
-
File.open(path, 'w'){ |file| file << generate_configuration(api_key, project_info) }
|
301
|
-
puts
|
307
|
+
File.open(path, 'w') { |file| file << generate_configuration(api_key, project_info) }
|
308
|
+
puts ''
|
302
309
|
puts " The project #{project_info['name']} was successfully initialized."
|
303
|
-
puts
|
304
|
-
if project_info[
|
305
|
-
puts
|
306
|
-
puts
|
307
|
-
puts
|
310
|
+
puts ''
|
311
|
+
if project_info['source_locale']['code'].nil? || project_info['target_locales'].size <= 1 || project_info['project_files'].none?
|
312
|
+
puts ''
|
313
|
+
puts ' There are a few more things to set up:'
|
314
|
+
puts ''
|
308
315
|
end
|
309
|
-
if project_info[
|
316
|
+
if project_info['source_locale']['code'].nil?
|
310
317
|
puts " *) You don't have a source locale setup."
|
311
|
-
puts
|
312
|
-
puts
|
318
|
+
puts ' Add the source locale with: `wti addlocale <locale_code>`'
|
319
|
+
puts ''
|
313
320
|
end
|
314
|
-
if project_info[
|
321
|
+
if project_info['target_locales'].size <= 1
|
315
322
|
puts " *) You don't have a target locale setup."
|
316
|
-
puts
|
317
|
-
puts
|
323
|
+
puts ' Add the first target locale with: `wti addlocale <locale_code>`'
|
324
|
+
puts ''
|
318
325
|
end
|
319
|
-
if project_info[
|
326
|
+
if project_info['project_files'].none?
|
320
327
|
puts " *) You don't have linguistic files setup."
|
321
|
-
puts
|
322
|
-
puts
|
328
|
+
puts ' Add a master file with: `wti add <path/to/file.xml>`'
|
329
|
+
puts ''
|
323
330
|
end
|
324
|
-
puts
|
325
|
-
puts
|
326
|
-
|
331
|
+
puts 'You can now use `wti` to push and pull your language files.'
|
332
|
+
puts 'Check `wti --help` for help.'
|
333
|
+
true
|
327
334
|
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
|
335
|
+
|
336
|
+
def match # rubocop:todo Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
337
|
+
configuration.files.find_all { |mf| mf.locale == configuration.source_locale }.each do |master_file|
|
338
|
+
if File.exist?(master_file.file_path)
|
334
339
|
puts StringUtil.important(master_file.file_path) + " (#{master_file.locale})"
|
340
|
+
else
|
341
|
+
puts StringUtil.failure(master_file.file_path) + " (#{master_file.locale})"
|
335
342
|
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
|
343
|
+
configuration.files.find_all { |f| f.master_id == master_file.id }.each do |file|
|
344
|
+
if File.exist?(file.file_path)
|
340
345
|
puts "- #{file.file_path}" + " (#{file.locale})"
|
346
|
+
else
|
347
|
+
puts StringUtil.failure("- #{file.file_path}") + " (#{file.locale})"
|
341
348
|
end
|
342
349
|
end
|
343
350
|
end
|
344
|
-
|
351
|
+
true
|
345
352
|
end
|
346
|
-
|
347
|
-
def status
|
353
|
+
|
354
|
+
def status # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
348
355
|
stats = YAML.load(Project.fetch_stats(configuration.api_key))
|
349
|
-
stale = false
|
350
356
|
completely_translated = true
|
351
357
|
completely_proofread = true
|
352
358
|
stats.each do |locale, values|
|
@@ -356,32 +362,28 @@ module WebTranslateIt
|
|
356
362
|
completely_proofread = false if percent_completed != 100
|
357
363
|
puts "#{locale}: #{percent_translated}% translated, #{percent_completed}% completed."
|
358
364
|
end
|
359
|
-
exit 100
|
360
|
-
exit 101
|
361
|
-
|
365
|
+
exit 100 unless completely_translated
|
366
|
+
exit 101 unless completely_proofread
|
367
|
+
true
|
362
368
|
end
|
363
|
-
|
364
|
-
def fetch_locales_to_pull
|
369
|
+
|
370
|
+
def fetch_locales_to_pull # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
365
371
|
if command_options.locale
|
366
372
|
command_options.locale.split.each do |locale|
|
367
373
|
puts "Locale #{locale} doesn't exist -- `wti addlocale #{locale}` to add it." unless configuration.target_locales.include?(locale)
|
368
374
|
end
|
369
375
|
locales = command_options.locale.split
|
376
|
+
elsif configuration.needed_locales.any?
|
377
|
+
locales = configuration.needed_locales
|
370
378
|
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
|
379
|
+
locales = configuration.target_locales
|
380
|
+
configuration.ignore_locales.each { |locale_to_delete| locales.delete(locale_to_delete) } if configuration.ignore_locales.any?
|
379
381
|
end
|
380
382
|
locales.push(configuration.source_locale) if command_options.all
|
381
|
-
|
383
|
+
locales.uniq
|
382
384
|
end
|
383
|
-
|
384
|
-
def fetch_locales_to_push(configuration)
|
385
|
+
|
386
|
+
def fetch_locales_to_push(configuration) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
385
387
|
if command_options.locale
|
386
388
|
command_options.locale.split.each do |locale|
|
387
389
|
puts "Locale #{locale} doesn't exist -- `wti addlocale #{locale}` to add it." unless configuration.target_locales.include?(locale)
|
@@ -391,65 +393,65 @@ module WebTranslateIt
|
|
391
393
|
locales = [configuration.source_locale]
|
392
394
|
end
|
393
395
|
if command_options.all
|
394
|
-
puts
|
396
|
+
puts '`wti push --all` was deprecated in wti 2.3. Use `wti push --target` instead.'
|
395
397
|
return []
|
396
398
|
elsif command_options.target
|
397
|
-
locales = configuration.target_locales.reject{ |locale| locale == configuration.source_locale }
|
399
|
+
locales = configuration.target_locales.reject { |locale| locale == configuration.source_locale }
|
398
400
|
end
|
399
|
-
|
401
|
+
locales.uniq
|
400
402
|
end
|
401
|
-
|
403
|
+
|
402
404
|
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
|
405
|
+
return command_options.config if command_options.config
|
406
|
+
|
407
|
+
return '.wti' unless File.exist?('config/translation.yml')
|
408
|
+
|
409
|
+
puts 'Warning: `config/translation.yml` is deprecated in favour of a `.wti` file.'
|
410
|
+
return 'config/translation.yml' unless Util.ask_yes_no('Would you like to migrate your configuration now?', true)
|
411
|
+
|
412
|
+
require 'fileutils'
|
413
|
+
return '.wti' if FileUtils.mv('config/translation.yml', '.wti')
|
414
|
+
|
415
|
+
puts 'Couldn’t move `config/translation.yml`.'
|
416
|
+
false
|
423
417
|
end
|
424
|
-
|
418
|
+
|
425
419
|
def generate_configuration(api_key, project_info)
|
426
|
-
|
427
|
-
|
420
|
+
<<~FILE
|
421
|
+
# Required - The Project API Token from WebTranslateIt.com
|
422
|
+
# More information: https://github.com/webtranslateit/webtranslateit/wiki#configuration-file
|
423
|
+
|
424
|
+
api_key: #{api_key}
|
425
|
+
|
426
|
+
# Optional - Locales not to sync with WebTranslateIt.
|
427
|
+
# Takes a string, a symbol, or an array of string or symbol.
|
428
|
+
|
429
|
+
# ignore_locales: [#{project_info['source_locale']['code']}]
|
428
430
|
|
429
|
-
# Optional
|
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["source_locale"]["code"]}'
|
431
|
+
# Optional - Locales to sync with WebTranslateIt.
|
432
|
+
# Takes a string, a symbol, or an array of string or symbol.
|
433
433
|
|
434
|
-
#
|
435
|
-
# needed_locales: #{project_info["target_locales"].map {|locale| locale["code"]}.to_s}
|
434
|
+
# needed_locales: #{project_info['target_locales'].map { |locale| locale['code'] }}
|
436
435
|
|
437
|
-
# Optional
|
438
|
-
#
|
439
|
-
# after_pull: "touch tmp/restart.txt" # Command executed after pulling files
|
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
|
436
|
+
# Optional: files not to sync with WebTranslateIt.
|
437
|
+
# Takes an array of globs.
|
443
438
|
|
444
|
-
#
|
445
|
-
# silence_errors: true
|
439
|
+
# ignore_files: ['somefile*.csv']
|
446
440
|
|
447
|
-
|
448
|
-
|
441
|
+
# Optional - Hooks
|
442
|
+
# Takes a string containing a command to run.
|
443
|
+
|
444
|
+
# before_pull: "echo 'some unix command'" # Command executed before pulling files
|
445
|
+
# after_pull: "touch tmp/restart.txt" # Command executed after pulling files
|
446
|
+
|
447
|
+
# before_push: "echo 'some unix command'" # Command executed before pushing files
|
448
|
+
# after_push: "touch tmp/restart.txt" # Command executed after pushing files
|
449
|
+
|
450
|
+
FILE
|
449
451
|
end
|
450
452
|
|
451
|
-
def throb
|
452
|
-
throb = %w
|
453
|
+
def throb # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
454
|
+
throb = %w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏]
|
453
455
|
throb.reverse! if rand > 0.5
|
454
456
|
i = rand throb.length
|
455
457
|
|
@@ -462,11 +464,11 @@ FILE
|
|
462
464
|
dot.call
|
463
465
|
end
|
464
466
|
yield
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
end
|
467
|
+
ensure
|
468
|
+
if thread
|
469
|
+
thread.kill
|
470
|
+
puts "\r\e[0G#\e[?25h"
|
470
471
|
end
|
471
472
|
end
|
473
|
+
end
|
472
474
|
end
|