<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Further to Robert's reply, you need to change the file name in
both the qrc file and in main.cpp. <br>
</p>
<p>Regards, Tony<br>
</p>
<div class="moz-cite-prefix">On 27/04/2021 3:31 pm, Robert Hairgrove
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:a4fac66d-f5b4-e75e-5070-d21c33ce9c59@hispeed.ch">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>You need to load the ".qm" file which is the binary generated
by running lrelease, not the ".ts" file.</p>
<p>In addition to your "hello_la.qm" file, you might want to load
Qt's "qtbase_la.qm" file (if there is one) which contains
translations for most of the built-in GUI elements.</p>
<p>HTH, Bob<br>
</p>
<p>--<br>
</p>
<div class="moz-cite-prefix">On 27.04.21 07:06, Nicholas Yue
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CADYXiJL8UMaB0da9qFBz4Q24xh7YbFFeeA-acQ3XJtnx6VWnmQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html;
charset=UTF-8">
<div dir="ltr">Hi,
<div><br>
</div>
<div> I am trying to embed translation file as a resource but
when I run the compiled program, it fails to load the
translation</div>
<div><br>
</div>
<div>ERROR: Translation failure to load<br>
</div>
<div><br>
</div>
<div>main.cpp</div>
<div>***********</div>
<div>#include <QApplication><br>
#include <QPushButton><br>
#include <QTranslator><br>
#include <iostream><br>
<br>
int main(int argc, char *argv[])<br>
{<br>
QApplication app(argc, argv);<br>
QString appDir = QCoreApplication::applicationDirPath();<br>
QTranslator translator;<br>
QString translationDir = appDir + "/translation";<br>
// if (translator.load("hellotr_la",translationDir)) {<br>
if (translator.load(":/language/hellotr_la.ts")) {<br>
app.installTranslator(&translator);<br>
} else {<br>
std::cerr << "ERROR: Translation failure to load"
<< std::endl;<br>
}<br>
<br>
QPushButton hello(QPushButton::tr("Hello world!"));<br>
hello.resize(100, 30);<br>
<br>
hello.show();<br>
return app.exec();<br>
}<br>
</div>
<div><br>
</div>
<div>hellotr_lang.qrc<br>
</div>
<div>******************</div>
<div><!DOCTYPE RCC><RCC version="1.0"><br>
<qresource prefix="/language"><br>
<file>hellotr_la.ts</file><br>
</qresource><br>
</RCC><br>
</div>
<div><br>
</div>
<div>hellotr_la.ts</div>
<div>*************</div>
<div><?xml version="1.0" encoding="utf-8"?><br>
<!DOCTYPE TS><br>
<TS version="2.1" language="la_VA"><br>
<context><br>
<name>QPushButton</name><br>
<message><br>
<location filename="main.cpp" line="19"/><br>
<source>Hello world!</source><br>
<translation
type="unfinished"></translation><br>
</message><br>
</context><br>
</TS><br>
</div>
<div><br>
</div>
<div>hellotr,pro</div>
<div>************</div>
<div>SOURCES = main.cpp<br>
TRANSLATIONS = hellotr_la.ts<br>
<br>
target.path = $$[QT_INSTALL_EXAMPLES]/linguist/hellotr<br>
INSTALLS += target<br>
<br>
QT += widgets<br>
<br>
RESOURCES += hellotr_lang.qrc<br>
<br>
</div>
<div><br>
</div>
<div>Cheers<br>
-- <br>
<div dir="ltr" class="gmail_signature"
data-smartmail="gmail_signature">
<div dir="ltr">Nicholas Yue<br>
Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5<br>
Custom Dev - C++ porting, OSX, Linux, Windows<br>
<a href="http://au.linkedin.com/in/nicholasyue"
target="_blank" moz-do-not-send="true">http://au.linkedin.com/in/nicholasyue</a><br>
<a href="https://vimeo.com/channels/naiadtools"
target="_blank" moz-do-not-send="true">https://vimeo.com/channels/naiadtools</a><br>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Interest mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Interest@qt-project.org" moz-do-not-send="true">Interest@qt-project.org</a>
<a class="moz-txt-link-freetext" href="https://lists.qt-project.org/listinfo/interest" moz-do-not-send="true">https://lists.qt-project.org/listinfo/interest</a>
</pre>
</blockquote>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Interest mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Interest@qt-project.org">Interest@qt-project.org</a>
<a class="moz-txt-link-freetext" href="https://lists.qt-project.org/listinfo/interest">https://lists.qt-project.org/listinfo/interest</a>
</pre>
</blockquote>
</body>
</html>