bin/crowdin-cli in crowdin-cli-0.0.10 vs bin/crowdin-cli in crowdin-cli-0.0.11
- old
+ new
@@ -81,11 +81,11 @@
# Return a string representing that part of the directory tree that is common to all the files
#
# @params [Array] paths set of strings representing directory paths
#
def find_common_directory_path(paths)
- return paths.first if paths.length <= 1
+ return paths.first.split('/').slice(0...-1).join('/') if paths.length <= 1
arr = paths.sort
first = arr.first.split('/')
last = arr.last.split('/')
i = 0
i += 1 while first[i] == last[i] && i <= first.length
@@ -154,12 +154,14 @@
remote_project_tree = get_remote_files_hierarchy(project_info['files'])
local_files = []
dest_files = []
+
@config['files'].each do |file|
if File.exist?("#{@base_path}#{file['source']}")
+ dest_files << file['source']
local_files << { dest: file['source'], source: "#{@base_path}#{file['source']}", export_pattern: file['translation'] }
else
Dir.glob("#{@base_path}#{file['source']}").each do |source|
dest = source.sub("#{@base_path}", '') # relative path in Crowdin
dest_files << dest
@@ -173,21 +175,16 @@
end
end
end
- local_project_tree = get_local_files_hierarchy(local_files.collect{ |h| h[:dest] })
-
common_dir = find_common_directory_path(dest_files)
-
- if common_dir
- local_files.each{ |file| file[:dest].sub!(common_dir, '') }
- local_project_tree[:dirs].each{ |dir| dir.sub!(common_dir, '')}
- local_project_tree[:dirs].delete_if{ |dir| dir == ''}
- local_project_tree[:files].each{ |file| file.sub!(common_dir, '')}
- end
+ local_project_tree = get_local_files_hierarchy(local_files.collect{ |h| h[:dest].sub(common_dir, '') })
+
+ local_files.each{ |file| file[:dest].sub!(common_dir, '') }
+
# Create directory tree
#
create_dirs = local_project_tree[:dirs] - remote_project_tree[:dirs]
create_dirs.each do |dir|
puts "Create directory `#{dir}`"
@@ -257,9 +254,10 @@
dest_files = []
@config['files'].each do |file|
if File.exists?("#{@base_path}#{file['source']}")
dest = file['source'].sub("#{@base_path}", '')
+ dest_files << dest
translation_languages.each do |lang|
source = export_pattern_to_path(dest, file['translation'], lang)
translated_files[lang['crowdin_code']] << { source: "#{@base_path}#{source}", dest: dest }
end