From 412e175f27cb7a9bc7f9161fb2b1515188c05c0d Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 24 Mar 2016 13:33:03 +0100 Subject: [PATCH] Translation updates Added a RetranslateMixin. Since PyQT does not support automated language changes of UI files (like the C++ QT does), this implements something similar. It assumes that the UI file has the same name as the class, but lowercase. Added RetraslateMixin to the new blacklist and networkstatus interfaces. --- src/bitmessageqt/bitmessageui.py | 2 ++ src/bitmessageqt/blacklist.py | 3 ++- src/bitmessageqt/networkstatus.py | 3 ++- src/bitmessageqt/retranslateui.py | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/bitmessageqt/retranslateui.py diff --git a/src/bitmessageqt/bitmessageui.py b/src/bitmessageqt/bitmessageui.py index b8547c22..5a8ae31f 100644 --- a/src/bitmessageqt/bitmessageui.py +++ b/src/bitmessageqt/bitmessageui.py @@ -726,6 +726,8 @@ class Ui_MainWindow(object): item.setText(_translate("MainWindow", "Received", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.chans), _translate("MainWindow", "Chans", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.networkstatus), _translate("MainWindow", "Network Status", None)) + self.blackwhitelist.retranslateUi() + self.networkstatus.retranslateUi() self.menuFile.setTitle(_translate("MainWindow", "File", None)) self.menuSettings.setTitle(_translate("MainWindow", "Settings", None)) self.menuHelp.setTitle(_translate("MainWindow", "Help", None)) diff --git a/src/bitmessageqt/blacklist.py b/src/bitmessageqt/blacklist.py index 11fdb201..1e4be35a 100644 --- a/src/bitmessageqt/blacklist.py +++ b/src/bitmessageqt/blacklist.py @@ -7,11 +7,12 @@ import widgets from addresses import addBMIfNotPresent from dialogs import AddAddressDialog from helper_sql import sqlExecute, sqlQuery +from retranslateui import RetranslateMixin from utils import avatarize from uisignaler import UISignaler -class Blacklist(QtGui.QWidget): +class Blacklist(QtGui.QWidget, RetranslateMixin): def __init__(self, parent=None): super(Blacklist, self).__init__(parent) widgets.load('blacklist.ui', self) diff --git a/src/bitmessageqt/networkstatus.py b/src/bitmessageqt/networkstatus.py index b51714d6..574af66b 100644 --- a/src/bitmessageqt/networkstatus.py +++ b/src/bitmessageqt/networkstatus.py @@ -2,11 +2,12 @@ from PyQt4 import QtCore, QtGui import shared from tr import _translate import l10n +from retranslateui import RetranslateMixin from uisignaler import UISignaler import widgets -class NetworkStatus(QtGui.QWidget): +class NetworkStatus(QtGui.QWidget, RetranslateMixin): def __init__(self, parent=None): super(NetworkStatus, self).__init__(parent) widgets.load('networkstatus.ui', self) diff --git a/src/bitmessageqt/retranslateui.py b/src/bitmessageqt/retranslateui.py new file mode 100644 index 00000000..e9d5bb3a --- /dev/null +++ b/src/bitmessageqt/retranslateui.py @@ -0,0 +1,18 @@ +from os import path +from PyQt4 import QtGui +from debug import logger +import widgets + +class RetranslateMixin(object): + def retranslateUi(self): + defaults = QtGui.QWidget() + widgets.load(self.__class__.__name__.lower() + '.ui', defaults) + for attr, value in defaults.__dict__.iteritems(): + setTextMethod = getattr(value, "setText", None) + if callable(setTextMethod): + getattr(self, attr).setText(getattr(defaults, attr).text()) + elif isinstance(value, QtGui.QTableWidget): + for i in range (value.columnCount()): + getattr(self, attr).horizontalHeaderItem(i).setText(getattr(defaults, attr).horizontalHeaderItem(i).text()) + for i in range (value.rowCount()): + getattr(self, attr).verticalHeaderItem(i).setText(getattr(defaults, attr).verticalHeaderItem(i).text())