Locale encoding fixes

On non-Windows, setlocale will try both normalised and preferred
encoding.
This commit is contained in:
Peter Šurda 2016-05-24 08:44:07 +02:00
parent 6dff105a5b
commit e353af3195
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -105,14 +105,18 @@ def change_translation(locale):
QtGui.QApplication.installTranslator(qsystranslator)
lang = pythonlocale.normalize(l10n.getTranslationLanguage())
langs = [lang.split(".")[0] + "." + l10n.encoding, lang]
if 'win32' in sys.platform or 'win64' in sys.platform:
lang = l10n.getWindowsLocale(lang)
langs = [l10n.getWindowsLocale(lang)]
for lang in langs:
try:
pythonlocale.setlocale(pythonlocale.LC_ALL, lang)
if 'win32' not in sys.platform and 'win64' not in sys.platform:
l10n.encoding = pythonlocale.nl_langinfo(pythonlocale.CODESET)
else:
l10n.encoding = pythonlocale.getlocale()[1]
logger.info("Successfully set locale to %s", lang)
break
except:
logger.error("Failed to set locale to %s", lang, exc_info=True)