diff options
| author | Felix Domke <tmbinc@elitedvb.net> | 2008-03-13 22:51:04 +0000 |
|---|---|---|
| committer | Felix Domke <tmbinc@elitedvb.net> | 2008-03-13 22:51:04 +0000 |
| commit | 0cb0ae82b752fa39732f42ac348dd34ffeef2052 (patch) | |
| tree | ae5fdc99d62d2f95bf260c5e8caf415653e81eec /po/xml2po.py | |
| parent | 8da0699500e3ef63875fa4af6d8d5c5248e99704 (diff) | |
| download | enigma2-0cb0ae82b752fa39732f42ac348dd34ffeef2052.tar.gz enigma2-0cb0ae82b752fa39732f42ac348dd34ffeef2052.zip | |
cleanup, handle XML comments including TRANSLATORS: comments
Diffstat (limited to 'po/xml2po.py')
| -rwxr-xr-x | po/xml2po.py | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/po/xml2po.py b/po/xml2po.py index a8b62666..3c6219ea 100755 --- a/po/xml2po.py +++ b/po/xml2po.py @@ -3,30 +3,34 @@ import sys import os import string from xml.sax import make_parser -from xml.sax.handler import ContentHandler +from xml.sax.handler import ContentHandler, property_lexical_handler +from _xmlplus.sax.saxlib import LexicalHandler -class parseXML(ContentHandler): +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" - if (attrs.has_key('value')): - attrlist[attrs.get('value', "")] = "foo" - if (attrs.has_key('caption')): - attrlist[attrs.get('caption', "")] = "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) - +parser.setProperty(property_lexical_handler, contentHandler) dir = os.listdir(sys.argv[1]) for x in dir: if (str(x[-4:]) == ".xml"): @@ -34,10 +38,16 @@ 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] string.replace(k, "\\n", "\"\n\"") + if c: + for l in c.split('\n'): + print "#. ", l print 'msgid "' + str(k) + '"' print 'msgstr ""' |
