2009-08-29 21:28:46 -04:00
|
|
|
import xml.dom.minidom
|
|
|
|
import sys
|
|
|
|
|
|
|
|
f = open('./data/po/gui_strings.h', 'w')
|
|
|
|
|
2010-09-01 12:01:19 -04:00
|
|
|
def traverse(file, node, isChallenge, isGP, isKart, level=0):
|
2009-08-29 21:28:46 -04:00
|
|
|
|
|
|
|
for e in node.childNodes:
|
|
|
|
if e.localName == None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
#print ' '*level, e.localName
|
|
|
|
|
|
|
|
comment = None
|
|
|
|
if e.hasAttribute("I18N"):
|
|
|
|
comment = e.getAttribute("I18N")
|
2009-12-22 16:57:15 -05:00
|
|
|
|
2010-09-01 12:01:19 -04:00
|
|
|
if isChallenge or isGP or isKart:
|
2009-12-22 16:57:15 -05:00
|
|
|
if e.hasAttribute("name"):
|
|
|
|
# print "Label=", e.getAttribute("name"), " Comment=", comment
|
|
|
|
line = ""
|
|
|
|
if comment == None:
|
2010-01-07 18:22:45 -05:00
|
|
|
line += "//I18N: " + file + "\n_(\"" + e.getAttribute("name") + "\")\n\n"
|
2009-12-22 16:57:15 -05:00
|
|
|
else:
|
2010-01-07 18:22:45 -05:00
|
|
|
line += "//I18N: File : " + file + "\n//I18N: " + comment + "\n_(\"" + e.getAttribute("name") + "\");\n\n"
|
2009-12-22 16:57:15 -05:00
|
|
|
|
|
|
|
f.write( line )
|
2010-09-01 12:01:19 -04:00
|
|
|
|
|
|
|
# challenges and GPs can have a description file; karts don't
|
2009-12-22 16:57:15 -05:00
|
|
|
if e.hasAttribute("description"):
|
|
|
|
# print "Label=", e.getAttribute("description"), " Comment=", comment
|
|
|
|
line = ""
|
|
|
|
if comment == None:
|
2010-01-07 18:22:45 -05:00
|
|
|
line += "//I18N: " + file + "\n_(\"" + e.getAttribute("description") + "\")\n\n"
|
2009-12-22 16:57:15 -05:00
|
|
|
else:
|
2010-01-07 18:22:45 -05:00
|
|
|
line += "//I18N: File : " + file + "\n//I18N: " + comment + "\n_(\"" + e.getAttribute("description") + "\");\n\n"
|
2009-12-22 16:57:15 -05:00
|
|
|
|
|
|
|
f.write( line )
|
|
|
|
else:
|
|
|
|
if e.hasAttribute("text"):
|
|
|
|
# print "Label=", e.getAttribute("text"), " Comment=", comment
|
|
|
|
line = ""
|
|
|
|
if comment == None:
|
2010-01-07 18:22:45 -05:00
|
|
|
line += "//I18N: " + file + "\n_(\"" + e.getAttribute("text") + "\")\n\n"
|
2009-12-22 16:57:15 -05:00
|
|
|
else:
|
2010-01-07 18:22:45 -05:00
|
|
|
line += "//I18N: " + file + "\n//I18N: " + comment + "\n_(\"" + e.getAttribute("text") + "\");\n\n"
|
2009-12-22 16:57:15 -05:00
|
|
|
|
|
|
|
f.write( line )
|
2009-08-29 21:28:46 -04:00
|
|
|
|
2010-09-01 12:01:19 -04:00
|
|
|
# don't recurse in children nodes for karts, they can contain sounds, etc. that should not be translated
|
|
|
|
if not isKart:
|
|
|
|
traverse(file, e, isChallenge, isGP, isKart, level+1)
|
2009-08-29 21:28:46 -04:00
|
|
|
|
|
|
|
filenames = sys.argv[1:]
|
|
|
|
for file in filenames:
|
2010-02-15 19:33:41 -05:00
|
|
|
#print "Parsing", file
|
2009-12-22 16:57:15 -05:00
|
|
|
|
|
|
|
isChallenge = False
|
2010-02-15 19:33:41 -05:00
|
|
|
isGP = False
|
2010-09-01 12:01:19 -04:00
|
|
|
isKart = False
|
2010-02-15 19:33:41 -05:00
|
|
|
|
2009-12-22 16:57:15 -05:00
|
|
|
if file.endswith(".challenge"):
|
|
|
|
isChallenge = True
|
2010-02-15 19:33:41 -05:00
|
|
|
if file.endswith(".grandprix"):
|
|
|
|
isGP = True
|
2010-09-01 12:01:19 -04:00
|
|
|
if file.endswith("kart.xml"):
|
|
|
|
isKart = True
|
2009-12-22 16:57:15 -05:00
|
|
|
|
2010-02-15 19:33:41 -05:00
|
|
|
try:
|
|
|
|
doc = xml.dom.minidom.parse(file)
|
2010-09-01 12:01:19 -04:00
|
|
|
except Exception as ex:
|
2010-02-15 19:33:41 -05:00
|
|
|
print "============================================"
|
2010-09-01 12:01:19 -04:00
|
|
|
print "/!\\ Expat doesn't like ", file, "! Error=", type(ex), " (", ex.args, ")"
|
2010-02-15 19:33:41 -05:00
|
|
|
print "============================================"
|
|
|
|
|
2010-09-01 12:01:19 -04:00
|
|
|
traverse(file, doc, isChallenge, isGP, isKart)
|
2009-08-29 21:28:46 -04:00
|
|
|
|