<html>
<head>
<style type="text/css">
body,p,td,div,span{
font-size:14px;font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; color: #212121;
};
body p{
margin:0px;
}
</style>
</head>
<body><div>Did you do the procedure with the .pro file / lupdate / pylupdate5 / QLinguist and lrelease? I use only .tr() not .translate()<br></div><div><br></div><div><br></div><div><br></div>Am Donnerstag, den 21.03.2019 um 09:32 schrieb Zdenko Podobny:<br><blockquote style="border:0;border-left: 2px solid #22437f; padding:0px; margin:0px; padding-left:5px; margin-left: 5px; "><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hello,</div><div><br></div><div>I am not sure what I am doing wrong, but translation is not working for my QSystemTrayIcon app. Here is my testing code:</div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:Consolas"><span style="color:rgb(204,120,50)">import </span>sys<br><span style="color:rgb(204,120,50)">from </span>PyQt5 <span style="color:rgb(204,120,50)">import </span>QtCore<span style="color:rgb(204,120,50)">, </span>QtGui<span style="color:rgb(204,120,50)">, </span>QtWidgets<br><br><br><span style="color:rgb(204,120,50)">class </span>SystemTrayIcon(QtWidgets.QSystemTrayIcon):<br><br> <span style="color:rgb(204,120,50)">def </span><span style="color:rgb(178,0,178)">__init__</span>(<span style="color:rgb(148,85,141)">self</span><span style="color:rgb(204,120,50)">, </span>icon<span style="color:rgb(204,120,50)">, </span>parent=<span style="color:rgb(204,120,50)">None</span>):<br> QtWidgets.QSystemTrayIcon.<span style="color:rgb(178,0,178)">__init__</span>(<span style="color:rgb(148,85,141)">self</span><span style="color:rgb(204,120,50)">, </span>icon<span style="color:rgb(204,120,50)">, </span>parent)<br> <span style="color:rgb(148,85,141)">self</span>.menu = QtWidgets.QMenu(parent)<br> settingsAction = <span style="color:rgb(148,85,141)">self</span>.menu.addAction(<span style="color:rgb(148,85,141)">self</span>.tr(<span style="color:rgb(106,135,89)">"Settings..."</span>))<br> settingsAction.triggered.connect(<span style="color:rgb(148,85,141)">self</span>.settings)<br> exitAction = <span style="color:rgb(148,85,141)">self</span>.menu.addAction(<span style="color:rgb(148,85,141)">self</span>.tr(<span style="color:rgb(106,135,89)">"Exit"</span>))<br> exitAction.triggered.connect(<span style="color:rgb(148,85,141)">self</span>.exit)<br> <span style="color:rgb(148,85,141)">self</span>.setContextMenu(<span style="color:rgb(148,85,141)">self</span>.menu)<br><br> <span style="color:rgb(204,120,50)">def </span><span style="color:rgb(255,198,109)">exit</span>(<span style="color:rgb(148,85,141)">self</span>):<br> QtCore.QCoreApplication.exit()<br> <span style="color:rgb(136,136,198)">print</span>(<span style="color:rgb(106,135,89)">"Finished!"</span>)<br><br> <span style="color:rgb(204,120,50)">def </span><span style="color:rgb(255,198,109)">settings</span>(<span style="color:rgb(148,85,141)">self</span>):<br> <span style="color:rgb(136,136,198)">print</span>(<span style="color:rgb(106,135,89)">"Not implemented yet..."</span>)<br><br><br>app = QtWidgets.QApplication(sys.argv)<br>widget = QtWidgets.QWidget()<br>trayIcon = SystemTrayIcon(QtGui.QIcon(<span style="color:rgb(106,135,89)">'logo.ico'</span>)<span style="color:rgb(204,120,50)">, </span>widget)<br>qtTranslator = QtCore.QTranslator()<br>appTranslator = QtCore.QTranslator(app)<br>loaded = appTranslator.load(<span style="color:rgb(106,135,89)">'sk_SK.qm'</span>)<br><span style="color:rgb(136,136,198)">print</span>(<span style="color:rgb(106,135,89)">"Translation loaded:"</span><span style="color:rgb(204,120,50)">, </span>loaded)<br><span style="color:rgb(204,120,50)">if </span>loaded: <span style="color:rgb(128,128,128)"># test translating:<br></span><span style="color:rgb(128,128,128)"> </span>_translate = appTranslator.translate<br> <span style="color:rgb(136,136,198)">print</span>(<span style="color:rgb(106,135,89)">"should NOT be 'Settings...': " </span>+<br> _translate(<span style="color:rgb(106,135,89)">"SystemTrayIcon"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"Settings..."</span>))<br>trayIcon.show()<br>sys.exit(app.exec_())</pre></div><div><br></div><div>Output in terminal is:</div><div><div>Translation loaded: True</div><div>should NOT be 'Settings...': Nastavenia…</div></div><div><br></div><div>So translation was loaded correctly and it is working... But when I invoke context menu on systray icon - menu is in English:</div><div><div><img src="cid:68bf8770a8219ca0875e1c083c22bc20@pmeoffice.de" alt="image.png" width="133" height="59"><br></div></div><div><br></div><div>How to fix it? <br></div><div>I am using PyQt5 5.11.3, Python 3.6.6 64bit on Windows 10.</div><div><br></div><div><div dir="ltr" class="gmail_signature">Zdenko</div></div></div></div></div></div></div></div>
</blockquote></body></html>