From e353af3195f6ef6e83e42a0c95103f055cd01baa Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Tue, 24 May 2016 08:44:07 +0200 Subject: [PATCH] Locale encoding fixes On non-Windows, setlocale will try both normalised and preferred encoding. --- src/bitmessageqt/__init__.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 47ff6edf..c8566aec 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -105,16 +105,20 @@ 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) - 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] - except: - logger.error("Failed to set locale to %s", lang, exc_info=True) + 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) class MyForm(settingsmixin.SMainWindow):