X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/0cb0ae82b752fa39732f42ac348dd34ffeef2052..1ff71d24c512a57686d8cdbef41bc0112ca9be72:/po/xml2po.py diff --git a/po/xml2po.py b/po/xml2po.py index 3c6219ea..cfbeaf4b 100755 --- a/po/xml2po.py +++ b/po/xml2po.py @@ -4,7 +4,13 @@ import os import string from xml.sax import make_parser from xml.sax.handler import ContentHandler, property_lexical_handler -from _xmlplus.sax.saxlib import LexicalHandler +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): @@ -30,24 +36,29 @@ attrlist = set() contentHandler = parseXML(attrlist) parser.setContentHandler(contentHandler) -parser.setProperty(property_lexical_handler, contentHandler) -dir = os.listdir(sys.argv[1]) -for x in dir: - if (str(x[-4:]) == ".xml"): - parser.parse(sys.argv[1] + str(x)) - -#parser.parse(sys.argv[1]) - -attrlist = list(attrlist) -attrlist.sort(key=lambda a: a[0]) - -for (k,c) in attrlist: - print - print '#: ' + sys.argv[1] - string.replace(k, "\\n", "\"\n\"") - if c: - for l in c.split('\n'): - print "#. ", l - print 'msgid "' + str(k) + '"' - print 'msgstr ""' +if not no_comments: + parser.setProperty(property_lexical_handler, contentHandler) +for arg in sys.argv[1:]: + if os.path.isdir(arg): + for file in os.listdir(arg): + if (file.endswith(".xml")): + parser.parse(os.path.join(arg, file)) + else: + parser.parse(arg) + + attrlist = list(attrlist) + attrlist.sort(key=lambda a: a[0]) + + for (k,c) in attrlist: + print + print '#: ' + arg + string.replace(k, "\\n", "\"\n\"") + if c: + for l in c.split('\n'): + print "#. ", l + if str(k).strip() != "": + print 'msgid "' + str(k) + '"' + print 'msgstr ""' + + attrlist = set()