2 parser/glade.rb - parser for Glade-2
4 Copyright (C) 2004,2005 Masao Mutoh
6 You may redistribute it and/or modify it under the same
7 license terms as Ruby or LGPL.
18 bindtextdomain("rgettext")
20 TARGET1 = /<property.*translatable="yes">(.*)/
21 TARGET2 = /(.*)<\/property>/
23 def parse(file, targets = []) # :nodoc:
24 lines = IO.readlines(file)
25 parse_lines(file, lines, targets)
29 def parse_lines(file, lines, targets) # :nodoc:
46 add_target(val, file, line_no, targets)
53 add_target(val, file, line_no, targets)
65 GLADE_RE = /glade-2.0.dtd/
67 def target?(file) # :nodoc:
68 data = IO.readlines(file)
69 if XML_RE =~ data[0] and GLADE_RE =~ data[1]
72 if File.extname(file) == '.glade'
73 raise _("`%{file}' is not glade-2.0 format.") % {:file => file}
79 def add_target(val, file, line_no, targets) # :nodoc:
80 return unless val.size > 0
81 assoc_data = targets.assoc(val)
82 val = CGI.unescapeHTML(val)
84 targets[targets.index(assoc_data)] = assoc_data << "#{file}:#{line_no}"
86 targets << [val.gsub(/\n/, '\n'), "#{file}:#{line_no}"]
94 # ex) ruby glade.rb foo.glade bar.glade
96 p GetText::GladeParser.parse(file)