Fix empty locale on windows platform
This commit is contained in:
parent
6db1dd500d
commit
255afca1b3
@ -4,7 +4,9 @@ import re
|
|||||||
import resources
|
import resources
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import locale
|
||||||
from libs.ustr import ustr
|
from libs.ustr import ustr
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PyQt5.QtCore import *
|
from PyQt5.QtCore import *
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -13,6 +15,7 @@ except ImportError:
|
|||||||
sip.setapi('QVariant', 2)
|
sip.setapi('QVariant', 2)
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
|
|
||||||
|
DEFAULT_LOCALE = locale.getlocale()[0] if locale.getlocale() and len(locale.getlocale()) > 0 else os.getenv('LANG')
|
||||||
|
|
||||||
class StringBundle:
|
class StringBundle:
|
||||||
|
|
||||||
@ -26,7 +29,7 @@ class StringBundle:
|
|||||||
self.__loadBundle(path)
|
self.__loadBundle(path)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getBundle(cls, localeStr=os.getenv('LANG')):
|
def getBundle(cls, localeStr=DEFAULT_LOCALE):
|
||||||
return StringBundle(cls.__create_key, localeStr)
|
return StringBundle(cls.__create_key, localeStr)
|
||||||
|
|
||||||
def getString(self, stringId):
|
def getString(self, stringId):
|
||||||
@ -37,11 +40,12 @@ class StringBundle:
|
|||||||
resultPaths = []
|
resultPaths = []
|
||||||
basePath = ":/strings"
|
basePath = ":/strings"
|
||||||
resultPaths.append(basePath)
|
resultPaths.append(basePath)
|
||||||
# Don't follow standard BCP47. Simple fallback
|
if localeStr is not None:
|
||||||
tags = re.split('[^a-zA-Z]', localeStr)
|
# Don't follow standard BCP47. Simple fallback
|
||||||
for tag in tags:
|
tags = re.split('[^a-zA-Z]', localeStr)
|
||||||
lastPath = resultPaths[-1]
|
for tag in tags:
|
||||||
resultPaths.append(lastPath + '-' + tag)
|
lastPath = resultPaths[-1]
|
||||||
|
resultPaths.append(lastPath + '-' + tag)
|
||||||
|
|
||||||
return resultPaths
|
return resultPaths
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user