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.
This commit is contained in:
Peter Šurda 2016-03-24 13:33:03 +01:00
parent ecfa18b1c6
commit 412e175f27
4 changed files with 24 additions and 2 deletions

View File

@ -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))

View File

@ -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)

View File

@ -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)

View File

@ -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())