[PyQt] Translation not working for QSystemTrayIcon

Zdenko Podobny zdenop at gmail.com
Thu Mar 21 08:32:37 GMT 2019


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: 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/b8caeb84/attachment.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/b8caeb84/attachment.png>


More information about the PyQt mailing list