Class: I18nPoTools::Formats::AndroidFormat

Inherits:
BaseFormat
  • Object
show all
Defined in:
lib/i18n_po_tools/formats/android_format.rb

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
# File 'lib/i18n_po_tools/formats/android_format.rb', line 7

def read(input_filename)
  content = read_file(input_filename)
  doc = Nokogiri.XML(content, nil, 'UTF-8')
  h = {}
  doc.xpath('//resources/string').each do |message_token|
    h[message_token["name"]] = message_token.inner_html
  end
  h
end

#write(output_filename, data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/i18n_po_tools/formats/android_format.rb', line 17

def write(output_filename, data)
  content  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  content += "<!-- "+banner_msg+" -->\n"
  content += "<resources>\n\n"
  data.each_pair do |k,v|
    content += "    <string name=\""+(k.nil? ? '':k)+"\">"+(v.nil? ? '':Nokogiri::HTML.fragment(v).to_html)+"</string>\n"
  end if data.present?
  content += "</resources>\n"
  write_file(output_filename, content)
end