Class: As3gettext::GenerateXml
- Inherits:
-
Object
- Object
- As3gettext::GenerateXml
- Includes:
- Builder, GetText
- Defined in:
- lib/as3gettext/generate_xml.rb
Instance Attribute Summary collapse
-
#xml_declaration ⇒ Object
Returns the value of attribute xml_declaration.
Instance Method Summary collapse
- #generate(files) ⇒ Object
-
#initialize ⇒ GenerateXml
constructor
A new instance of GenerateXml.
Constructor Details
#initialize ⇒ GenerateXml
Returns a new instance of GenerateXml.
15 16 17 18 |
# File 'lib/as3gettext/generate_xml.rb', line 15 def initialize @parser = PoParser.new @xml_declaration = false end |
Instance Attribute Details
#xml_declaration ⇒ Object
Returns the value of attribute xml_declaration.
19 20 21 |
# File 'lib/as3gettext/generate_xml.rb', line 19 def xml_declaration @xml_declaration end |
Instance Method Details
#generate(files) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/as3gettext/generate_xml.rb', line 21 def generate(files) files.map! {|f| Pathname.new(f) } res = '' xml = XmlMarkup.new(:indent => 2, :target => res) xml.instruct! :xml, :version=>"1.0", :encoding=> "UTF-8" if xml_declaration xml.langs do files.each do |file| langname = file.basename('.po').to_s unless langname.empty? data = MOFile.new @parser.parse(file.read, data) xml.lang(:lang => langname) { data.each do |msgid, msgstr| next if msgid.length == 0 xml. { xml.msgid(msgid) xml.msgstr(msgstr) } end } end end end res.gsub(/&#([\d+]+);/){[$1.to_i].pack("U")} end |