[PyQt] Translation not working for QSystemTrayIcon
Hans Jörg Maurer
hjm at pmeonline.net
Thu Mar 21 08:44:27 GMT 2019
Did you do the procedure with the .pro file / lupdate / pylupdate5
/ QLinguist and lrelease? I use only .tr() not .translate()
Am Donnerstag, den 21.03.2019 um 09:32 schrieb Zdenko Podobny:
Hello,
I am not sure what I am doing wrong, but translation is not working
for my QSystemTrayIcon app. Here is my testing code:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
def __init__(self, icon, parent=None):
QtWidgets.QSystemTrayIcon.__init__(self, icon, parent)
self.menu = QtWidgets.QMenu(parent)
settingsAction = self.menu.addAction(self.tr("Settings..."))
settingsAction.triggered.connect(self.settings)
exitAction = self.menu.addAction(self.tr("Exit"))
exitAction.triggered.connect(self.exit)
self.setContextMenu(self.menu)
def exit(self):
QtCore.QCoreApplication.exit()
print("Finished!")
def settings(self):
print("Not implemented yet...")
app = QtWidgets.QApplication(sys.argv)
widget = QtWidgets.QWidget()
trayIcon = SystemTrayIcon(QtGui.QIcon('logo.ico'), widget)
qtTranslator = QtCore.QTranslator()
appTranslator = QtCore.QTranslator(app)
loaded = appTranslator.load('sk_SK.qm')
print("Translation loaded:", loaded)
if loaded: # test translating:
_translate = appTranslator.translate
print("should NOT be 'Settings...': " +
_translate("SystemTrayIcon", "Settings..."))
trayIcon.show()
sys.exit(app.exec_())
Output in terminal is:
Translation loaded: True
should NOT be 'Settings...': Nastavenia…
So translation was loaded correctly and it is working... But when I
invoke context menu on systray icon - menu is in English:
image.png
How to fix it?
I am using PyQt5 5.11.3, Python 3.6.6 64bit on Windows 10.
Zdenko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190321/1f87f062/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 5368 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190321/1f87f062/attachment-0001.png>
More information about the PyQt
mailing list