Reputation: 4004
I am using QT Linguist 5.13.2 on Windows 10.
The project has a number of translation files which all work, apart from the one for Italian.
Here is an snippet of the relevant code where the option is mapped to a qm
file:
void Stg::initTranslators()
{
_translatorEn = new QTranslator(this);
_translatorPl = new QTranslator(this);
_translatorFr = new QTranslator(this);
_translatorDe = new QTranslator(this);
_translatorNl = new QTranslator(this);
_translatorEs = new QTranslator(this);
_translatorIt = new QTranslator(this);
_translatorPt = new QTranslator(this);
_translatorAr = new QTranslator(this);
_translatorZh = new QTranslator(this);
_translatorEn->load(QStringLiteral(":/translation/translation/trn_en.qm"));
_translatorPl->load(QStringLiteral(":/translation/translation/trn_pl.qm"));
_translatorFr->load(QStringLiteral(":/translation/translation/trn_fr.qm"));
_translatorDe->load(QStringLiteral(":/translation/translation/trn_de.qm"));
_translatorNl->load(QStringLiteral(":/translation/translation/trn_nl.qm"));
_translatorEs->load(QStringLiteral(":/translation/translation/trn_es.qm"));
_translatorIt->load(QStringLiteral(":/translation/translation/trn_it.qm")); // Italian
_translatorPt->load(QStringLiteral(":/translation/translation/trn_pt.qm"));
_translatorAr->load(QStringLiteral(":/translation/translation/trn_ar.qm"));
_translatorZh->load(QStringLiteral(":/translation/translation/trn_zh.qm"));
}
In the code when the language is selected this code is executed to set the language:
switch (_appLanguage) {
case LANG_EN : { qApp->installTranslator(_translatorEn); } break;
case LANG_PL : { qApp->installTranslator(_translatorPl); } break;
case LANG_FR : { qApp->installTranslator(_translatorFr); } break;
case LANG_DE : { qApp->installTranslator(_translatorDe); } break;
case LANG_NL : { qApp->installTranslator(_translatorNl); } break;
case LANG_ES : { qApp->installTranslator(_translatorEs); } break;
case LANG_IT : { qApp->installTranslator(_translatorIt); } break; // Italian
case LANG_PT : { qApp->installTranslator(_translatorPt); } break;
case LANG_AR : { qApp->installTranslator(_translatorAr); } break;
case LANG_ZH : { qApp->installTranslator(_translatorZh); } break;
default : { } break;
}
All languages switch correctly, apart from Italian.
To determine if the issue is the translation file, or the switching code, I change the mapping to Arabic for the Italian selection:
_translatorIt->load(QStringLiteral(":/translation/translation/trn_ar.qm")); // Italian
With this the language settings do switch to Arabic when selecting Italian, which suggest the issue is in the trn_it.ts
and/or the generated trn_it.qm
.
When I load the trn_it.ts
file into Qt Linguist it reports no errors, and the trn_it.qm
file generated (via File->Release) is about the right size (as the other language qm
files).
Doing a diff
between the trn_it.ts
and trn_de.ts
files reveals the only differences are the expected <translation>
elements. Everything else is the same.
Here is a snippet:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
<name>AboutDialog</name>
<message>
<location filename="ui/aboutdialog.cpp" line="90"/>
<location filename="ui/aboutdialog.cpp" line="98"/>
<source>Unregistered</source>
<translation>Non registrato</translation>
</message>
I'm at a loss to explain this, and how to debug this further.
Upvotes: 0
Views: 873
Reputation: 4004
After much trial and error, I found the reason for the Italian translation not working was because the trn_it.qm
file (which was new) had not been added as a resource (eg via Qt Creator) for the project.
Once this was done, clean and rebuild did the trick.
Upvotes: 2