[PyQt] Translation not working for QSystemTrayIcon
Zdenko Podobny
zdenop at gmail.com
Thu Mar 21 11:16:23 GMT 2019
I do not use .pro file - I run it manually:
pylupdate5 scratch_1.py -ts sk_SK.ts
linguist sk_SK.ts
lrelease sk_SK.ts
QTranslator.translate()
<https://doc.qt.io/qt-5/qtranslator.html#translate> returns
the translation for the key (context, sourceText, disambiguation). In my
example above it is not replaceable with QObject.tr()
<https://doc.qt.io/qt-5/qobject.html#tr>
Zdenko
št 21. 3. 2019 o 9:44 Hans Jörg Maurer <hjm at pmeonline.net> napísal(a):
> 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: 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/b5cd4f6a/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/b5cd4f6a/attachment-0001.png>
More information about the PyQt
mailing list