2009-08-29 21:28:46 -04:00
|
|
|
import xml.dom.minidom
|
|
|
|
import sys
|
2011-03-30 13:12:29 -04:00
|
|
|
import codecs
|
2009-08-29 21:28:46 -04:00
|
|
|
|
|
|
|
f = open('./data/po/gui_strings.h', 'w')
|
2011-03-30 13:12:29 -04:00
|
|
|
f.write( codecs.BOM_UTF8 )
|
2009-08-29 21:28:46 -04:00
|
|
|
|
2014-12-27 16:50:03 -05:00
|
|
|
def traverse(file, node, isChallenge, isGP, isKart, isTrack, isAchievements, 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")
|
2012-09-19 20:05:38 -04:00
|
|
|
|
|
|
|
if e.localName == "subtitle" and e.hasAttribute("text") and len(e.getAttribute("text")) > 0:
|
|
|
|
#print "Label=", e.getAttribute("name"), " Comment=", comment
|
|
|
|
line = ""
|
|
|
|
if comment == None:
|
|
|
|
line += "//I18N: Cutscene subtitle from " + file + "\n_(\"" + e.getAttribute("text") + "\")\n\n"
|
|
|
|
else:
|
|
|
|
line += "//I18N: Cutscene subtitle from " + file + "\n//I18N: " + comment + "\n_(\"" + e.getAttribute("text") + "\");\n\n"
|
|
|
|
|
|
|
|
f.write( line.encode( "utf-8" ) )
|
|
|
|
|
2014-12-27 16:50:03 -05:00
|
|
|
if isChallenge or isGP or isKart or isTrack or isAchievements:
|
2012-10-27 18:34:06 -04:00
|
|
|
if isTrack and e.hasAttribute("internal") and e.getAttribute("internal") == "Y": continue
|
2011-03-30 13:16:58 -04:00
|
|
|
if e.hasAttribute("name") and len(e.getAttribute("name")) > 0:
|
2011-01-23 19:11:56 -05:00
|
|
|
#print "Label=", e.getAttribute("name"), " Comment=", comment
|
2009-12-22 16:57:15 -05:00
|
|
|
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
|
|
|
|
2011-03-30 13:12:29 -04:00
|
|
|
f.write( line.encode( "utf-8" ) )
|
2010-09-01 12:01:19 -04:00
|
|
|
|
|
|
|
# challenges and GPs can have a description file; karts don't
|
2011-03-30 13:16:58 -04:00
|
|
|
if e.hasAttribute("description") and len(e.getAttribute("description")) > 0:
|
2009-12-22 16:57:15 -05:00
|
|
|
# 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
|
|
|
|
2011-03-30 13:12:29 -04:00
|
|
|
f.write( line.encode( "utf-8" ) )
|
2009-12-22 16:57:15 -05:00
|
|
|
else:
|
2011-03-30 13:16:58 -04:00
|
|
|
if e.hasAttribute("text") and len(e.getAttribute("text")) > 0:
|
2009-12-22 16:57:15 -05:00
|
|
|
# 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
|
|
|
|
2011-03-30 13:12:29 -04:00
|
|
|
f.write( line.encode( "utf-8" ) )
|
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:
|
2014-12-27 16:50:03 -05:00
|
|
|
traverse(file, e, isChallenge, isGP, isKart, isTrack, isAchievements, 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
|
2011-01-23 19:11:56 -05:00
|
|
|
isTrack = False
|
2014-12-27 16:50:03 -05:00
|
|
|
isAchievements = 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
|
2011-01-23 19:11:56 -05:00
|
|
|
if file.endswith("track.xml"):
|
|
|
|
isTrack = True
|
2014-12-27 16:50:03 -05:00
|
|
|
if file.endswith("achievements.xml"):
|
|
|
|
isAchievements = 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 "============================================"
|
|
|
|
|
2014-12-27 16:50:03 -05:00
|
|
|
traverse(file, doc, isChallenge, isGP, isKart, isTrack, isAchievements)
|
2009-08-29 21:28:46 -04:00
|
|
|
|