[PyQt] Translation not working for QSystemTrayIcon

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


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..."))
        exitAction = self.menu.addAction(self.tr("Exit"))

    def exit(self):

    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..."))

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.

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