<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Translate a single QString]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">how can i translate a single QString in an Qt Console application. I just can find examples with gui. But it doesnt work....<br />
I am working on an embedded linux systeem and some error messages have to be translated.<br />
for example (just an primitive example)</p>
<pre><code>#include "translate.h"
#include &lt;QCoreApplication&gt;
#include &lt;QDebug&gt;
#include &lt;QTranslator&gt;


Translate::Translate(QObject *parent) : QObject(parent)
{
    translate();
}

void Translate::translate()
{
    QString message = tr("Hello");

    QTranslator translator;
    translator.load("ConsoleTranslationExample_de_DE");
    qApp-&gt;installTranslator(&amp;translator);

    QTextStream o(stdout);
    o &lt;&lt; message;
}

</code></pre>
<p dir="auto">Can anybody please help me. Wasted yesterday the whole day to find a solution :-(</p>
]]></description><link>https://forum.qt.io/topic/130155/translate-a-single-qstring</link><generator>RSS for Node</generator><lastBuildDate>Wed, 12 Aug 2026 14:49:55 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/130155.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Sep 2021 07:27:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Translate a single QString on Thu, 09 Sep 2021 08:09:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eyllanesc">@<bdi>eyllanesc</bdi></a> Thank you. I got it. With the full path it works</p>
<pre><code>void Translate::translate()
{
    QTranslator translator;

    if(!translator.load(qApp-&gt;applicationDirPath() + "/ConsoleTranslationExample_de_DE.qm")){
        qDebug() &lt;&lt; "Cant find translation file";
        return;
    }
    qApp-&gt;installTranslator(&amp;translator);

    QString message = tr("Hello");
    QTextStream o(stdout);
    o &lt;&lt; message;

}

</code></pre>
]]></description><link>https://forum.qt.io/post/679871</link><guid isPermaLink="true">https://forum.qt.io/post/679871</guid><dc:creator><![CDATA[d.rein]]></dc:creator><pubDate>Thu, 09 Sep 2021 08:09:03 GMT</pubDate></item><item><title><![CDATA[Reply to Translate a single QString on Thu, 09 Sep 2021 07:57:51 GMT]]></title><description><![CDATA[<p dir="auto">@d-rein said in <a href="/post/679861">Translate a single QString</a>:</p>
<blockquote>
<p dir="auto">It is false. Mh creator cant fiond the translation file<br />
the ts file is located in the src folder of my project and the qm files are located inside the .qm dir of the build dir</p>
</blockquote>
<p dir="auto">so the qm file is inside a folder, and not on the same lvl as your executable ?</p>
<p dir="auto">you'll have to specify that to the load command</p>
]]></description><link>https://forum.qt.io/post/679864</link><guid isPermaLink="true">https://forum.qt.io/post/679864</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Thu, 09 Sep 2021 07:57:51 GMT</pubDate></item><item><title><![CDATA[Reply to Translate a single QString on Thu, 09 Sep 2021 07:54:16 GMT]]></title><description><![CDATA[<p dir="auto">@d-rein Just for testing use the fullpath:  <code>translator.load("/path/of/ConsoleTranslationExample_de_DE.qm");</code></p>
]]></description><link>https://forum.qt.io/post/679863</link><guid isPermaLink="true">https://forum.qt.io/post/679863</guid><dc:creator><![CDATA[eyllanesc]]></dc:creator><pubDate>Thu, 09 Sep 2021 07:54:16 GMT</pubDate></item><item><title><![CDATA[Reply to Translate a single QString on Thu, 09 Sep 2021 07:51:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eyllanesc">@<bdi>eyllanesc</bdi></a> said in <a href="/post/679858">Translate a single QString</a>:</p>
<blockquote>
<p dir="auto">qDebug() &lt;&lt; translator.load("ConsoleTranslationExample_de_DE");</p>
</blockquote>
<p dir="auto">It is false. Mh creator cant fiond the translation file<br />
the ts file is located in the src folder of my project and the qm files are located inside the .qm dir of the build dir</p>
]]></description><link>https://forum.qt.io/post/679861</link><guid isPermaLink="true">https://forum.qt.io/post/679861</guid><dc:creator><![CDATA[d.rein]]></dc:creator><pubDate>Thu, 09 Sep 2021 07:51:00 GMT</pubDate></item><item><title><![CDATA[Reply to Translate a single QString on Thu, 09 Sep 2021 07:41:31 GMT]]></title><description><![CDATA[<p dir="auto">@d-rein what is the output of  <code>qDebug() &lt;&lt; translator.load("ConsoleTranslationExample_de_DE");</code>?</p>
]]></description><link>https://forum.qt.io/post/679858</link><guid isPermaLink="true">https://forum.qt.io/post/679858</guid><dc:creator><![CDATA[eyllanesc]]></dc:creator><pubDate>Thu, 09 Sep 2021 07:41:31 GMT</pubDate></item><item><title><![CDATA[Reply to Translate a single QString on Thu, 09 Sep 2021 07:39:38 GMT]]></title><description><![CDATA[<p dir="auto">No, still doent work...</p>
<p dir="auto">TranslationFile:</p>
<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!DOCTYPE TS&gt;
&lt;TS version="2.1" language="de_DE"&gt;
&lt;context&gt;
    &lt;name&gt;Translate&lt;/name&gt;
    &lt;message&gt;
        &lt;source&gt;Hello&lt;/source&gt;
        &lt;translation&gt;Hallo&lt;/translation&gt;
    &lt;/message&gt;
&lt;/context&gt;
&lt;/TS&gt;
</code></pre>
<p dir="auto">cpp:</p>
<pre><code>void Translate::translate()
{
    QTranslator translator;
    translator.load("ConsoleTranslationExample_de_DE");
    qApp-&gt;installTranslator(&amp;translator);
    
    QString message = tr("Hello");
    QTextStream o(stdout);
    o &lt;&lt; message;
}

</code></pre>
<p dir="auto">Output:  Hello</p>
]]></description><link>https://forum.qt.io/post/679857</link><guid isPermaLink="true">https://forum.qt.io/post/679857</guid><dc:creator><![CDATA[d.rein]]></dc:creator><pubDate>Thu, 09 Sep 2021 07:39:38 GMT</pubDate></item><item><title><![CDATA[Reply to Translate a single QString on Thu, 09 Sep 2021 07:31:34 GMT]]></title><description><![CDATA[<p dir="auto">@d-rein move <code>QString message = tr("Hello");</code> after <code>qApp-&gt;installTranslator(&amp;translator);</code></p>
]]></description><link>https://forum.qt.io/post/679848</link><guid isPermaLink="true">https://forum.qt.io/post/679848</guid><dc:creator><![CDATA[eyllanesc]]></dc:creator><pubDate>Thu, 09 Sep 2021 07:31:34 GMT</pubDate></item></channel></rss>