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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a101699f9966dada34fbe97383366647f61ea48c
4
- data.tar.gz: 3458fcb682ba7a0865af8334bc53afcd379facfa
3
+ metadata.gz: 66ad927a1e1132fbcd7e3423ea92d67ab4fcf9ee
4
+ data.tar.gz: b82bd71053c5d79e1c710a0f24a272aae0d99289
5
5
  SHA512:
6
- metadata.gz: d0c270bc37ac7c063a087388b5108e432cc3a8e193db4886991bc59749a831520742841672808ce1fed4e2450e50a25d49f25502d49113c1ee5004fcd9dc6642
7
- data.tar.gz: 98034c0849daa227fe58093f7846db1bf8c153718dbc77732659b452a03ce771c8dcb57e88f7a251f35afa84547ad4b438138e92db0132f750fc72c8ba585fc8
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
- def unzip_file(zip, dest, files_list)
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(zip) do |zip_file|
184
- zip_file.select{ |f| f.file? }.each do |f|
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
- f_path = File.join(dest, file)
188
- FileUtils.mkdir_p(File.dirname(f_path))
194
+ fpath = File.join(dest_path, file)
195
+ FileUtils.mkdir_p(File.dirname(fpath))
189
196
  puts "Download: `#{file}'"
190
- zip_file.extract(f, f_path)
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
- Dir.glob("#{@base_path}#{file['source']}").select{ |fn| File.file?(fn) }.each do |source|
266
- dest = source.sub("#{@base_path}", '') # relative path in Crowdin
267
- dest_files << dest
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
- export_pattern = construct_export_pattern(dest, file['source'], file['translation'])
285
+ export_pattern = construct_export_pattern(dest, file['source'], file['translation'])
270
286
 
271
- local_file = { dest: dest, source: source, export_pattern: export_pattern }
272
- local_file.merge!({ sheme: file['scheme'] }) if file.has_key?('scheme')
273
- local_file.merge!({ first_line_contains_header: file['first_line_contains_header'] }) if file.has_key?('first_line_contains_header')
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
- local_files << local_file
276
- end
277
- end # if
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-dublicates'] ? 1 : 0
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
- Dir.glob("#{@base_path}#{file['source']}").select{ |fn| File.file?(fn) }.each do |source|
408
- dest = source.sub("#{@base_path}", '') # relative path in Crowdin
409
- dest_files << dest
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
- export_pattern = construct_export_pattern(dest, file['source'], file['translation'])
438
+ export_pattern = construct_export_pattern(dest, file['source'], file['translation'])
412
439
 
413
- translation_languages.each do |lang|
414
- source = export_pattern_to_path(dest, export_pattern, lang, languages_mapping)
415
- translated_files[lang['crowdin_code']] << { source: "#{@base_path}#{source}", dest: dest }
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 translation
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 zip archive
524
+ # keys is all possible files in .ZIP archive
496
525
  # values is resulted local files
497
- # usually they are equal
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
- downloadable_files[zipped_file] = local_file
538
+ downloadable_files_hash[zipped_file] = local_file
511
539
  end
512
540
  else
513
- Dir.glob("#{@base_path}#{file['source']}").select{ |fn| File.file?(fn) }.each do |source|
514
- dest = source.sub("#{@base_path}", '') # relative path in Crowdin
541
+ Find.find(@base_path) do |source_path|
542
+ dest = source_path.sub(@base_path, '') # relative path in Crowdin
515
543
 
516
- export_pattern = construct_export_pattern(dest, file['source'], file['translation'])
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
- translation_languages.each do |lang|
519
- zipped_file = export_pattern_to_path(dest, export_pattern, lang)
520
- local_file = export_pattern_to_path(dest, export_pattern, lang, languages_mapping)
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
- downloadable_files[zipped_file] = local_file
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
- file = Tempfile.new(language)
531
- path = file.path
568
+ tempfile = Tempfile.new(language)
569
+ zipfile_name = tempfile.path
532
570
  begin
533
- @crowdin.download_translation(language, output: path)
534
- unzip_file(path, @base_path, downloadable_files)
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
- file.close
537
- file.unlink # delete the temp file
575
+ tempfile.close
576
+ tempfile.unlink # delete the tempfile
538
577
  end
539
578
  end
540
579
 
@@ -1,5 +1,5 @@
1
1
  module Crowdin
2
2
  module CLI
3
- VERSION = '0.1.9'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
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.1.9
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-06-24 00:00:00.000000000 Z
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.0
147
+ rubygems_version: 2.0.3
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: Crowdin CLI.