|
@@ -4,14 +4,14 @@ require 'nokogiri'
|
|
|
module MultiLangTrans
|
|
|
ORINGIN_PATH = 'template/Resources.resw'
|
|
|
TEMPLATE_PATH = 'template/template.csv'
|
|
|
-
|
|
|
+
|
|
|
def self.run
|
|
|
make_template
|
|
|
input_file_paths = Dir.glob('input/*.csv')
|
|
|
input_file_paths.each do |input_file_path|
|
|
|
input_content = read_csv(input_file_path)
|
|
|
- output_file_path = to_output_path(input_file_path)
|
|
|
- write_xml(output_file_path, input_content)
|
|
|
+ output_file_paths = get_output_paths(input_file_path)
|
|
|
+ write_xml(output_file_paths, input_content)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -36,18 +36,21 @@ module MultiLangTrans
|
|
|
input_content
|
|
|
end
|
|
|
|
|
|
- def self.to_output_path(input_path)
|
|
|
+ def self.get_output_paths(input_path)
|
|
|
+ output_paths = {}
|
|
|
output_path = input_path.sub('input/', "output/")
|
|
|
- output_path = output_path.sub('.csv', ".xml")
|
|
|
+ output_paths[:matched] = output_path.sub('.csv', ".txt")
|
|
|
+ output_paths[:dismatched] = output_path.sub('.csv', "-not-found.txt")
|
|
|
+ output_paths
|
|
|
end
|
|
|
|
|
|
- def self.write_xml(xml_file_path, content_rows)
|
|
|
- not_found = []
|
|
|
- File.open(xml_file_path, 'w') do |f|
|
|
|
- content_rows.each do |row|
|
|
|
+ def self.write_xml(xml_file_paths, content_rows)
|
|
|
+ not_found_rows = []
|
|
|
+ File.open(xml_file_paths[:matched], 'w') do |f|
|
|
|
+ content_rows.each_with_index do |row, index|
|
|
|
template_row = @template_content.find{|t| t['trans_value'] == row['template_value']}
|
|
|
if template_row.nil?
|
|
|
- not_found << row['template_value']
|
|
|
+ not_found_rows << "line:#{index + 2}.\t#{row['template_value']}"
|
|
|
else
|
|
|
f.puts("<data name=\"#{template_row['name']}\" xml:space=\"preserve\">")
|
|
|
f.puts(" <value>#{row['trans_value']}</valie>") unless row['trans_value'].nil?
|
|
@@ -56,10 +59,8 @@ module MultiLangTrans
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
- File.open("#{xml_file_path}-not-found", 'w') do |f|
|
|
|
- not_found.each_with_index do |row, index|
|
|
|
- f.puts("#{index}. [#{row}]")
|
|
|
- end
|
|
|
+ File.open(xml_file_paths[:dismatched], 'w') do |f|
|
|
|
+ not_found_rows.each { |row| f.puts(row) }
|
|
|
end
|
|
|
end
|
|
|
end
|