Class: I18nPoTools::Formats::CsvFormat
Instance Attribute Summary
Attributes inherited from BaseFormat
#options
Instance Method Summary
collapse
Methods inherited from BaseFormat
#banner_msg, #file_encoding, #read_file, #read_with_options, #write_file, #write_with_options
Instance Method Details
#read(input_filename) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/i18n_po_tools/formats/csv_format.rb', line 7
def read(input_filename)
content = read_file(input_filename)
h = {}
first = true
CSV.parse(content) do |row|
if first
first = false
else
h[row[0]] = row[1]
end
end
h
end
|
#write(output_filename, data) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/i18n_po_tools/formats/csv_format.rb', line 21
def write(output_filename, data)
content = CSV.generate do |csv|
csv << ["Key","Translation"]
data.each_pair do |k,v|
csv << [k,v]
end if data.present?
end
write_file(output_filename, content)
end
|