<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">I do not use .pro file - I run it manually:<div>pylupdate5 scratch_1.py -ts sk_SK.ts</div><div>linguist sk_SK.ts</div><div>lrelease sk_SK.ts<br><div><br></div><a href="https://doc.qt.io/qt-5/qtranslator.html#translate">QTranslator.translate()</a> returns the translation for the key (context, sourceText, disambiguation). In my example above it is not replaceable with <a href="https://doc.qt.io/qt-5/qobject.html#tr">QObject.tr()</a><div><br></div><div><br clear="all"><div><div dir="ltr" class="gmail_signature">Zdenko</div></div><br></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">št 21. 3. 2019 o 9:44 Hans Jörg Maurer <<a href="mailto:hjm@pmeonline.net">hjm@pmeonline.net</a>> napísal(a):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><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-width:0px 0px 0px 2px;border-top-style:initial;border-right-style:initial;border-bottom-style:initial;border-top-color:initial;border-right-color:initial;border-bottom-color:initial;border-left-style:solid;border-left-color:rgb(34,67,127);padding:0px 0px 0px 5px;margin:0px 0px 0px 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:1699fc92d0ccb971f161" 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-m_-2408667777685871904gmail_signature">Zdenko</div></div></div></div></div></div></div></div>
</blockquote></div>
</blockquote></div>