crowdin-cli 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/bin/crowdin-cli +84 -45
- data/lib/crowdin-cli/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66ad927a1e1132fbcd7e3423ea92d67ab4fcf9ee
|
4
|
+
data.tar.gz: b82bd71053c5d79e1c710a0f24a272aae0d99289
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bb8e237425d2bf49a2647e4006191cfbdb646b05f144dd96f2dc730bffb285b6d771493dfa2034e7ae86a8cb9c08effa92dad7d908991c8b7159acb729af857
|
7
|
+
data.tar.gz: c5126f6fc09657b5a67808cdbf2492f515b8a28d421f8fd91b074c931e6e39e202c87cbc1129cb78f0e4bedbcc766e90e654f856e83e8e7a47871ccf0a9ac8d9
|
data/README.md
CHANGED
@@ -138,6 +138,21 @@ Check [complete list of Crowdin language codes](http://crowdin.net/page/api/lang
|
|
138
138
|
|
139
139
|
You can also override language codes for other placeholders like `%android_code%`, `%locale%` etc...
|
140
140
|
|
141
|
+
### Ignoring directories
|
142
|
+
|
143
|
+
From time to time there are directories you don't want translate on Crowdin.
|
144
|
+
Local per-file rules can be added to the config file in your project.
|
145
|
+
```
|
146
|
+
files:
|
147
|
+
-
|
148
|
+
source: /locale/en/**/*.po
|
149
|
+
translation: /locale/%two_letters_code%/**/%original_file_name%
|
150
|
+
ignore:
|
151
|
+
- /locale/en/templates
|
152
|
+
- /locale/en/workflow
|
153
|
+
|
154
|
+
```
|
155
|
+
|
141
156
|
## Example Configurations
|
142
157
|
|
143
158
|
### GetText Project
|
data/bin/crowdin-cli
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'pp'
|
4
|
+
require 'find'
|
4
5
|
require 'crowdin-cli'
|
5
6
|
|
6
7
|
# GLI_DEBUG=true bundle exec bin/crowdin-cli
|
@@ -174,20 +175,26 @@ def find_common_directory_path(paths)
|
|
174
175
|
first.slice(0, i).join('/')
|
175
176
|
end
|
176
177
|
|
177
|
-
|
178
|
+
# Extract compressed files +files_list+ in a ZIP archive +zipfile_name+ to +dest_path+
|
179
|
+
#
|
180
|
+
# +files_list+ is a Hash of key-value pairs. Where key is a posible archive filename based on current project configuration
|
181
|
+
# and value is the expanded filename
|
182
|
+
#
|
183
|
+
def unzip_file_with_translations(zipfile_name, dest_path, files_list)
|
178
184
|
# overwrite files if they already exist inside of the extracted path
|
179
185
|
Zip.options[:on_exists_proc] = true
|
180
186
|
|
187
|
+
# files that exists in archive and doesn't match current project configuration
|
181
188
|
unmatched_files = []
|
182
189
|
|
183
|
-
Zip::ZipFile.open(
|
184
|
-
|
190
|
+
Zip::ZipFile.open(zipfile_name) do |zipfile|
|
191
|
+
zipfile.select{ |zip_entry| zip_entry.file? }.each do |f|
|
185
192
|
file = files_list['/' + f.name]
|
186
193
|
if file
|
187
|
-
|
188
|
-
FileUtils.mkdir_p(File.dirname(
|
194
|
+
fpath = File.join(dest_path, file)
|
195
|
+
FileUtils.mkdir_p(File.dirname(fpath))
|
189
196
|
puts "Download: `#{file}'"
|
190
|
-
|
197
|
+
zipfile.extract(f, fpath)
|
191
198
|
else
|
192
199
|
unmatched_files << f
|
193
200
|
end
|
@@ -262,19 +269,30 @@ command :upload do |c|
|
|
262
269
|
|
263
270
|
local_files << local_file
|
264
271
|
else
|
265
|
-
|
266
|
-
dest =
|
267
|
-
|
272
|
+
Find.find(@base_path) do |source_path|
|
273
|
+
dest = source_path.sub(@base_path, '') # relative path in Crowdin
|
274
|
+
|
275
|
+
if File.directory?(source_path)
|
276
|
+
ignores = file['ignore'] || []
|
277
|
+
if ignores.include?(dest)
|
278
|
+
Find.prune # Don't look any further into this directory
|
279
|
+
else
|
280
|
+
next
|
281
|
+
end
|
282
|
+
elsif File.fnmatch?(file['source'], dest)
|
283
|
+
dest_files << dest
|
268
284
|
|
269
|
-
|
285
|
+
export_pattern = construct_export_pattern(dest, file['source'], file['translation'])
|
270
286
|
|
271
|
-
|
272
|
-
|
273
|
-
|
287
|
+
local_file = { dest: dest, source: source_path, export_pattern: export_pattern }
|
288
|
+
local_file.merge!({ sheme: file['scheme'] }) if file.has_key?('scheme')
|
289
|
+
local_file.merge!({ first_line_contains_header: file['first_line_contains_header'] }) if file.has_key?('first_line_contains_header')
|
274
290
|
|
275
|
-
|
276
|
-
|
277
|
-
|
291
|
+
local_files << local_file
|
292
|
+
end
|
293
|
+
end # Find
|
294
|
+
|
295
|
+
end # if File.exists?
|
278
296
|
end # @config['files']
|
279
297
|
|
280
298
|
if dest_files.empty?
|
@@ -360,7 +378,7 @@ EOS
|
|
360
378
|
|
361
379
|
c.action do |global_options, options, args|
|
362
380
|
params = {}
|
363
|
-
params[:import_duplicates] = options['import-
|
381
|
+
params[:import_duplicates] = options['import-duplicates'] ? 1 : 0
|
364
382
|
params[:import_eq_suggestions] = options['import-eq-suggestions'] ? 1 : 0
|
365
383
|
params[:auto_approve_imported] = options['auto-approve-imported'] ? 1 : 0
|
366
384
|
|
@@ -404,18 +422,29 @@ EOS
|
|
404
422
|
translated_files[lang['crowdin_code']] << { source: "#{@base_path}#{source}", dest: dest }
|
405
423
|
end
|
406
424
|
else
|
407
|
-
|
408
|
-
dest =
|
409
|
-
|
425
|
+
Find.find(@base_path) do |source_path|
|
426
|
+
dest = source_path.sub(@base_path, '') # relative path in Crowdin
|
427
|
+
|
428
|
+
if File.directory?(source_path)
|
429
|
+
ignores = file['ignore'] || []
|
430
|
+
if ignores.include?(dest)
|
431
|
+
Find.prune # Don't look any further into this directory
|
432
|
+
else
|
433
|
+
next
|
434
|
+
end
|
435
|
+
elsif File.fnmatch?(file['source'], dest)
|
436
|
+
dest_files << dest
|
410
437
|
|
411
|
-
|
438
|
+
export_pattern = construct_export_pattern(dest, file['source'], file['translation'])
|
412
439
|
|
413
|
-
|
414
|
-
|
415
|
-
|
440
|
+
translation_languages.each do |lang|
|
441
|
+
source = export_pattern_to_path(dest, export_pattern, lang, languages_mapping)
|
442
|
+
translated_files[lang['crowdin_code']] << { source: "#{@base_path}#{source}", dest: dest }
|
443
|
+
end
|
416
444
|
end
|
417
445
|
|
418
|
-
end
|
446
|
+
end # Find
|
447
|
+
|
419
448
|
end # if
|
420
449
|
end # @config['files']
|
421
450
|
|
@@ -448,7 +477,7 @@ EOS
|
|
448
477
|
puts "Warning: Local file `#{file[:source]}' does not exists"
|
449
478
|
end
|
450
479
|
else
|
451
|
-
# if source file not exist, don't upload
|
480
|
+
# if source file does not exist, don't upload translations
|
452
481
|
puts "Warning: Skip `#{file[:source].sub(@base_path, '')}'"
|
453
482
|
end
|
454
483
|
end
|
@@ -492,13 +521,12 @@ command :download do |c|
|
|
492
521
|
source_language = project_info['details']['source_language']['code']
|
493
522
|
source_language = supported_languages.find{ |lang| lang['crowdin_code'] == source_language }
|
494
523
|
|
495
|
-
# keys is all possible files in
|
524
|
+
# keys is all possible files in .ZIP archive
|
496
525
|
# values is resulted local files
|
497
|
-
|
498
|
-
downloadable_files = {}
|
526
|
+
downloadable_files_hash = {}
|
499
527
|
|
500
528
|
@config['files'].each do |file|
|
501
|
-
languages_mapping = file['languages_mapping'] #Hash or NilClass
|
529
|
+
languages_mapping = file['languages_mapping'] # Hash or NilClass
|
502
530
|
|
503
531
|
if File.exists?("#{@base_path}#{file['source']}")
|
504
532
|
dest = file['source'].sub("#{@base_path}", '')
|
@@ -507,34 +535,45 @@ command :download do |c|
|
|
507
535
|
zipped_file = export_pattern_to_path(dest, file['translation'], lang)
|
508
536
|
local_file = export_pattern_to_path(dest, file['translation'], lang, languages_mapping)
|
509
537
|
|
510
|
-
|
538
|
+
downloadable_files_hash[zipped_file] = local_file
|
511
539
|
end
|
512
540
|
else
|
513
|
-
|
514
|
-
dest =
|
541
|
+
Find.find(@base_path) do |source_path|
|
542
|
+
dest = source_path.sub(@base_path, '') # relative path in Crowdin
|
515
543
|
|
516
|
-
|
544
|
+
if File.directory?(source_path)
|
545
|
+
ignores = file['ignore'] || []
|
546
|
+
if ignores.include?(dest)
|
547
|
+
Find.prune # Don't look any further into this directory
|
548
|
+
else
|
549
|
+
next
|
550
|
+
end
|
551
|
+
elsif File.fnmatch?(file['source'], dest)
|
552
|
+
export_pattern = construct_export_pattern(dest, file['source'], file['translation'])
|
517
553
|
|
518
|
-
|
519
|
-
|
520
|
-
|
554
|
+
translation_languages.each do |lang|
|
555
|
+
zipped_file = export_pattern_to_path(dest, export_pattern, lang)
|
556
|
+
local_file = export_pattern_to_path(dest, export_pattern, lang, languages_mapping)
|
521
557
|
|
522
|
-
|
558
|
+
downloadable_files_hash[zipped_file] = local_file
|
559
|
+
end
|
523
560
|
end
|
524
561
|
|
525
|
-
end
|
562
|
+
end # Find
|
563
|
+
|
526
564
|
end # if
|
527
565
|
end # @config['files']
|
528
566
|
|
529
567
|
##
|
530
|
-
|
531
|
-
|
568
|
+
tempfile = Tempfile.new(language)
|
569
|
+
zipfile_name = tempfile.path
|
532
570
|
begin
|
533
|
-
@crowdin.download_translation(language, output:
|
534
|
-
|
571
|
+
@crowdin.download_translation(language, output: zipfile_name)
|
572
|
+
|
573
|
+
unzip_file_with_translations(zipfile_name, @base_path, downloadable_files_hash)
|
535
574
|
ensure
|
536
|
-
|
537
|
-
|
575
|
+
tempfile.close
|
576
|
+
tempfile.unlink # delete the tempfile
|
538
577
|
end
|
539
578
|
end
|
540
579
|
|
data/lib/crowdin-cli/version.rb
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Crowdin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.0.
|
147
|
+
rubygems_version: 2.0.3
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: Crowdin CLI.
|