From d8408048186c025520cd63d6ffe705f8d0316f44 Mon Sep 17 00:00:00 2001 From: Ilya Shalyapin Date: Wed, 19 Sep 2018 13:07:19 +0500 Subject: [PATCH 1/2] use system language by default --- electrum/gui/qt/__init__.py | 4 ++-- electrum/i18n.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py index 80adeaa99..4fdb1b52e 100644 --- a/electrum/gui/qt/__init__.py +++ b/electrum/gui/qt/__init__.py @@ -38,7 +38,7 @@ from PyQt5.QtWidgets import * from PyQt5.QtCore import * import PyQt5.QtCore as QtCore -from electrum.i18n import _, set_language +from electrum.i18n import _, set_language, get_default_language from electrum.plugin import run_hook from electrum.storage import WalletStorage from electrum.base_wizard import GoBack @@ -89,7 +89,7 @@ class QNetworkUpdatedSignalObject(QObject): class ElectrumGui(PrintError): def __init__(self, config, daemon, plugins): - set_language(config.get('language')) + set_language(config.get('language', get_default_language())) # Uncomment this call to verify objects are being properly # GC-ed when windows are closed #network.add_jobs([DebugMem([Abstract_Wallet, SPV, Synchronizer, diff --git a/electrum/i18n.py b/electrum/i18n.py index 9c6fad995..bb4a2da59 100644 --- a/electrum/i18n.py +++ b/electrum/i18n.py @@ -26,6 +26,8 @@ import os import gettext +from PyQt5.QtCore import QLocale + LOCALE_DIR = os.path.join(os.path.dirname(__file__), 'locale') language = gettext.translation('electrum', LOCALE_DIR, fallback=True) @@ -41,6 +43,11 @@ def set_language(x): language = gettext.translation('electrum', LOCALE_DIR, fallback=True, languages=[x]) +def get_default_language(): + system_locale = QLocale.system().name() + return languages.get(system_locale, 'en_UK') + + languages = { '': _('Default'), 'ar_SA': _('Arabic'), From 4c8103af3bd18bb7d2fee6fcc74706e4dcb06a90 Mon Sep 17 00:00:00 2001 From: Ilya Shalyapin Date: Sun, 23 Sep 2018 14:11:50 +0500 Subject: [PATCH 2/2] move get_default_language to gui.qt.util --- electrum/gui/qt/__init__.py | 2 +- electrum/gui/qt/util.py | 7 ++++++- electrum/i18n.py | 7 ------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py index 4fdb1b52e..7557f0ecf 100644 --- a/electrum/gui/qt/__init__.py +++ b/electrum/gui/qt/__init__.py @@ -38,7 +38,7 @@ from PyQt5.QtWidgets import * from PyQt5.QtCore import * import PyQt5.QtCore as QtCore -from electrum.i18n import _, set_language, get_default_language +from electrum.i18n import _, set_language from electrum.plugin import run_hook from electrum.storage import WalletStorage from electrum.base_wizard import GoBack diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py index 50ed0a5c3..804a99078 100644 --- a/electrum/gui/qt/util.py +++ b/electrum/gui/qt/util.py @@ -10,7 +10,7 @@ from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * -from electrum.i18n import _ +from electrum.i18n import _, languages from electrum.util import FileImportFailed, FileExportFailed from electrum.paymentrequest import PR_UNPAID, PR_PAID, PR_EXPIRED @@ -812,6 +812,11 @@ class IconCache: return self.__cache[file_name] +def get_default_language(): + name = QLocale.system().name() + return name if name in languages else 'en_UK' + + if __name__ == "__main__": app = QApplication([]) t = WaitingDialog(None, 'testing ...', lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done")) diff --git a/electrum/i18n.py b/electrum/i18n.py index bb4a2da59..9c6fad995 100644 --- a/electrum/i18n.py +++ b/electrum/i18n.py @@ -26,8 +26,6 @@ import os import gettext -from PyQt5.QtCore import QLocale - LOCALE_DIR = os.path.join(os.path.dirname(__file__), 'locale') language = gettext.translation('electrum', LOCALE_DIR, fallback=True) @@ -43,11 +41,6 @@ def set_language(x): language = gettext.translation('electrum', LOCALE_DIR, fallback=True, languages=[x]) -def get_default_language(): - system_locale = QLocale.system().name() - return languages.get(system_locale, 'en_UK') - - languages = { '': _('Default'), 'ar_SA': _('Arabic'),