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)
41 dir = os.listdir(sys.argv[1])
43 if (str(x[-4:]) == ".xml"):
44 parser.parse(sys.argv[1] + str(x))
46 #parser.parse(sys.argv[1])
48 attrlist = list(attrlist)
49 attrlist.sort(key=lambda a: a[0])
51 for (k,c) in attrlist:
53 print '#: ' + sys.argv[1]
54 string.replace(k, "\\n", "\"\n\"")
56 for l in c.split('\n'):
59 print 'msgid "' + str(k) + '"'