crowdin-cli 0.4.6 → 0.5.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/bin/crowdin-cli +131 -18
- data/lib/crowdin-cli/version.rb +1 -1
- data/locales/en.yml +2 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea82b26b6c10089325ddbffcd1429c915dc67dd6
|
4
|
+
data.tar.gz: 0d6f374b2216d33ebc138d5afea0090d7c431913
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdab714082fe77e71906c7a1b339828ae0a662ffab1ce729862aec2ba8aae9e5fe5ba646ed8b47c139dfb1eed2860532ab433dad41b5ba6690295de4bbce4f39
|
7
|
+
data.tar.gz: eb84df5ff216c5c43b4fc69aab971656936f2fb4e277c2975d14b6093d77b41e7c7dd9d7caef0cb0768decd152ca82f9cad4215788b1b0724ada425777e2de0e
|
data/README.md
CHANGED
@@ -406,7 +406,7 @@ Use help provided with an application to get more information about available co
|
|
406
406
|
Tested with the following Ruby versions:
|
407
407
|
|
408
408
|
- MRI 2.2.1
|
409
|
-
- JRuby 9.0.0.0
|
409
|
+
- JRuby 9.0.0.0
|
410
410
|
|
411
411
|
## Creating a JAR file
|
412
412
|
|
@@ -416,10 +416,10 @@ Installation/SystemRequirements:
|
|
416
416
|
- Java
|
417
417
|
- rvm
|
418
418
|
|
419
|
-
Install JRuby 9.0.0.0
|
419
|
+
Install JRuby 9.0.0.0 and Warbler gem:
|
420
420
|
|
421
421
|
```
|
422
|
-
$ rvm install jruby-9.0.0.0
|
422
|
+
$ rvm install jruby-9.0.0.0
|
423
423
|
$ gem install warbler --pre
|
424
424
|
```
|
425
425
|
|
@@ -428,7 +428,7 @@ Create a new file called `Gemfile` in new project directory, an specify `crowdin
|
|
428
428
|
```ruby
|
429
429
|
source 'https://rubygems.org'
|
430
430
|
gem 'crowdin-api', '=0.3.0'
|
431
|
-
gem 'crowdin-cli', '=0.4.
|
431
|
+
gem 'crowdin-cli', '=0.4.6'
|
432
432
|
```
|
433
433
|
|
434
434
|
Create a new file called `bin/crowdin-cli`:
|
data/bin/crowdin-cli
CHANGED
@@ -5,6 +5,9 @@ require 'pp'
|
|
5
5
|
require 'find'
|
6
6
|
require 'crowdin-cli'
|
7
7
|
|
8
|
+
# For development purposes only. Comment in production
|
9
|
+
# require 'byebug'
|
10
|
+
|
8
11
|
# GLI_DEBUG=true bundle exec bin/crowdin-cli
|
9
12
|
|
10
13
|
# Setup i18n
|
@@ -20,6 +23,8 @@ I18n.locale = :en
|
|
20
23
|
def get_remote_files_hierarchy(files, root = '/', hierarchy = { dirs: [], files: [] })
|
21
24
|
files.each do |node|
|
22
25
|
case node['node_type']
|
26
|
+
when 'branch'
|
27
|
+
get_remote_files_hierarchy(node['files'], root + node['name'] + '/', hierarchy)
|
23
28
|
when 'directory'
|
24
29
|
hierarchy[:dirs] << "#{root}#{node['name']}"
|
25
30
|
get_remote_files_hierarchy(node['files'], root + node['name'] + '/', hierarchy)
|
@@ -349,7 +354,6 @@ default_value File.join(Dir.home, '.crowdin.yaml')
|
|
349
354
|
arg_name '<s>'
|
350
355
|
flag [:identity]
|
351
356
|
|
352
|
-
|
353
357
|
desc I18n.t('app.commands.upload.desc')
|
354
358
|
long_desc I18n.t('app.commands.upload.long_desc')
|
355
359
|
command :upload do |c|
|
@@ -362,6 +366,10 @@ command :upload do |c|
|
|
362
366
|
c.default_value true
|
363
367
|
c.switch ['auto-update']
|
364
368
|
|
369
|
+
c.desc I18n.t('app.flags.branch.desc')
|
370
|
+
c.arg_name 'branch_name'
|
371
|
+
c.flag [:b, :branch]
|
372
|
+
|
365
373
|
c.action do |global_options, options, args|
|
366
374
|
project_info = @crowdin.project_info
|
367
375
|
|
@@ -371,7 +379,29 @@ command :upload do |c|
|
|
371
379
|
supported_languages = @crowdin.supported_languages
|
372
380
|
source_language = supported_languages.find { |lang| lang['crowdin_code'] == source_language }
|
373
381
|
|
374
|
-
|
382
|
+
if @branch_name
|
383
|
+
branch = project_info['files'].find { |h| h['node_type'] == 'branch' && h['name'] == @branch_name }
|
384
|
+
|
385
|
+
if branch
|
386
|
+
branch_files = [] << branch
|
387
|
+
else
|
388
|
+
print "Creating a new branch `#{@branch_name}'"
|
389
|
+
|
390
|
+
@crowdin.add_directory(@branch_name, is_branch: '1')
|
391
|
+
|
392
|
+
puts "\rCreating a new branch `#{@branch_name}' - OK"
|
393
|
+
branch_files = []
|
394
|
+
end
|
395
|
+
|
396
|
+
remote_project_tree = get_remote_files_hierarchy(branch_files)
|
397
|
+
|
398
|
+
# Remove branch directory from a directory path string
|
399
|
+
remote_project_tree[:dirs].map! { |p| p.split('/')[2..-1].unshift('').join('/') }
|
400
|
+
remote_project_tree[:files].map! { |p| p.split('/')[2..-1].unshift('').join('/') }
|
401
|
+
else
|
402
|
+
# INFO it also includes all branches
|
403
|
+
remote_project_tree = get_remote_files_hierarchy(project_info['files'])
|
404
|
+
end
|
375
405
|
|
376
406
|
local_files = []
|
377
407
|
dest_files = []
|
@@ -443,8 +473,15 @@ command :upload do |c|
|
|
443
473
|
#
|
444
474
|
create_dirs = local_project_tree[:dirs] - remote_project_tree[:dirs]
|
445
475
|
create_dirs.each do |dir|
|
446
|
-
|
447
|
-
|
476
|
+
# FIXME if directory path starts with / Crowdin returns an error:
|
477
|
+
# 17: Specified directory was not found
|
478
|
+
dir.slice!(0) if dir.start_with?('/')
|
479
|
+
|
480
|
+
print "Creating directory `#{dir}'"
|
481
|
+
|
482
|
+
@crowdin.add_directory(dir, branch: @branch_name)
|
483
|
+
|
484
|
+
puts "\rCreating directory `#{dir}' - OK"
|
448
485
|
end
|
449
486
|
|
450
487
|
if options['auto-update']
|
@@ -454,13 +491,17 @@ command :upload do |c|
|
|
454
491
|
update_files = local_project_tree[:files] & remote_project_tree[:files]
|
455
492
|
files_for_upload = local_files.select { |file| update_files.include?(file[:dest]) }
|
456
493
|
files_for_upload.each do |file|
|
457
|
-
|
494
|
+
file[:dest].slice!(0) if file[:dest].start_with?('/')
|
458
495
|
|
459
496
|
params = {}
|
497
|
+
params[:branch] = @branch_name if @branch_name
|
498
|
+
|
460
499
|
@allowed_options.each do |option|
|
461
500
|
params[option.to_sym] = file.delete(option.to_sym)
|
462
501
|
end
|
463
502
|
|
503
|
+
print "Updating source file `#{file[:dest]}'"
|
504
|
+
|
464
505
|
resp = @crowdin.update_file([] << file, params)
|
465
506
|
|
466
507
|
case resp['files'].first[1]
|
@@ -477,16 +518,22 @@ command :upload do |c|
|
|
477
518
|
add_files = local_project_tree[:files] - remote_project_tree[:files]
|
478
519
|
files_for_add = local_files.select { |file| add_files.include?(file[:dest]) }
|
479
520
|
files_for_add.each do |file|
|
480
|
-
|
521
|
+
# If file path starts with / Crowdin returns error
|
522
|
+
# 17: Specified directory was not found
|
523
|
+
# make sure that file[:dest] not start with '/'
|
524
|
+
file[:dest].slice!(0) if file[:dest].start_with?('/')
|
481
525
|
|
482
526
|
params = {}
|
483
527
|
params[:type] = file.delete(:type) if file[:type]
|
528
|
+
params[:branch] = @branch_name if @branch_name
|
484
529
|
|
485
530
|
@allowed_options.each do |option|
|
486
531
|
params[option.to_sym] = file.delete(option.to_sym)
|
487
532
|
end
|
488
533
|
|
489
|
-
|
534
|
+
print "Uploading source file `#{file[:dest]}'"
|
535
|
+
|
536
|
+
@crowdin.add_file([] << file, params)
|
490
537
|
|
491
538
|
puts "\rUploading source file `#{file[:dest]}' - OK"
|
492
539
|
end
|
@@ -503,6 +550,10 @@ command :upload do |c|
|
|
503
550
|
c.arg_name 'crowdin_language_code'
|
504
551
|
c.flag [:l, :language]
|
505
552
|
|
553
|
+
c.desc I18n.t('app.flags.branch.desc')
|
554
|
+
c.arg_name 'branch_name'
|
555
|
+
c.flag [:b, :branch]
|
556
|
+
|
506
557
|
c.desc I18n.t('app.commands.upload.commands.translations.switches.import_duplicates.desc')
|
507
558
|
c.switch ['import-duplicates']
|
508
559
|
|
@@ -522,7 +573,24 @@ command :upload do |c|
|
|
522
573
|
|
523
574
|
project_info = @crowdin.project_info
|
524
575
|
|
525
|
-
|
576
|
+
if @branch_name
|
577
|
+
branch = project_info['files'].find { |h| h['node_type'] == 'branch' && h['name'] == @branch_name }
|
578
|
+
|
579
|
+
if branch
|
580
|
+
params[:branch] = @branch_name
|
581
|
+
branch_files = [] << branch
|
582
|
+
else
|
583
|
+
exit_now!("branch '#{@branch_name}' doesn't exist in the project")
|
584
|
+
end
|
585
|
+
|
586
|
+
remote_project_tree = get_remote_files_hierarchy(branch_files)
|
587
|
+
|
588
|
+
# Remove branch directory from a directory path string
|
589
|
+
remote_project_tree[:dirs].map! { |p| p.split('/')[2..-1].unshift('').join('/') }
|
590
|
+
remote_project_tree[:files].map! { |p| p.split('/')[2..-1].unshift('').join('/') }
|
591
|
+
else
|
592
|
+
remote_project_tree = get_remote_files_hierarchy(project_info['files'])
|
593
|
+
end
|
526
594
|
|
527
595
|
project_languages = project_info['languages'].collect { |h| h['code'] }
|
528
596
|
|
@@ -614,26 +682,33 @@ command :upload do |c|
|
|
614
682
|
translated_files.each_pair do |language, files|
|
615
683
|
files.each do |file|
|
616
684
|
file[:dest] = file[:dest].sub(common_dir, '')
|
685
|
+
source_file = file[:source].sub(/\A#{Regexp.escape(@base_path)}/, '')
|
617
686
|
|
618
687
|
if remote_project_tree[:files].include?(file[:dest])
|
619
688
|
if File.exist?(file[:source])
|
620
|
-
|
689
|
+
# If file path starts with / Crowdin returns error
|
690
|
+
# 17: Specified directory was not found
|
691
|
+
# make sure that file[:dest] not start with '/'
|
692
|
+
file[:dest].slice!(0) if file[:dest].start_with?('/')
|
693
|
+
|
694
|
+
print "Uploading translation file `#{source_file}'"
|
621
695
|
|
622
696
|
resp = @crowdin.upload_translation([] << file, language, params)
|
697
|
+
|
623
698
|
case resp['files'].first[1]
|
624
699
|
when 'skipped'
|
625
|
-
puts "\rUploading translation file `#{
|
700
|
+
puts "\rUploading translation file `#{source_file}' - Skipped"
|
626
701
|
when 'uploaded'
|
627
|
-
puts "\rUploading translation file `#{
|
702
|
+
puts "\rUploading translation file `#{source_file}' - OK"
|
628
703
|
when 'not_allowed'
|
629
|
-
puts "\rUploading translation file `#{
|
704
|
+
puts "\rUploading translation file `#{source_file}' - is not possible"
|
630
705
|
end
|
631
706
|
else
|
632
707
|
puts "Warning: Local file `#{file[:source]}' does not exist"
|
633
708
|
end
|
634
709
|
else
|
635
710
|
# if source file does not exist, don't upload translations
|
636
|
-
puts "Warning: Skip `#{
|
711
|
+
puts "Warning: Skip `#{source_file}'. Translation can not be uploaded for a non-existent source file `#{file[:dest]}'. Please upload sources first."
|
637
712
|
end
|
638
713
|
end
|
639
714
|
end
|
@@ -652,10 +727,13 @@ command :download do |c|
|
|
652
727
|
c.arg_name 'language_code'
|
653
728
|
c.flag [:l, :language], default_value: 'all'
|
654
729
|
|
730
|
+
c.desc I18n.t('app.flags.branch.desc')
|
731
|
+
c.arg_name 'branch_name'
|
732
|
+
c.flag [:b, :branch]
|
733
|
+
|
655
734
|
c.desc I18n.t('app.commands.download.switches.ignore_match.desc')
|
656
735
|
c.switch ['ignore-match'], negatable: false
|
657
736
|
|
658
|
-
|
659
737
|
c.action do |global_options, options, args|
|
660
738
|
language = options[:language]
|
661
739
|
|
@@ -681,9 +759,12 @@ command :download do |c|
|
|
681
759
|
end
|
682
760
|
end
|
683
761
|
|
762
|
+
params = {}
|
763
|
+
params[:branch] = @branch_name if @branch_name
|
764
|
+
|
684
765
|
# use export API method before to download the most recent translations
|
685
766
|
print 'Building ZIP archive with the latest translations '
|
686
|
-
export_translations = @crowdin.export_translations
|
767
|
+
export_translations = @crowdin.export_translations(params)
|
687
768
|
if export_translations['success']
|
688
769
|
if export_translations['success']['status'] == 'built'
|
689
770
|
puts "- OK"
|
@@ -753,11 +834,15 @@ command :download do |c|
|
|
753
834
|
end # if
|
754
835
|
end # @config['files']
|
755
836
|
|
756
|
-
##
|
757
837
|
tempfile = Tempfile.new(language)
|
758
838
|
zipfile_name = tempfile.path
|
839
|
+
|
840
|
+
params = {}
|
841
|
+
params[:output] = zipfile_name
|
842
|
+
params[:branch] = @branch_name if @branch_name
|
843
|
+
|
759
844
|
begin
|
760
|
-
@crowdin.download_translation(language,
|
845
|
+
@crowdin.download_translation(language, params)
|
761
846
|
|
762
847
|
unzip_file_with_translations(zipfile_name, @base_path, downloadable_files_hash, options['ignore-match'])
|
763
848
|
ensure
|
@@ -777,9 +862,20 @@ command :list do |ls_cmd|
|
|
777
862
|
proj_cmd.desc I18n.t('app.commands.list.switches.tree.desc')
|
778
863
|
proj_cmd.switch ['tree'], negatable: false
|
779
864
|
|
865
|
+
proj_cmd.desc I18n.t('app.flags.branch.desc')
|
866
|
+
proj_cmd.arg_name 'branch_name'
|
867
|
+
proj_cmd.flag [:b, :branch]
|
868
|
+
|
780
869
|
proj_cmd.action do |global_options, options, args|
|
781
870
|
project_info = @crowdin.project_info
|
782
|
-
|
871
|
+
|
872
|
+
if @branch_name
|
873
|
+
branch = project_info['files'].find { |h| h['node_type'] == 'branch' && h['name'] == @branch_name }
|
874
|
+
branch_files = branch ? [] << branch : []
|
875
|
+
remote_project_tree = get_remote_files_hierarchy(branch_files)
|
876
|
+
else
|
877
|
+
remote_project_tree = get_remote_files_hierarchy(project_info['files'])
|
878
|
+
end
|
783
879
|
|
784
880
|
if options[:tree]
|
785
881
|
tree = build_hash_tree(remote_project_tree[:files])
|
@@ -795,6 +891,10 @@ command :list do |ls_cmd|
|
|
795
891
|
src_cmd.desc I18n.t('app.commands.list.switches.tree.desc')
|
796
892
|
src_cmd.switch ['tree'], negatable: false
|
797
893
|
|
894
|
+
src_cmd.desc I18n.t('app.flags.branch.desc')
|
895
|
+
src_cmd.arg_name 'branch_name'
|
896
|
+
src_cmd.flag [:b, :branch]
|
897
|
+
|
798
898
|
src_cmd.action do |global_options, options, args|
|
799
899
|
local_files = []
|
800
900
|
dest_files = []
|
@@ -865,6 +965,10 @@ command :list do |ls_cmd|
|
|
865
965
|
trans_cmd.desc I18n.t('app.commands.list.switches.tree.desc')
|
866
966
|
trans_cmd.switch ['tree'], negatable: false
|
867
967
|
|
968
|
+
trans_cmd.desc I18n.t('app.flags.branch.desc')
|
969
|
+
trans_cmd.arg_name 'branch_name'
|
970
|
+
trans_cmd.flag [:b, :branch]
|
971
|
+
|
868
972
|
trans_cmd.action do |global_options, options, args|
|
869
973
|
project_info = @crowdin.project_info
|
870
974
|
|
@@ -1064,6 +1168,15 @@ pre do |globals ,command, options, args|
|
|
1064
1168
|
EOS
|
1065
1169
|
end
|
1066
1170
|
|
1171
|
+
@branch_name = options[:branch] || nil
|
1172
|
+
@base_path = @branch_name ? File.join(@base_path, @branch_name) : @base_path
|
1173
|
+
|
1174
|
+
unless Dir.exists?(@base_path)
|
1175
|
+
exit_now! <<-EOS.strip_heredoc
|
1176
|
+
No such directory `#{@base_path}`. Please make sure that the `base_path` or a branch name is properly set.
|
1177
|
+
EOS
|
1178
|
+
end
|
1179
|
+
|
1067
1180
|
@preserve_hierarchy = false
|
1068
1181
|
if @config['preserve_hierarchy']
|
1069
1182
|
@preserve_hierarchy = case @config['preserve_hierarchy']
|
data/lib/crowdin-cli/version.rb
CHANGED
data/locales/en.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crowdin-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Crowdin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.4.0.pre
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.4.0.pre
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: i18n
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,12 +145,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: 1.9.3
|
146
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
147
|
requirements:
|
148
|
-
- - "
|
148
|
+
- - ">"
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
150
|
+
version: 1.3.1
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.4.
|
153
|
+
rubygems_version: 2.4.8
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Crowdin CLI.
|