bin/crowdin-cli in crowdin-cli-0.5.1 vs bin/crowdin-cli in crowdin-cli-0.5.3
- old
+ new
@@ -80,10 +80,11 @@
'%locale%' => lang['locale'],
'%locale_with_underscore%' => lang['locale'].gsub('-', '_'),
'%android_code%' => android_locale_code(lang['locale']),
'%osx_code%' => osx_language_code(lang['crowdin_code']) + '.lproj',
'%osx_xliff%' => osx_language_code(lang['crowdin_code']) + '.xliff',
+ '%osx_locale%' => osx_language_code(lang['crowdin_code']),
}
placeholders = pattern.inject([]){ |memo, h| memo << h.first[/%(.*)%/, 1] }
unless languages_mapping.nil?
@@ -207,11 +208,12 @@
'%three_letters_code%',
'%locale%',
'%locale_with_underscore%',
'%android_code%',
'%osx_code%',
- '%osx_liff%',
+ '%osx_xliff%',
+ '%osx_locale%',
'%original_file_name%',
'%original_path%',
'%file_extension%',
'%file_name%',
]
@@ -252,12 +254,18 @@
# files that exists in archive and doesn't match current project configuration
unmatched_files = []
Zip::File.open(zipfile_name) do |zipfile|
zipfile.select { |zip_entry| zip_entry.file? }.each do |f|
+ filename = f.name
+ if @branch_name and @base_path_contains_branch_subfolders
+ # strip branch from filename
+ filename = f.name.sub(File.join(@branch_name, '/'), '')
+ end
+
# `f' - relative path in archive
- file = files_list[f.name]
+ file = files_list[filename]
if file
fpath = File.join(dest_path, file)
FileUtils.mkdir_p(File.dirname(fpath))
puts "Extracting: `#{file}'"
zipfile.extract(f, fpath)
@@ -450,11 +458,11 @@
local_files << local_file
end
end # Find
- end # if File.exists?
+ end # if File.exist?
end # @config['files']
if dest_files.empty?
exit_now! <<-EOS.strip_heredoc
No source files to upload.
@@ -628,11 +636,11 @@
file_translation_languages = [] << source_language
else
file_translation_languages = translation_languages
end
- if File.exists?(File.join(@base_path, file['source']))
+ if File.exist?(File.join(@base_path, file['source']))
dest = file['dest'] || file['source']
dest.sub!(/\A#{Regexp.escape(@base_path)}/, '')
dest_files << dest
file_translation_languages.each do |lang|
@@ -730,10 +738,13 @@
c.flag [:b, :branch]
c.desc I18n.t('app.commands.download.switches.ignore_match.desc')
c.switch ['ignore-match'], negatable: false
+ c.desc I18n.t('app.commands.download.switches.include_unchanged')
+ c.switch ['include-unchanged'], negatable: false
+
c.action do |global_options, options, args|
if @branch_name
branch = @project_info['files'].find { |h| h['node_type'] == 'branch' && h['name'] == @branch_name }
unless branch
@@ -766,19 +777,21 @@
end
params = {}
params[:branch] = @branch_name if @branch_name
- # use export API method before to download the most recent translations
- print 'Building ZIP archive with the latest translations '
- export_translations = @crowdin.export_translations(params)
- 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."
+ unless options['include-unchanged']
+ # use export API method before to download the most recent translations
+ print 'Building ZIP archive with the latest translations '
+ export_translations = @crowdin.export_translations(params)
+ 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
end
source_language = @project_info['details']['source_language']['code']
source_language = supported_languages.find { |lang| lang['crowdin_code'] == source_language }
@@ -801,11 +814,11 @@
file_translation_languages = [] << source_language
else
file_translation_languages = translation_languages
end
- if File.exists?(File.join(@base_path, file['source']))
+ if File.exist?(File.join(@base_path, file['source']))
dest = file['source'].sub(/\A#{Regexp.escape(@base_path)}/, '')
file_translation_languages.each do |lang|
zipped_file = export_pattern_to_path(dest, file['translation'], lang)
zipped_file.sub!(/^\//, '')
@@ -950,11 +963,11 @@
local_files << local_file
end
end # Find
- end # if File.exists?
+ end # if File.exist?
end # @config['files']
common_dir = @preserve_hierarchy ? '' : find_common_directory_path(dest_files)
local_project_tree = get_local_files_hierarchy(local_files.collect { |h| h[:dest].sub(common_dir, '') })
@@ -983,11 +996,11 @@
@config['files'].each do |file|
languages_mapping = file['languages_mapping'] # Hash or NilClass
ignores = file['ignore'] || []
- if File.exists?(File.join(@base_path, file['source']))
+ if File.exist?(File.join(@base_path, file['source']))
dest = file['source'].sub(/\A#{Regexp.escape(@base_path)}/, '')
translation_languages.each do |lang|
local_file = export_pattern_to_path(dest, file['translation'], lang, languages_mapping)
translation_files << local_file
@@ -1051,11 +1064,11 @@
'translate_attributes',
'content_segmentation',
'translatable_elements',
]
- unless File.exists?(globals[:config])
+ unless File.exist?(globals[:config])
exit_now! <<-EOS.strip_heredoc
Can't find configuration file (default `crowdin.yaml').
Type `crowdin-cli help` to know how to specify custom configuration file
See http://crowdin.com/page/cli-tool#configuration-file for more details
@@ -1093,11 +1106,11 @@
end
end
# user credentials in the user-specific config file have a higher priority than project-specific
#
- if File.exists?(globals[:identity])
+ if File.exist?(globals[:identity])
identity = YAML.load(ERB.new(File.read(globals[:identity])).result) || {}
['api_key', 'project_identifier', 'base_path'].each do |key|
@config[key] = identity[key] if identity[key]
end
end
@@ -1168,13 +1181,29 @@
puts <<-EOS.strip_heredoc
Warning: Configuration file misses parameter `base_path` that defines your project root directory. Using `#{@base_path}` as a root directory.
EOS
end
+ @base_path_contains_branch_subfolders = false
+ if @config['base_path_contains_branch_subfolders']
+ @base_path_contains_branch_subfolders = case @config['base_path_contains_branch_subfolders']
+ when true
+ true
+ when false
+ false
+ else
+ exit_now! <<-EOS.strip_heredoc
+ Parameter `base_path_contains_branch_subfolders` allows values of true or false.
+ EOS
+ end
+ end
+
@branch_name = options[:branch] || nil
- # @base_path = @branch_name ? File.join(@base_path, @branch_name) : @base_path
+ if @branch_name and @base_path_contains_branch_subfolders
+ @base_path = File.join(@base_path, @branch_name)
+ end
- unless Dir.exists?(@base_path)
+ unless Dir.exist?(@base_path)
exit_now! <<-EOS.strip_heredoc
No such directory `#{@base_path}`. Please make sure that the `base_path` is properly set.
EOS
end