From b9a80c14c44b6e58251f10be778aafd60540e546 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 13 Mar 2015 17:02:14 +0200 Subject: [PATCH] Start work on language support --- otp/otpbase/OTPLocalizer.py | 32 ++++++++++------------------ toontown/golf/DistributedGolfHole.py | 10 ++++----- toontown/toonbase/ClientStart.py | 4 +++- toontown/toonbase/TTLocalizer.py | 29 ++++++++++--------------- 4 files changed, 30 insertions(+), 45 deletions(-) diff --git a/otp/otpbase/OTPLocalizer.py b/otp/otpbase/OTPLocalizer.py index bee62791..3e20d68e 100644 --- a/otp/otpbase/OTPLocalizer.py +++ b/otp/otpbase/OTPLocalizer.py @@ -1,45 +1,35 @@ -from panda3d.core import * import string import types + try: - language = getConfigExpress().GetString('language', 'english') - checkLanguage = getConfigExpress().GetBool('check-language', 0) + language = settings['language'] except: - language = simbase.config.GetString('language', 'english') - checkLanguage = simbase.config.GetBool('check-language', 0) - -def getLanguage(): - return language - + language = 'English' print 'OTPLocalizer: Running in language: %s' % language -if language == 'english': - _languageModule = 'otp.otpbase.OTPLocalizer' + language.capitalize() -else: - checkLanguage = 1 - _languageModule = 'otp.otpbase.OTPLocalizer_' + language -print 'from ' + _languageModule + ' import *' from otp.otpbase.OTPLocalizerEnglish import * -if checkLanguage: + +if language != 'English': l = {} g = {} + module = 'otp.optbase.OTPLocalizer' + language englishModule = __import__('otp.otpbase.OTPLocalizerEnglish', g, l) - foreignModule = __import__(_languageModule, g, l) + foreignModule = __import__(module, g, l) for key, val in englishModule.__dict__.items(): if key not in foreignModule.__dict__: - print 'WARNING: Foreign module: %s missing key: %s' % (_languageModule, key) + print 'WARNING: Foreign module: %s missing key: %s' % (module, key) locals()[key] = val elif isinstance(val, types.DictType): fval = foreignModule.__dict__.get(key) for dkey, dval in val.items(): if dkey not in fval: - print 'WARNING: Foreign module: %s missing key: %s.%s' % (_languageModule, key, dkey) + print 'WARNING: Foreign module: %s missing key: %s.%s' % (module, key, dkey) fval[dkey] = dval for dkey in fval.keys(): if dkey not in val: - print 'WARNING: Foreign module: %s extra key: %s.%s' % (_languageModule, key, dkey) + print 'WARNING: Foreign module: %s extra key: %s.%s' % (module, key, dkey) for key in foreignModule.__dict__.keys(): if key not in englishModule.__dict__: - print 'WARNING: Foreign module: %s extra key: %s' % (_languageModule, key) + print 'WARNING: Foreign module: %s extra key: %s' % (module, key) diff --git a/toontown/golf/DistributedGolfHole.py b/toontown/golf/DistributedGolfHole.py index 0b98a83f..64070363 100644 --- a/toontown/golf/DistributedGolfHole.py +++ b/toontown/golf/DistributedGolfHole.py @@ -104,11 +104,11 @@ class DistributedGolfHole(DistributedPhysicsWorld.DistributedPhysicsWorld, FSM, self.__textGen = TextNode('golfHoleText') self.__textGen.setFont(ToontownGlobals.getSignFont()) self.__textGen.setAlign(TextNode.ACenter) - if TTLocalizer.getLanguage() in ['castillian', - 'japanese', - 'german', - 'portuguese', - 'french']: + if TTLocalizer.getLanguage() in ['Castillian', + 'Japanese', + 'German', + 'Portuguese', + 'French']: self.__textGen.setGlyphScale(0.7) self.avIdList = [] self.enterAimStart = 0 diff --git a/toontown/toonbase/ClientStart.py b/toontown/toonbase/ClientStart.py index 19da21eb..95c2af36 100644 --- a/toontown/toonbase/ClientStart.py +++ b/toontown/toonbase/ClientStart.py @@ -72,6 +72,8 @@ if 'loadDisplay' not in settings: settings['loadDisplay'] = 'pandagl' if 'toonChatSounds' not in settings: settings['toonChatSounds'] = True +if 'language' not in settings: + settings['language'] = 'English' loadPrcFileData('Settings: res', 'win-size %d %d' % tuple(settings.get('res', (800, 600)))) loadPrcFileData('Settings: fullscreen', 'fullscreen %s' % settings['fullscreen']) loadPrcFileData('Settings: music', 'audio-music-active %s' % settings['music']) @@ -80,7 +82,7 @@ loadPrcFileData('Settings: musicVol', 'audio-master-music-volume %s' % settings[ loadPrcFileData('Settings: sfxVol', 'audio-master-sfx-volume %s' % settings['sfxVol']) loadPrcFileData('Settings: loadDisplay', 'load-display %s' % settings['loadDisplay']) loadPrcFileData('Settings: toonChatSounds', 'toon-chat-sounds %s' % settings['toonChatSounds']) - +loadPrcFileData('Settings: language', 'language %s' % settings['language']) import os diff --git a/toontown/toonbase/TTLocalizer.py b/toontown/toonbase/TTLocalizer.py index 48ab0b98..1798f6e2 100644 --- a/toontown/toonbase/TTLocalizer.py +++ b/toontown/toonbase/TTLocalizer.py @@ -1,45 +1,38 @@ -from panda3d.core import * import string import types + try: - language = getConfigExpress().GetString('language', 'english') - checkLanguage = getConfigExpress().GetBool('check-language', 0) + language = settings['language'] except: - language = simbase.config.GetString('language', 'english') - checkLanguage = simbase.config.GetBool('check-language', 0) + language = 'English' def getLanguage(): return language - print 'TTLocalizer: Running in language: %s' % language -if language == 'english': - _languageModule = 'toontown.toonbase.TTLocalizer' + language.capitalize() -else: - checkLanguage = 1 - _languageModule = 'toontown.toonbase.TTLocalizer_' + language -print 'from ' + _languageModule + ' import *' from toontown.toonbase.TTLocalizerEnglish import * -if checkLanguage: + +if language != 'English': l = {} g = {} + module = 'toontown.toonbase.TTLocalizer' + language englishModule = __import__('toontown.toonbase.TTLocalizerEnglish', g, l) - foreignModule = __import__(_languageModule, g, l) + foreignModule = __import__(module, g, l) for key, val in englishModule.__dict__.items(): if key not in foreignModule.__dict__: - print 'WARNING: Foreign module: %s missing key: %s' % (_languageModule, key) + print 'WARNING: Foreign module: %s missing key: %s' % (module, key) locals()[key] = val elif isinstance(val, types.DictType): fval = foreignModule.__dict__.get(key) for dkey, dval in val.items(): if dkey not in fval: - print 'WARNING: Foreign module: %s missing key: %s.%s' % (_languageModule, key, dkey) + print 'WARNING: Foreign module: %s missing key: %s.%s' % (module, key, dkey) fval[dkey] = dval for dkey in fval.keys(): if dkey not in val: - print 'WARNING: Foreign module: %s extra key: %s.%s' % (_languageModule, key, dkey) + print 'WARNING: Foreign module: %s extra key: %s.%s' % (module, key, dkey) for key in foreignModule.__dict__.keys(): if key not in englishModule.__dict__: - print 'WARNING: Foreign module: %s extra key: %s' % (_languageModule, key) + print 'WARNING: Foreign module: %s extra key: %s' % (module, key)