<?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[Problem with plurals (tr())]]></title><description><![CDATA[<p dir="auto">In my source code I have:</p>
<pre><code>		QString message{ tr("Do you really want to permanently erase %n file(s)?\n"
			"This operation cannot be reversed or cancelled.",
			"IDS_WARNING_ERASEFILES", selectedRows.size()) };
</code></pre>
<p dir="auto">I also have a DSS.en.ts</p>
<p dir="auto">Which has an entry:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/b9ca75ea-9db6-445b-89c9-2ec84f2641b1.png" alt="08c7b568-64e9-48c3-9077-c2076c1e45c4-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">but when I run the application I get:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/04306726-2184-4d1f-83c1-5993102242c8.png" alt="6f682e7b-275d-4ba1-9dca-2ecf2c00af55-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Clearly I'm doing something wrong but I've no clue what!</p>
<p dir="auto">This code is called before I create the QMainWindow:</p>
<pre><code>	//
	// Retrieve the Qt language name (e.g.) en_GB
	//
	language = settings.value("Language").toString();

	//
	// Language was not defined in our preferences, so select the system default
	//
	if (language == "")
	{
		language = QLocale::system().name();
	}

	QTranslator appTranslator;
	//
	// Install the language if it actually exists.
	//
	if (appTranslator.load("DSS." + language, ":/i18n/"))
	{
		QCoreApplication::instance()-&gt;installTranslator(&amp;appTranslator);
	}
</code></pre>
<p dir="auto">There's no data stored for "Language" in the settings (empty registry string), and under the debugger, the language value returned by QLocale::system().name() was "en_GB" which I though would result in the .en translation being loaded</p>
<p dir="auto">David</p>
]]></description><link>https://forum.qt.io/topic/139556/problem-with-plurals-tr</link><generator>RSS for Node</generator><lastBuildDate>Sun, 25 Oct 2026 09:18:22 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139556.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 25 Sep 2022 11:36:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem with plurals (tr()) on Sun, 25 Sep 2022 16:10:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/perdrix">@<bdi>Perdrix</bdi></a> said in <a href="/post/730109">Problem with plurals (tr())</a>:</p>
<blockquote>
<p dir="auto">File name with text after a character in search_delimiters stripped ("_." is the default for search_delimiters if it is an empty string) and suffix.</p>
</blockquote>
<p dir="auto">baaah, I hate this stupid automatic search for every possibility.</p>
<p dir="auto">You're correct.</p>
<p dir="auto">Do you load it in your main.cpp? Otherwise appTranslator will go out of scope.</p>
]]></description><link>https://forum.qt.io/post/730113</link><guid isPermaLink="true">https://forum.qt.io/post/730113</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 25 Sep 2022 16:10:35 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with plurals (tr()) on Mon, 26 Sep 2022 10:56:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/perdrix">@<bdi>Perdrix</bdi></a> said in <a href="/post/730163">Problem with plurals (tr())</a>:</p>
<blockquote>
<p dir="auto">I think I was misled by the fact that it didn't crash and burn ...</p>
</blockquote>
<p dir="auto">Why should it - it's a Qbject so QCoreApplication::installTranslator() simply connects to QObject::destroyed() and cleans up it's internal structures then.</p>
]]></description><link>https://forum.qt.io/post/730167</link><guid isPermaLink="true">https://forum.qt.io/post/730167</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Mon, 26 Sep 2022 10:56:25 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with plurals (tr()) on Mon, 26 Sep 2022 10:45:35 GMT]]></title><description><![CDATA[<p dir="auto">OK thanks, it all works now that I have moved the QTranslator objects from the stack.</p>
<p dir="auto">I think I was misled by the fact that it didn't crash and burn ...</p>
<p dir="auto">D.</p>
]]></description><link>https://forum.qt.io/post/730163</link><guid isPermaLink="true">https://forum.qt.io/post/730163</guid><dc:creator><![CDATA[Perdrix]]></dc:creator><pubDate>Mon, 26 Sep 2022 10:45:35 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with plurals (tr()) on Mon, 26 Sep 2022 03:15:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/perdrix">@<bdi>Perdrix</bdi></a> said in <a href="/post/730135">Problem with plurals (tr())</a>:</p>
<blockquote>
<p dir="auto">I though QCoreApplication::instance()-&gt;installTranslator(&amp;appTranslator); would copy the appTranslator into its internals?</p>
</blockquote>
<p dir="auto">No, it just stores and uses the pointer you passed to access the QTranslator object.  If the translator goes out of scope then it will be destroyed and you may get crashing or, as seems to be the case, reversion to no-translation behaviour.  When your SetUILanguage() exits, the QTranslator you allocated on the stack will go out of scope.</p>
]]></description><link>https://forum.qt.io/post/730137</link><guid isPermaLink="true">https://forum.qt.io/post/730137</guid><dc:creator><![CDATA[ChrisW67]]></dc:creator><pubDate>Mon, 26 Sep 2022 03:15:33 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with plurals (tr()) on Mon, 26 Sep 2022 02:13:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> I call SetUILanguage(); from main()</p>
<p dir="auto">the code I pasted above is in SetUILanguage.</p>
<p dir="auto">I though QCoreApplication::instance()-&gt;installTranslator(&amp;appTranslator); would copy the appTranslator into its internals?</p>
<p dir="auto">I will move that code to main()  and let you know how it goes.</p>
<p dir="auto">D.</p>
]]></description><link>https://forum.qt.io/post/730135</link><guid isPermaLink="true">https://forum.qt.io/post/730135</guid><dc:creator><![CDATA[Perdrix]]></dc:creator><pubDate>Mon, 26 Sep 2022 02:13:39 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with plurals (tr()) on Sun, 25 Sep 2022 16:10:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/perdrix">@<bdi>Perdrix</bdi></a> said in <a href="/post/730109">Problem with plurals (tr())</a>:</p>
<blockquote>
<p dir="auto">File name with text after a character in search_delimiters stripped ("_." is the default for search_delimiters if it is an empty string) and suffix.</p>
</blockquote>
<p dir="auto">baaah, I hate this stupid automatic search for every possibility.</p>
<p dir="auto">You're correct.</p>
<p dir="auto">Do you load it in your main.cpp? Otherwise appTranslator will go out of scope.</p>
]]></description><link>https://forum.qt.io/post/730113</link><guid isPermaLink="true">https://forum.qt.io/post/730113</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 25 Sep 2022 16:10:35 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with plurals (tr()) on Sun, 25 Sep 2022 15:49:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a></p>
<p dir="auto">Because that's what the documentation says:</p>
<p dir="auto">bool QTranslator::load(const QString &amp;filename, const QString &amp;directory = QString(), const QString &amp;search_delimiters = QString(), const QString &amp;suffix = QString())<br />
Loads filename + suffix (".qm" if the suffix is not specified), which may be an absolute file name or relative to directory. Returns true if the translation is successfully loaded; otherwise returns false.<br />
If directory is not specified, the current directory is used (i.e., as currentPath()).<br />
The previous contents of this translator object are discarded.<br />
If the file name does not exist, other file names are tried in the following order:</p>
<ol>
<li>File name without suffix appended.</li>
<li>File name with text after a character in search_delimiters stripped ("_." is the default for search_delimiters if it is an empty string) and suffix.</li>
<li>File name stripped without suffix appended.</li>
<li>File name stripped further, etc.</li>
</ol>
<p dir="auto">For example, an application running in the fr_CA locale (French-speaking Canada) might call load("foo.fr_ca", "/opt/foolib"). load() would then try to open the first existing readable file from this list:</p>
<p dir="auto">/opt/foolib/foo.fr_ca.qm<br />
/opt/foolib/foo.fr_ca<br />
/opt/foolib/foo.fr.qm<br />
/opt/foolib/foo.fr<br />
/opt/foolib/foo.qm<br />
/opt/foolib/foo</p>
<p dir="auto">David</p>
]]></description><link>https://forum.qt.io/post/730109</link><guid isPermaLink="true">https://forum.qt.io/post/730109</guid><dc:creator><![CDATA[Perdrix]]></dc:creator><pubDate>Sun, 25 Sep 2022 15:49:21 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with plurals (tr()) on Sun, 25 Sep 2022 13:30:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/perdrix">@<bdi>Perdrix</bdi></a> said in <a href="/post/730095">Problem with plurals</a>:</p>
<blockquote>
<p dir="auto">was "en_GB" which I though</p>
</blockquote>
<blockquote>
<p dir="auto">I also have a DSS.en.ts</p>
</blockquote>
<blockquote>
<p dir="auto">appTranslator.load("DSS." + language</p>
</blockquote>
<p dir="auto">Why/how should it load DSS.en.ts when language contains 'en_GB' ?</p>
]]></description><link>https://forum.qt.io/post/730106</link><guid isPermaLink="true">https://forum.qt.io/post/730106</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 25 Sep 2022 13:30:06 GMT</pubDate></item></channel></rss>