From c29f266020027d1768ac3762fd75f0c5dcd311d8 Mon Sep 17 00:00:00 2001 From: mailchuck Date: Wed, 27 Apr 2016 09:48:53 +0200 Subject: [PATCH] Translation fixes - locale name is properly normalised rather than simply changing the string - translations now support plurals/paucals - networkstatus updated --- src/bitmessageqt/__init__.py | 16 +++++++--------- src/bitmessageqt/networkstatus.py | 17 ++++++++++------- src/tr.py | 11 +++++++---- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index cac530fc..ce28b5e8 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -71,8 +71,11 @@ from dialogs import AddAddressDialog from class_objectHashHolder import objectHashHolder from class_singleWorker import singleWorker -def _translate(context, text): - return QtGui.QApplication.translate(context, text) +def _translate(context, text, number = None): + if number is None: + return QtGui.QApplication.translate(context, text) + else: + return QtGui.QApplication.translate(context, text, None, QtCore.QCoreApplication.CodecForTr, number) def change_translation(locale): global qmytranslator, qsystranslator @@ -100,16 +103,11 @@ def change_translation(locale): qsystranslator.load(translationpath) QtGui.QApplication.installTranslator(qsystranslator) - lang = l10n.getTranslationLanguage() - if "_" not in lang: - lang += "_" + lang.upper() - if ".utf8" not in lang.lower(): - lang += ".utf8" + lang = pythonlocale.normalize(l10n.getTranslationLanguage()) try: pythonlocale.setlocale(pythonlocale.LC_ALL, lang) except: - logger.error("Failed to set locale to %s", lang) - pass + logger.error("Failed to set locale to %s", lang, exc_info=True) class MyForm(settingsmixin.SMainWindow): diff --git a/src/bitmessageqt/networkstatus.py b/src/bitmessageqt/networkstatus.py index e778e605..df6a3de5 100644 --- a/src/bitmessageqt/networkstatus.py +++ b/src/bitmessageqt/networkstatus.py @@ -35,7 +35,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin): QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.runEveryTwoSeconds) def formatBytes(self, num): - for x in [_translate("networkstatus", "byte(s)"), "kB", "MB", "GB"]: + for x in [_translate("networkstatus", "byte(s)", num), "kB", "MB", "GB"]: if num < 1000.0: return "%3.0f %s" % (num, x) num /= 1000.0 @@ -44,21 +44,24 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin): def formatByteRate(self, num): num /= 1000 return "%4.0f kB" % num + + def updateNumberOfObjectsToBeSynced(self): + self.labelSyncStatus.setText(_translate("networkstatus", "Object(s) to be synced: %n", sum(shared.numberOfObjectsThatWeHaveYetToGetPerPeer.itervalues()))) def updateNumberOfMessagesProcessed(self): - self.labelSyncStatus.setText(_translate("networkstatus", "Objects to be synced: %1").arg(str(sum(shared.numberOfObjectsThatWeHaveYetToGetPerPeer.itervalues())))) + self.updateNumberOfObjectsToBeSynced() self.labelMessageCount.setText(_translate( - "networkstatus", "Processed %1 person-to-person messages.").arg(str(shared.numberOfMessagesProcessed))) + "networkstatus", "Processed %n person-to-person message(s).", shared.numberOfMessagesProcessed)) def updateNumberOfBroadcastsProcessed(self): - self.labelSyncStatus.setText(_translate("networkstatus", "Objects to be synced: %1").arg(str(sum(shared.numberOfObjectsThatWeHaveYetToGetPerPeer.itervalues())))) + self.updateNumberOfObjectsToBeSynced() self.labelBroadcastCount.setText(_translate( - "networkstatus", "Processed %1 broadcast messages.").arg(str(shared.numberOfBroadcastsProcessed))) + "networkstatus", "Processed %n broadcast message(s).", shared.numberOfBroadcastsProcessed)) def updateNumberOfPubkeysProcessed(self): - self.labelSyncStatus.setText(_translate("networkstatus", "Objects to be synced: %1").arg(str(sum(shared.numberOfObjectsThatWeHaveYetToGetPerPeer.itervalues())))) + self.updateNumberOfObjectsToBeSynced() self.labelPubkeyCount.setText(_translate( - "networkstatus", "Processed %1 public keys.").arg(str(shared.numberOfPubkeysProcessed))) + "networkstatus", "Processed %n public key(s).", shared.numberOfPubkeysProcessed)) def updateNumberOfBytes(self): """ diff --git a/src/tr.py b/src/tr.py index c11d1f57..16ae2856 100644 --- a/src/tr.py +++ b/src/tr.py @@ -12,10 +12,10 @@ class translateClass: else: return self.text -def _translate(context, text): - return translateText(context, text) +def _translate(context, text, n = None): + return translateText(context, text, n) -def translateText(context, text): +def translateText(context, text, n = None): if not shared.safeConfigGetBoolean('bitmessagesettings', 'daemon'): try: from PyQt4 import QtCore, QtGui @@ -23,7 +23,10 @@ def translateText(context, text): print 'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon' print 'Error message:', err os._exit(0) - return QtGui.QApplication.translate(context, text) + if n is None: + return QtGui.QApplication.translate(context, text) + else: + return QtGui.QApplication.translate(context, text, None, QtCore.QCoreApplication.CodecForTr, n) else: if '%' in text: return translateClass(context, text.replace('%','',1))