bin/crowdin-cli in crowdin-cli-0.0.2 vs bin/crowdin-cli in crowdin-cli-0.0.3
- old
+ new
@@ -5,20 +5,11 @@
require 'gli'
require 'zip/zip'
require 'crowdin-api'
require 'crowdin-cli'
-#begin # XXX: Remove this begin/rescue before distributing your app
-#require 'crowdin-cli'
-#rescue LoadError
-# STDERR.puts "In development, you need to use `bundle exec bin/crowdin-cli` to run your app"
-# STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
-# STDERR.puts "Feel free to remove this message from bin/crowdin-cli now"
-# exit 64
-#end
-
-# Ця хуїта повертає структуру директорій на сервері
+# повертає структуру директорій на сервері
#
def walk_remote_tree(files, root = '/', result = { dirs: [], files: [] })
files.each do |node|
case node['node_type']
when 'directory'
@@ -31,11 +22,10 @@
return result
end
-# Хуйня... хулі
# Повертає локальну структуру директорій
# На вході масив файлів, наприклад:
# ['/path/to/admin/en.xml', '/path/to/user/settings/strings.xml']
# Результат хеш { dirs:[послідовний масив директорій для створення], files: [] }
#
@@ -67,11 +57,21 @@
zip_file.extract(f, f_path)
end
end
end
+def android_locale_code(locale_code)
+ locale_code = case locale_code
+ when 'he-IL' then 'iw-IL'
+ when 'yi-DE' then 'ji-DE'
+ when 'id-ID' then 'in-ID'
+ else locale_code
+ end
+ return locale_code.sub('-', '-r')
+end
+
###
include GLI::App
program_desc 'A CLI to sync locale files with crowdin.net'
@@ -107,14 +107,10 @@
# TODO: change variables names!
c.desc 'Upload source files'
c.command :sources do |c|
c.action do |global_options, options, args|
-
- c.desc 'defines whether to add files if there is the same file previously added'
- c.switch [:upload_duplicates]
-
project_info = @crowdin.project_info(:json)
project_info = JSON.parse(project_info)
remote_project_tree = walk_remote_tree(project_info['files'])
@@ -143,18 +139,16 @@
end
# Update existing files in Crowdin project
#
# array containing elements common to the two arrays
- if options[:upload_dublicates]
- update_files = local_project_tree[:files] & remote_project_tree[:files]
- files_for_upload = local_files.select{ |file| update_files.include?(file[:dest]) }
- files_for_upload.map{ |file| file.keep_if{ |k, v| [:source, :dest].include?(k) } }
- files_for_upload.each do |file|
- puts "Update file `#{file[:dest]}`"
- @crowdin.update_file([] << file)
- end
+ update_files = local_project_tree[:files] & remote_project_tree[:files]
+ files_for_upload = local_files.select{ |file| update_files.include?(file[:dest]) }
+ files_for_upload.map{ |file| file.keep_if{ |k, v| [:source, :dest].include?(k) } }
+ files_for_upload.each do |file|
+ puts "Update file `#{file[:dest]}`"
+ @crowdin.update_file([] << file)
end
# Add new files to Crowdin project
#
add_files = local_project_tree[:files] - remote_project_tree[:files]
@@ -234,11 +228,11 @@
'%two_letter_code%' => lang['iso_639_1'],
'%tree_letter_code%' => lang['iso_639_3'],
'%locale%' => lang['locale'],
'%locale_with_underscore%' => lang['locale'].gsub('-', '_'),
'%original_file_name%' => original_file_name,
- '%android_code%' => 'values-',
+ '%android_code%' => android_locale_code(lang['locale']),
'%original_path%' => original_path,
'%file_extension%' => file_extension,
'%file_name%' => file_extension,
})
translated_files[lang['crowdin_code']] << { source: @local_path + file, dest: source }
@@ -277,9 +271,12 @@
c.desc 'the language of translation you need'
c.arg_name 'language_code'
c.flag :l, :language, :default_value => 'all'
c.action do |global_options ,options, args|
+ # use export API method before to download the most recent translations
+ @crowdin.export_translations
+
language = options[:language]
file = Tempfile.new(language)
begin
@crowdin.download_translation(language, :output => file)