X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/7725f7f3f752fce60f4a5dff7ef68e59557ad613..672b0fa44cd420dbf5b4d1f9c9a5c3201ada06da:/po/xml2po.py diff --git a/po/xml2po.py b/po/xml2po.py index dac3a773..8108caeb 100755 --- a/po/xml2po.py +++ b/po/xml2po.py @@ -1,27 +1,43 @@ #!/usr/bin/python import sys import os +import string from xml.sax import make_parser -from xml.sax.handler import ContentHandler - -class parseXML(ContentHandler): +from xml.sax.handler import ContentHandler, property_lexical_handler +try: + from _xmlplus.sax.saxlib import LexicalHandler + no_comments = False +except ImportError: + class LexicalHandler: + pass + no_comments = True + +class parseXML(ContentHandler, LexicalHandler): def __init__(self, attrlist): self.isPointsElement, self.isReboundsElement = 0, 0 self.attrlist = attrlist + self.last_comment = None + + def comment(self, comment): + if comment.find("TRANSLATORS:") != -1: + self.last_comment = comment def startElement(self, name, attrs): - if (attrs.has_key('text')): - attrlist[attrs.get('text', "")] = "foo" - if (attrs.has_key('title')): - attrlist[attrs.get('title', "")] = "foo" + for x in ["text", "title", "value", "caption"]: + try: + attrlist.add((attrs[x], self.last_comment)) + self.last_comment = None + except KeyError: + pass parser = make_parser() -attrlist = {} +attrlist = set() contentHandler = parseXML(attrlist) parser.setContentHandler(contentHandler) - +if not no_comments: + parser.setProperty(property_lexical_handler, contentHandler) dir = os.listdir(sys.argv[1]) for x in dir: if (str(x[-4:]) == ".xml"): @@ -29,9 +45,17 @@ for x in dir: #parser.parse(sys.argv[1]) -for k, v in attrlist.items(): +attrlist = list(attrlist) +attrlist.sort(key=lambda a: a[0]) + +for (k,c) in attrlist: print print '#: ' + sys.argv[1] - print 'msgid "' + str(k) + '"' - print 'msgstr ""' + string.replace(k, "\\n", "\"\n\"") + if c: + for l in c.split('\n'): + print "#. ", l + if str(k) != "": + print 'msgid "' + str(k) + '"' + print 'msgstr ""'