crowdin-cli 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +7 -6
- data/bin/crowdin-cli +92 -51
- data/lib/crowdin-cli/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -32,7 +32,7 @@ Create a `crowdin.yaml` YAML file in your root project directory with the follow
|
|
32
32
|
|
33
33
|
```
|
34
34
|
---
|
35
|
-
|
35
|
+
project_idenfier: test
|
36
36
|
api_key: KeepTheAPIkeySecret
|
37
37
|
base_url: http://api.crowdin.net
|
38
38
|
base_path: /path/to/your/project
|
@@ -44,13 +44,13 @@ files:
|
|
44
44
|
```
|
45
45
|
|
46
46
|
* `api_key` - Crowdin Project API key
|
47
|
-
* `
|
47
|
+
* `project_identifier` - Crowdin project name
|
48
48
|
* `base_url` - (default: http://api.crowdin.net)
|
49
49
|
* `base_path` - defines what directory we have to scan(default: current directory)
|
50
50
|
* `files`
|
51
51
|
* `source` - defines only files we will upload as sources
|
52
52
|
* `translation` - attribute defines where translations should be placed after downloading (also we have to check those path to detect and upload existing translations)
|
53
|
-
|
53
|
+
|
54
54
|
Use the following placeholders to put appropriate variables into the resulting file name:
|
55
55
|
* `%language%` - Language name (i.e. Ukrainian)
|
56
56
|
* `%two_letters_code%` - Language code ISO 639-1 (i.e. uk)
|
@@ -77,7 +77,7 @@ Also you can add and upload all directories mathing the pattern including all ne
|
|
77
77
|
Create a `crowdin.yaml` YAML file in your root project directory with the following structure:
|
78
78
|
```
|
79
79
|
---
|
80
|
-
|
80
|
+
project_identifier: test
|
81
81
|
api_key: KeepTheAPIkeySecret
|
82
82
|
base_url: http://api.crowdin.net
|
83
83
|
base_path: /path/to/your/project
|
@@ -92,7 +92,7 @@ Languages mapping.
|
|
92
92
|
|
93
93
|
```
|
94
94
|
---
|
95
|
-
|
95
|
+
project_identifier: test
|
96
96
|
api_key: KeepTheAPIkeySecret
|
97
97
|
base_url: http://api.crowdin.net
|
98
98
|
base_path: /path/to/your/project
|
@@ -102,7 +102,8 @@ files:
|
|
102
102
|
source: /locale/en/**/*.po
|
103
103
|
translation: /locale/%two_letters_code%/**/%original_file_name%
|
104
104
|
languages_mapping:
|
105
|
-
|
105
|
+
two_letters_code:
|
106
|
+
# crowdin_language_code: local_name
|
106
107
|
ru: ros
|
107
108
|
uk: ukr
|
108
109
|
```
|
data/bin/crowdin-cli
CHANGED
@@ -70,7 +70,7 @@ def export_pattern_to_path(path, export_pattern, lang, languages_mapping = nil)
|
|
70
70
|
unless languages_mapping.nil?
|
71
71
|
pattern = Hash[pattern.map{|k, str| [
|
72
72
|
k,
|
73
|
-
(languages_mapping[k[/%(.*)%/, 1]][
|
73
|
+
(languages_mapping[k[/%(.*)%/, 1]][lang['crowdin_code']] rescue nil) || str]
|
74
74
|
}]
|
75
75
|
end
|
76
76
|
|
@@ -119,42 +119,36 @@ end
|
|
119
119
|
###
|
120
120
|
include GLI::App
|
121
121
|
|
122
|
-
program_desc 'A CLI to sync locale files with crowdin.net'
|
123
|
-
|
124
122
|
version Crowdin::CLI::VERSION
|
125
123
|
|
124
|
+
program_desc 'is a command line tool that allows you to manage and synchronize your localization resources with Crowdin project'
|
125
|
+
program_long_desc 'This tool requires configuration file to be created. See http://crowdin.net/page/cli-client for more details.'
|
126
|
+
sort_help :manually # help commands are ordered in the order declared
|
127
|
+
wrap_help_text :to_terminal
|
128
|
+
|
126
129
|
desc 'Be verbose'
|
127
130
|
switch [:v, :verbose]
|
128
131
|
|
129
|
-
desc '
|
132
|
+
desc 'Configuration file'
|
130
133
|
default_value File.join(Dir.pwd, 'crowdin.yaml')
|
131
134
|
arg_name '<s>'
|
132
135
|
flag [:c, :config]
|
133
136
|
|
134
|
-
desc '
|
135
|
-
|
137
|
+
desc 'Allows you to upload source files and existing translations to Crowdin project'
|
138
|
+
long_desc 'This command is used to upload source files and translations to Crowdin. This command is used in combination with sub-commands `sources` and `translations`.'
|
139
|
+
|
136
140
|
command :upload do |c|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
#c.desc 'Upload source and translation files'
|
146
|
-
#c.command :all do |c|
|
147
|
-
# c.action do |global_options, options, args|
|
148
|
-
# puts options
|
149
|
-
# puts "`upload all` command ran"
|
150
|
-
# end
|
151
|
-
#end
|
152
|
-
|
153
|
-
c.desc 'Upload source files'
|
141
|
+
|
142
|
+
c.desc 'safely upload source files to Crowdin'
|
143
|
+
c.long_desc <<EOS
|
144
|
+
Upload source files to Crowdin project. If there are new localization files locally they will be added to Crowdin project.
|
145
|
+
Othervice files will be updated (if no --no-auto-update option specified).
|
146
|
+
EOS
|
147
|
+
|
154
148
|
c.command :sources do |c|
|
155
149
|
|
156
|
-
c.desc '
|
157
|
-
c.switch [
|
150
|
+
c.desc 'Defines whether to update source files in Crowdin project. --no-auto-update is useful when you just want to upload new files without updating existing ones.'
|
151
|
+
c.switch ['auto-update']
|
158
152
|
|
159
153
|
c.action do |global_options, options, args|
|
160
154
|
project_info = @crowdin.project_info
|
@@ -206,15 +200,16 @@ command :upload do |c|
|
|
206
200
|
@crowdin.add_directory(dir)
|
207
201
|
end
|
208
202
|
|
209
|
-
|
203
|
+
if options['auto-update'].nil? or options['auto-update']
|
210
204
|
# Update existing files in Crowdin project
|
211
205
|
#
|
212
206
|
# array containing elements common to the two arrays
|
213
207
|
update_files = local_project_tree[:files] & remote_project_tree[:files]
|
214
208
|
files_for_upload = local_files.select{ |file| update_files.include?(file[:dest]) }
|
215
209
|
files_for_upload.each do |file|
|
216
|
-
|
210
|
+
print "Updating file `#{file[:dest]}'"
|
217
211
|
@crowdin.update_file([] << file)
|
212
|
+
puts "\rUpdating file `#{file[:dest]}' - OK"
|
218
213
|
end
|
219
214
|
end
|
220
215
|
|
@@ -223,29 +218,37 @@ command :upload do |c|
|
|
223
218
|
add_files = local_project_tree[:files] - remote_project_tree[:files]
|
224
219
|
files_for_add = local_files.select{ |file| add_files.include?(file[:dest]) }
|
225
220
|
files_for_add.each do |file|
|
226
|
-
|
221
|
+
print "Uploading file `#{file[:dest]}'"
|
227
222
|
@crowdin.add_file([] << file)
|
223
|
+
puts "\rUploading file `#{file[:dest]}' - OK"
|
228
224
|
end
|
229
225
|
|
230
226
|
end # action
|
231
227
|
end # command
|
232
228
|
|
233
|
-
c.desc '
|
229
|
+
c.desc 'upload existing translations to Crowdin project'
|
230
|
+
c.long_desc <<EOS
|
231
|
+
Upload existing translations to Crowdin.
|
232
|
+
See below available options that can be used in combination with this command.
|
233
|
+
If no options specified uploaded translations will be not approved,
|
234
|
+
imported to Crowdin project even if they are duplicated and imported even they are equal to souce string.
|
235
|
+
(In many localization formats they can be considered as not actually translations).
|
236
|
+
EOS
|
234
237
|
c.command :translations do |c|
|
235
238
|
|
236
|
-
c.desc '
|
239
|
+
c.desc 'Defines what language upload translations to. By default translations will be uploaded for all Crowdin project target languages'
|
237
240
|
c.default_value 'all'
|
238
|
-
c.arg_name '
|
241
|
+
c.arg_name 'crowdin_language_code'
|
239
242
|
c.flag [:l, :language]
|
240
243
|
|
241
|
-
c.desc '
|
242
|
-
c.switch [
|
244
|
+
c.desc 'Defines whether to add translation if there is the same translation already existing in Crowdin project'
|
245
|
+
c.switch ['import-duplicates']
|
243
246
|
|
244
|
-
c.desc '
|
245
|
-
c.switch [
|
247
|
+
c.desc 'Defines whether to add translation if it is equal to source string in Crowdin project'
|
248
|
+
c.switch ['import-eq-suggestions']
|
246
249
|
|
247
|
-
c.desc '
|
248
|
-
c.switch [
|
250
|
+
c.desc 'Automatically approve uploaded translations'
|
251
|
+
c.switch ['auto-approve-imported']
|
249
252
|
|
250
253
|
|
251
254
|
c.action do |global_options, options, args|
|
@@ -303,9 +306,9 @@ command :upload do |c|
|
|
303
306
|
exit_now!("Nothing to upload") if dest_files.empty?
|
304
307
|
|
305
308
|
params = {}
|
306
|
-
params[:import_duplicates] = options[
|
307
|
-
params[:import_eq_suggestions] = options[
|
308
|
-
params[:auto_approve_imported] = options[
|
309
|
+
params[:import_duplicates] = options['import-dublicates'] ? 1 : 0
|
310
|
+
params[:import_eq_suggestions] = options['import-eq-suggestions'] ? 1 : 0
|
311
|
+
params[:auto_approve_imported] = options['auto-approve-imported'] ? 1 : 0
|
309
312
|
|
310
313
|
common_dir = find_common_directory_path(dest_files)
|
311
314
|
|
@@ -314,14 +317,15 @@ command :upload do |c|
|
|
314
317
|
file[:dest].sub!(common_dir, '')
|
315
318
|
if remote_project_tree[:files].include?(file[:dest])
|
316
319
|
if File.exist?(file[:source])
|
317
|
-
|
320
|
+
print "Uploading `#{file[:source].sub(@base_path, '')}'"
|
318
321
|
@crowdin.upload_translation([] << file, language, params)
|
322
|
+
puts "\rUploading `#{file[:source].sub(@base_path, '')}' - OK"
|
319
323
|
else
|
320
|
-
puts "Local file
|
324
|
+
puts "Warning: Local file `#{file[:source]}' does not exists"
|
321
325
|
end
|
322
326
|
else
|
323
327
|
# if source file not exist, don't upload translation
|
324
|
-
puts "Skip
|
328
|
+
puts "Warning: Skip `#{file[:source].sub(@base_path, '')}'"
|
325
329
|
end
|
326
330
|
end
|
327
331
|
end
|
@@ -331,17 +335,17 @@ command :upload do |c|
|
|
331
335
|
|
332
336
|
end
|
333
337
|
|
334
|
-
desc 'Download
|
338
|
+
desc 'Download latest translations from Crowdin and put them to the right places in your project'
|
335
339
|
#arg_name 'Describe arguments to download here'
|
336
340
|
command :download do |c|
|
337
341
|
|
338
|
-
c.desc 'the language
|
342
|
+
c.desc 'If the option is defined the translations will be downloaded for single specified language. Othervice (by default) translations are downloaded for all languages'
|
339
343
|
c.arg_name 'language_code'
|
340
344
|
c.flag :l, :language, :default_value => 'all'
|
341
345
|
|
342
346
|
c.action do |global_options ,options, args|
|
343
347
|
# use export API method before to download the most recent translations
|
344
|
-
|
348
|
+
@crowdin.export_translations
|
345
349
|
|
346
350
|
language = options[:language]
|
347
351
|
project_info = @crowdin.project_info
|
@@ -417,9 +421,41 @@ pre do |global ,command, options, args|
|
|
417
421
|
# Use skips_pre before a command to skip this block
|
418
422
|
# on that command only
|
419
423
|
|
420
|
-
|
424
|
+
if File.exists?(global[:config])
|
425
|
+
@config = YAML.load_file(global[:config])
|
426
|
+
|
427
|
+
['api_key', 'project_identifier'].each do |key|
|
428
|
+
unless @config[key]
|
429
|
+
exit_now! <<EOS
|
430
|
+
Configuration file misses required option `#{key}`
|
431
|
+
|
432
|
+
See http://crowdin.net/page/cli-client#configuration-file for more details
|
433
|
+
EOS
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
unless @config['files']
|
438
|
+
exit_now! <<EOS
|
439
|
+
Configuration file misses required section `files`
|
440
|
+
|
441
|
+
See http://crowdin.net/page/cli-client#configuration-file for more details
|
442
|
+
EOS
|
443
|
+
end
|
444
|
+
|
445
|
+
else
|
446
|
+
exit_now! <<EOS
|
447
|
+
Can't find configuration file (default `crowdin.yml').
|
448
|
+
Type `crowdin-cli help` to know how to specify custom configuration file
|
449
|
+
|
450
|
+
See http://crowdin.net/page/cli-client#configuration-file for more details
|
451
|
+
EOS
|
452
|
+
end
|
453
|
+
|
454
|
+
@config['files'].each do |file|
|
455
|
+
file['source'] = '/' + file['source'] unless file['source'].start_with?('/')
|
456
|
+
file['translation'] = '/' + file['translation'] unless file['translation'].start_with?('/')
|
457
|
+
end
|
421
458
|
|
422
|
-
#@base_path = @config['base_path'] || Dir.pwd
|
423
459
|
if @config['base_path']
|
424
460
|
if @config['base_path'].start_with?('/')
|
425
461
|
@base_path = @config['base_path']
|
@@ -431,9 +467,14 @@ pre do |global ,command, options, args|
|
|
431
467
|
end
|
432
468
|
|
433
469
|
Crowdin::API.log = Logger.new($stderr) if global[:v]
|
434
|
-
@crowdin = Crowdin::API.new(api_key: @config['api_key'], project_id: @config['
|
470
|
+
@crowdin = Crowdin::API.new(api_key: @config['api_key'], project_id: @config['project_identifier'], base_url: @config['base_url'] || 'http://api.crowdin.net')
|
471
|
+
begin
|
472
|
+
@crowdin.project_info
|
473
|
+
rescue
|
474
|
+
exit_now!("Seems Crowdin server API URL is not valid. Please check the `base_url` parameter in the configuration file.")
|
475
|
+
end
|
435
476
|
|
436
|
-
puts "Executing #{command.name}" if global[:v]
|
477
|
+
#puts "Executing #{command.name}" if global[:v]
|
437
478
|
true
|
438
479
|
end
|
439
480
|
|
@@ -441,7 +482,7 @@ post do |global, command, options, args|
|
|
441
482
|
# Post logic here
|
442
483
|
# Use skips_post before a command to skip this
|
443
484
|
# block on that command only
|
444
|
-
puts "Executed #{command.name}" if global[:v]
|
485
|
+
#puts "Executed #{command.name}" if global[:v]
|
445
486
|
end
|
446
487
|
|
447
488
|
on_error do |exception|
|
data/lib/crowdin-cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crowdin-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 2.
|
69
|
+
version: 2.4.0
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: 2.
|
77
|
+
version: 2.4.0
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: rubyzip
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|