fix the crash when providing invalid locale in env

This commit is contained in:
tzutalin
2018-12-28 10:07:59 -08:00
parent 40b30f1cee
commit d27e6a5dfa
2 changed files with 19 additions and 2 deletions
+8 -2
View File
@@ -15,7 +15,6 @@ except ImportError:
sip.setapi('QVariant', 2)
from PyQt4.QtCore import *
DEFAULT_LOCALE = locale.getlocale()[0] if locale.getlocale() and len(locale.getlocale()) > 0 else os.getenv('LANG')
class StringBundle:
@@ -29,7 +28,14 @@ class StringBundle:
self.__loadBundle(path)
@classmethod
def getBundle(cls, localeStr=DEFAULT_LOCALE):
def getBundle(cls, localeStr=None):
if localeStr is None:
try:
localeStr = locale.getlocale()[0] if locale.getlocale() and len(
locale.getlocale()) > 0 else os.getenv('LANG')
except:
print('Invalid locale')
locale = 'en'
return StringBundle(cls.__create_key, localeStr)
def getString(self, stringId):