14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/crowdin2csv.rb', line 14
def crowdin2csv(filename, output_filename)
CSV.open(output_filename, 'w') do |csv|
csv << CSV_HEADER
doc = Nokogiri::XML(File.read(filename), nil, 'UTF-8', &:strict)
doc.css('file').each do |file|
file_id = file.attr('id')
original = file.attr('original')
_source_lang = file.attr('source-language')
_target_lang = file.attr('target-language')
_datatype = file.attr('datatype')
file.css('trans-unit').each do |trans_unit|
trans_unit_id = trans_unit.attr('id')
resname = trans_unit.attr('resname')
source = trans_unit.css('source').text
target = trans_unit.css('target').text
note = trans_unit.css('note').text
cols = [trans_unit_id, file_id, original, source, target, resname, note]
csv << cols
end
end
end
end
|