bin/crowdin-cli in crowdin-cli-0.3.10 vs bin/crowdin-cli in crowdin-cli-0.4.0
- old
+ new
@@ -387,11 +387,11 @@
end
local_files << local_file
else
Find.find(@base_path) do |source_path|
- dest = source_path.sub(@base_path, '') # relative path in Crowdin
+ dest = source_path.sub(/\A#{@base_path}/, '') # relative path in Crowdin
if File.directory?(source_path)
if ignores.any? { |pattern| File.fnmatch?(pattern, dest, File::FNM_PATHNAME) }
Find.prune # Don't look any further into this directory
else
@@ -555,20 +555,20 @@
else
file_translation_languages = translation_languages
end
if File.exists?(File.join(@base_path, file['source']))
- dest = file['source'].sub("#{@base_path}", '')
+ dest = file['source'].sub(/\A#{@base_path}/, '')
dest_files << dest
file_translation_languages.each do |lang|
source = export_pattern_to_path(dest, file['translation'], lang, languages_mapping)
translated_files[lang['crowdin_code']] << { source: File.join(@base_path, source), dest: dest }
end
else
Find.find(@base_path) do |source_path|
- dest = source_path.sub(@base_path, '') # relative path in Crowdin
+ dest = source_path.sub(/\A#{@base_path}/, '') # relative path in Crowdin
if File.directory?(source_path)
if ignores.any? { |pattern| File.fnmatch?(pattern, dest, File::FNM_PATHNAME) }
Find.prune # Don't look any further into this directory
else
@@ -606,25 +606,27 @@
files.each do |file|
file[:dest] = file[:dest].sub(common_dir, '')
if remote_project_tree[:files].include?(file[:dest])
if File.exist?(file[:source])
- print "Uploading translation file `#{file[:source].sub(@base_path, '')}'"
+ print "Uploading translation file `#{file[:source].sub(/\A#{@base_path}/, '')}'"
resp = @crowdin.upload_translation([] << file, language, params)
case resp['files'].first[1]
when 'skipped'
- puts "\rUploading translation file `#{file[:source].sub(@base_path, '')}' - Skipped"
+ puts "\rUploading translation file `#{file[:source].sub(/\A#{@base_path}/, '')}' - Skipped"
when 'uploaded'
- puts "\rUploading translation file `#{file[:source].sub(@base_path, '')}' - OK"
+ puts "\rUploading translation file `#{file[:source].sub(/\A#{@base_path}/, '')}' - OK"
+ when 'not_allowed'
+ puts "\rUploading translation file `#{file[:source].sub(/\A#{@base_path}/, '')}' - is not possible"
end
else
puts "Warning: Local file `#{file[:source]}' does not exist"
end
else
# if source file does not exist, don't upload translations
- puts "Warning: Skip `#{file[:source].sub(@base_path, '')}'"
+ puts "Warning: Skip `#{file[:source].sub(/\A#{@base_path}/, '')}'"
end
end
end
end # action
@@ -665,11 +667,20 @@
exit_now!("language '#{language}' doesn't exist in a project")
end
end
# use export API method before to download the most recent translations
- @crowdin.export_translations
+ print 'Build ZIP archive with the latest translations '
+ export_translations = @crowdin.export_translations
+ if export_translations['success']
+ if export_translations['success']['status'] == 'built'
+ puts "- OK"
+ elsif export_translations['success']['status'] == 'skipped'
+ puts "- Skipped"
+ puts "Warning: Export was skipped. Please note that this method can be invoked only once per 30 minutes."
+ end
+ end
source_language = project_info['details']['source_language']['code']
source_language = supported_languages.find { |lang| lang['crowdin_code'] == source_language }
translation_languages = supported_languages.select { |lang| project_languages.include?(lang['crowdin_code']) }
@@ -691,22 +702,22 @@
else
file_translation_languages = translation_languages
end
if File.exists?(File.join(@base_path, file['source']))
- dest = file['source'].sub("#{@base_path}", '')
+ dest = file['source'].sub(/\A#{@base_path}/, '')
file_translation_languages.each do |lang|
zipped_file = export_pattern_to_path(dest, file['translation'], lang)
zipped_file.sub!(/^\//, '')
local_file = export_pattern_to_path(dest, file['translation'], lang, languages_mapping)
downloadable_files_hash[zipped_file] = local_file
end
else
Find.find(@base_path) do |source_path|
- dest = source_path.sub(@base_path, '') # relative path in Crowdin
+ dest = source_path.sub(/\A#{@base_path}/, '') # relative path in Crowdin
if File.directory?(source_path)
if ignores.any? { |pattern| File.fnmatch?(pattern, dest, File::FNM_PATHNAME) }
Find.prune # Don't look any further into this directory
else
@@ -793,11 +804,11 @@
end
local_files << local_file
else
Find.find(@base_path) do |source_path|
- dest = source_path.sub(@base_path, '') # relative path in Crowdin
+ dest = source_path.sub(/\A#{@base_path}/, '') # relative path in Crowdin
if File.directory?(source_path)
if ignores.any? { |pattern| File.fnmatch?(pattern, dest, File::FNM_PATHNAME) }
Find.prune # Don't look any further into this directory
else
@@ -854,20 +865,20 @@
languages_mapping = file['languages_mapping'] # Hash or NilClass
ignores = file['ignore'] || []
if File.exists?(File.join(@base_path, file['source']))
- dest = file['source'].sub("#{@base_path}", '')
+ dest = file['source'].sub(/\A#{@base_path}/, '')
translation_languages.each do |lang|
local_file = export_pattern_to_path(dest, file['translation'], lang, languages_mapping)
translation_files << local_file
end
else
Find.find(@base_path) do |source_path|
- dest = source_path.sub(@base_path, '') # relative path in Crowdin
+ dest = source_path.sub(/\A#{@base_path}/, '') # relative path in Crowdin
if File.directory?(source_path)
if ignores.any? { |pattern| File.fnmatch?(pattern, dest, File::FNM_PATHNAME) }
Find.prune # Don't look any further into this directory
else
@@ -930,10 +941,10 @@
else
@config = YAML.load_file(globals[:config]) || {}
if File.exists?(globals[:identity])
identity = YAML.load_file(globals[:identity]) || {}
- ['api_key', 'project_identifier'].each do |key|
+ ['api_key', 'project_identifier', 'base_path'].each do |key|
@config[key] = identity[key] if identity[key]
end
end
['api_key', 'project_identifier'].each do |key|