Skip to content

Commit

Permalink
Fix empty locale on windows platform
Browse files Browse the repository at this point in the history
  • Loading branch information
tzutalin committed Dec 3, 2018
1 parent 6db1dd5 commit 255afca
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions libs/stringBundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import resources
import os
import sys
import locale
from libs.ustr import ustr

try:
from PyQt5.QtCore import *
except ImportError:
Expand All @@ -13,6 +15,7 @@
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:

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

@classmethod
def getBundle(cls, localeStr=os.getenv('LANG')):
def getBundle(cls, localeStr=DEFAULT_LOCALE):
return StringBundle(cls.__create_key, localeStr)

def getString(self, stringId):
Expand All @@ -37,11 +40,12 @@ def __createLookupFallbackList(self, localeStr):
resultPaths = []
basePath = ":/strings"
resultPaths.append(basePath)
# Don't follow standard BCP47. Simple fallback
tags = re.split('[^a-zA-Z]', localeStr)
for tag in tags:
lastPath = resultPaths[-1]
resultPaths.append(lastPath + '-' + tag)
if localeStr is not None:
# Don't follow standard BCP47. Simple fallback
tags = re.split('[^a-zA-Z]', localeStr)
for tag in tags:
lastPath = resultPaths[-1]
resultPaths.append(lastPath + '-' + tag)

return resultPaths

Expand Down

0 comments on commit 255afca

Please sign in to comment.