5 from xml.sax import make_parser
6 from xml.sax.handler import ContentHandler, property_lexical_handler
8 from _xmlplus.sax.saxlib import LexicalHandler
15 class parseXML(ContentHandler, LexicalHandler):
16 def __init__(self, attrlist):
17 self.isPointsElement, self.isReboundsElement = 0, 0
18 self.attrlist = attrlist
19 self.last_comment = None
21 def comment(self, comment):
22 if comment.find("TRANSLATORS:") != -1:
23 self.last_comment = comment
25 def startElement(self, name, attrs):
26 for x in ["text", "title", "value", "caption"]:
28 attrlist.add((attrs[x], self.last_comment))
29 self.last_comment = None
33 parser = make_parser()
37 contentHandler = parseXML(attrlist)
38 parser.setContentHandler(contentHandler)
40 parser.setProperty(property_lexical_handler, contentHandler)
42 for arg in sys.argv[1:]:
43 if os.path.isdir(arg):
44 for file in os.listdir(arg):
45 if (file.endswith(".xml")):
46 parser.parse(os.path.join(arg, file))
50 attrlist = list(attrlist)
51 attrlist.sort(key=lambda a: a[0])
53 for (k,c) in attrlist:
56 string.replace(k, "\\n", "\"\n\"")
58 for l in c.split('\n'):
61 print 'msgid "' + str(k) + '"'