wmlunits: Improved translation handling,

...and added option to specify po directory.
This commit is contained in:
Elias Pschernig 2008-04-18 13:54:00 +00:00
parent bc3db730ea
commit 6394e55824
3 changed files with 17 additions and 6 deletions

View File

@ -11,11 +11,11 @@ class ParserWithCoreMacros:
"""
A wrapper around the WML parser to do some things like we want.
"""
def __init__(self, isocode, datadir, userdir):
def __init__(self, isocode, datadir, userdir, transdir):
self.datadir = datadir
self.userdir = userdir
# Handle translations.
self.translations = wmltools.Translations()
self.translations = wmltools.Translations(transdir)
def gettext(textdomain, x):
return self.translations.get(textdomain, isocode, x, x)
self.gettext = gettext
@ -134,14 +134,14 @@ class WesnothList:
"""
Lists various Wesnoth stuff like units, campaigns, terrains, factions...
"""
def __init__(self, isocode, datadir, userdir):
def __init__(self, isocode, datadir, userdir, transdir):
self.unit_lookup = {}
self.race_lookup = {}
self.terrain_lookup = {}
self.movetype_lookup = {}
self.era_lookup = {}
self.campaign_lookup = {}
self.parser = ParserWithCoreMacros(isocode, datadir, userdir)
self.parser = ParserWithCoreMacros(isocode, datadir, userdir, transdir)
def add_terrains(self):
"""

View File

@ -633,7 +633,12 @@ class Translation(dict):
return key[key.find("^") + 1:]
return "?"
else:
return self.gettext.get(key, dflt)
t = self.gettext.get(key, dflt)
if not t:
if key:
return key[key.find("^") + 1:]
return "?"
return t
def __getitem__(self, key):
if self.isocode == "C":
return key

View File

@ -692,7 +692,7 @@ def output(isocode):
"""
print "WML parser language reset to %s." % isocode
stuff = helpers.WesnothList(isocode, datadir, userdir)
stuff = helpers.WesnothList(isocode, datadir, userdir, transdir)
# Parse some stuff we may need.
print "Parsing terrains ...",
@ -786,6 +786,8 @@ if __name__ == '__main__':
help = "Specify Wesnoth's data to use. Default is to search current directory upwards.")
op.add_option("-u", "--userdir",
help = "Specify user data dir to use, which is automatically scanned for addons. For example -u ~/.wesnoth/data")
op.add_option("-t", "--transdir",
help = "Specify directory which has a po subfolder for translations.")
options, args = op.parse_args()
if not options.output:
@ -801,6 +803,10 @@ if __name__ == '__main__':
datadir = options.datadir
userdir = options.userdir
if options.transdir:
transdir = options.transdir
else:
transdir = os.path.dirname(datadir)
if options.language == "all":
languages = find_languages().keys()