bin/crowdin-cli in crowdin-cli-0.2.1 vs bin/crowdin-cli in crowdin-cli-0.2.2

- old
+ new

@@ -102,38 +102,76 @@ export_pattern.insert(0, '/') if translation.start_with?('/') return export_pattern end -# Provides a partial implementation of translate a glob +pattern+ to a regular expression +# This is a partial translation of the algorithm defined in fnmatch.py +# https://github.com/python-git/python/blob/master/Lib/fnmatch.py +# Provides a partial implementation of translate a glob +pat+ to a regular expression +# +# Patterns are Unix shell style: +# * matches everything +# ? matches any single character +# [seq] matches any character in seq +# [^seq] matches any char not in seq +# # NOTE: -# `**` surrounded by backslashes `/` in the +pattern+ -# `**` used only once in the +pattern+ +# `**` surrounded by backslashes `/` in the +pat+ +# `**` used only once in the +pat+ # -def translate_pattern_to_regexp(pattern) +def translate_pattern_to_regexp(pat) i = 0 - n = pattern.size + n = pat.size res = '' while i < n - c = pattern[i] + c = pat[i] i = i + 1 if c == '*' j = i - if j < n and pattern[j] == '*' + if j < n and pat[j] == '*' res[-1] = '(\/)?(?<double_asterisk>.*)?' i = j + 1 else - res << '(.*)' + res = res + '.*' end elsif c == '?' - res << '.' + res = res + '.' + elsif c == '[' + j = i + # The following two statements check if the sequence we stumbled + # upon is '[]' or '[^]' because those are not valid character + # classes. + if j < n and pat[j] == '^' + j = j + 1 + end + if j < n and pat[j] == ']' + j = j + 1 + end + # Look for the closing ']' right off the bat. If one is not found, + # escape the opening '[' and continue. If it is found, process + # he contents of '[...]'. + while j < n and pat[j] != ']' + j = j + 1 + end + if j >= n + res = res + '\\[' + else + stuff = pat[i...j].gsub('\\', '\\\\') + i = j + 1 + #if stuff[0] == '!' + # stuff = '^' + stuff[1..-1] + #elsif stuff[0] == '^' + # stuff = '\\' + stuff + #end + res = "#{res}[#{stuff}]" + end else - res << Regexp.escape(c) + res = res + Regexp.escape(c) end end - return Regexp.new(res) + return Regexp.new(res + '$') end def android_locale_code(locale_code) locale_code = case locale_code when 'he-IL' then 'iw-IL' @@ -260,10 +298,12 @@ @config['files'].each do |file| get_invalid_placeholders(file['translation']).each do |placeholder| puts "Warning: #{placeholder} is not valid variable supported by Crowdin. See http://crowdin.net/page/cli-tool#configuration-file for more details." end + ignores = file['ignore'] || [] + if File.exist?(File.join(@base_path, file['source'])) dest = file['source'] dest_files << dest local_file = { dest: dest, source: File.join(@base_path, file['source']), export_pattern: file['translation'] } @@ -275,17 +315,18 @@ else Find.find(@base_path) do |source_path| dest = source_path.sub(@base_path, '') # relative path in Crowdin if File.directory?(source_path) - ignores = file['ignore'] || [] - if ignores.include?(dest) + if ignores.any?{ |pattern| File.fnmatch?(pattern, dest, File::FNM_PATHNAME) } Find.prune # Don't look any further into this directory else next end elsif File.fnmatch?(file['source'], dest, File::FNM_PATHNAME) + next if ignores.any?{ |pattern| File.fnmatch?(pattern, dest, File::FNM_PATHNAME) } + dest_files << dest export_pattern = construct_export_pattern(dest, file['source'], file['translation']) local_file = { dest: dest, source: source_path, export_pattern: export_pattern } @@ -414,10 +455,12 @@ @config['files'].each do |file| get_invalid_placeholders(file['translation']).each do |placeholder| puts "Warning: #{placeholder} is not valid variable supported by Crowdin. See http://crowdin.net/page/cli-tool#configuration-file for more details." end + ignores = file['ignore'] || [] + languages_mapping = file['languages_mapping'] # CSV files only (default: false) multilingual_spreadsheet = file['multilingual_spreadsheet'] || false @@ -438,17 +481,18 @@ else Find.find(@base_path) do |source_path| dest = source_path.sub(@base_path, '') # relative path in Crowdin if File.directory?(source_path) - ignores = file['ignore'] || [] - if ignores.include?(dest) + if ignores.any?{ |pattern| File.fnmatch?(pattern, dest, File::FNM_PATHNAME) } Find.prune # Don't look any further into this directory else next end elsif File.fnmatch?(file['source'], dest, File::FNM_PATHNAME) + next if ignores.any?{ |pattern| File.fnmatch?(pattern, dest, File::FNM_PATHNAME) } + dest_files << dest export_pattern = construct_export_pattern(dest, file['source'], file['translation']) file_translation_languages.each do |lang| @@ -541,10 +585,12 @@ downloadable_files_hash = {} @config['files'].each do |file| languages_mapping = file['languages_mapping'] # Hash or NilClass + ignores = file['ignore'] || [] + # CSV files only (default: false) multilingual_spreadsheet = file['multilingual_spreadsheet'] || false if multilingual_spreadsheet file_translation_languages = [] << source_language @@ -565,16 +611,17 @@ else Find.find(@base_path) do |source_path| dest = source_path.sub(@base_path, '') # relative path in Crowdin if File.directory?(source_path) - ignores = file['ignore'] || [] - if ignores.include?(dest) + if ignores.any?{ |pattern| File.fnmatch?(pattern, dest, File::FNM_PATHNAME) } Find.prune # Don't look any further into this directory else next end elsif File.fnmatch?(file['source'], dest, File::FNM_PATHNAME) + next if ignores.any?{ |pattern| File.fnmatch?(pattern, dest, File::FNM_PATHNAME) } + export_pattern = construct_export_pattern(dest, file['source'], file['translation']) file_translation_languages.each do |lang| zipped_file = export_pattern_to_path(dest, export_pattern, lang) zipped_file.sub!(/^\//, '')