Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 255afca

Browse files
committed
Fix empty locale on windows platform
1 parent 6db1dd5 commit 255afca

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

libs/stringBundle.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import resources
55
import os
66
import sys
7+
import locale
78
from libs.ustr import ustr
9+
810
try:
911
from PyQt5.QtCore import *
1012
except ImportError:
@@ -13,6 +15,7 @@
1315
sip.setapi('QVariant', 2)
1416
from PyQt4.QtCore import *
1517

18+
DEFAULT_LOCALE = locale.getlocale()[0] if locale.getlocale() and len(locale.getlocale()) > 0 else os.getenv('LANG')
1619

1720
class StringBundle:
1821

@@ -26,7 +29,7 @@ def __init__(self, create_key, localeStr):
2629
self.__loadBundle(path)
2730

2831
@classmethod
29-
def getBundle(cls, localeStr=os.getenv('LANG')):
32+
def getBundle(cls, localeStr=DEFAULT_LOCALE):
3033
return StringBundle(cls.__create_key, localeStr)
3134

3235
def getString(self, stringId):
@@ -37,11 +40,12 @@ def __createLookupFallbackList(self, localeStr):
3740
resultPaths = []
3841
basePath = ":/strings"
3942
resultPaths.append(basePath)
40-
# Don't follow standard BCP47. Simple fallback
41-
tags = re.split('[^a-zA-Z]', localeStr)
42-
for tag in tags:
43-
lastPath = resultPaths[-1]
44-
resultPaths.append(lastPath + '-' + tag)
43+
if localeStr is not None:
44+
# Don't follow standard BCP47. Simple fallback
45+
tags = re.split('[^a-zA-Z]', localeStr)
46+
for tag in tags:
47+
lastPath = resultPaths[-1]
48+
resultPaths.append(lastPath + '-' + tag)
4549

4650
return resultPaths
4751

0 commit comments

Comments
 (0)