bin/crowdin-cli in crowdin-cli-0.0.20 vs bin/crowdin-cli in crowdin-cli-0.1.0
- old
+ new
@@ -1,9 +1,11 @@
#!/usr/bin/env ruby
require 'crowdin-cli'
+# GLI_DEBUG=true bundle exec bin/crowdin-cli
+
# Return +hierarchy+ of directories and files in Crowdin project
#
# +files+ - basically, it's project files details from API method `project_info`
#
def get_remote_files_hierarchy(files, root = '/', hierarchy = { dirs: [], files: [] })
@@ -200,25 +202,31 @@
puts "Warning: #{placeholder} is not valid variable supported by Crowdin. See http://crowdin.net/page/cli-client#configuration-file for more details."
end
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'] }
+ local_file = { 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
file_pattern = export_pattern_to_path(dest, file['translation'], source_language)
diff = (dest.split('/') - file_pattern.split('/')).join('/')
export_pattern = file['translation'].sub('**', diff)
- local_files << { dest: dest, source: source, export_pattern: export_pattern }
+ local_file = { dest: dest, source: source, export_pattern: export_pattern }
end
end # if
+
+ # Used only when uploading CSV file to define data columns mapping.
+ local_file.merge!({ sheme: file['scheme'] }) if file.has_key?('scheme')
+ local_file.merge!({ first_line_contains_header: file['first_line_contains_header'] }) if file.has_key?('first_line_contains_header')
+
+ local_files << local_file
end # @config['files']
if dest_files.empty?
exit_now!("nothing to upload. See http://crowdin.net/page/cli-client#configuration-file for more details.")
end
@@ -243,11 +251,16 @@
# array containing elements common to the two arrays
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.each do |file|
print "Updating file `#{file[:dest]}'"
- resp = @crowdin.update_file([] << file)
+
+ params = {}
+ params[:scheme] = file.delete(:sheme)
+ params[:first_line_contains_header] = file.delete(:first_line_contains_header)
+
+ resp = @crowdin.update_file([] << file, params)
case resp['files'].first[1]
when 'skipped'
puts "\rUpdating file `#{file[:dest]}' - Skipped"
when 'updated'
puts "\rUpdating file `#{file[:dest]}' - OK"
@@ -259,10 +272,15 @@
#
add_files = local_project_tree[:files] - remote_project_tree[:files]
files_for_add = local_files.select{ |file| add_files.include?(file[:dest]) }
files_for_add.each do |file|
print "Uploading file `#{file[:dest]}'"
- res = @crowdin.add_file([] << file)
+
+ params = {}
+ params[:scheme] = file.delete(:sheme)
+ params[:first_line_contains_header] = file.delete(:first_line_contains_header)
+
+ resp = @crowdin.add_file([] << file, params)
puts "\rUploading file `#{file[:dest]}' - OK"
end
end # action
end # command