mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-20 15:24:14 +02:00
QETApp: fall back to English when the QET translation is empty
A .qm compiled from a 0%-translated .ts (fi, no, rs, sk, sl, sr) loads successfully but contains no messages, so setLanguage() treated the language as loaded and never fell back to qet_en: users got the French source strings instead of English. Treat an empty translator as not loaded. Also log the QET and Qt .qm files actually loaded in the startup diagnostics (MachineInfo), to make translation reports easier to triage.
This commit is contained in:
@@ -159,6 +159,8 @@ void MachineInfo::send_info_to_debug()
|
||||
qInfo()<< "";
|
||||
qInfo()<< " System language defined in QET configuration:"<< QString(QETApp::langFromSetting().toLatin1());
|
||||
qInfo()<< " language Path:"<< QString(QETApp::languagesPath().toLatin1());
|
||||
qInfo()<< " Loaded QET translation:"<< QETApp::loadedQetTranslationFile();
|
||||
qInfo()<< " Loaded Qt translation:"<< QETApp::loadedQtTranslationFile();
|
||||
qInfo()<< " Common Elements Dir:"<< QString(QETApp::commonElementsDir().toLatin1());
|
||||
qInfo()<< " Common TitleBlock Templates Dir:"<< QString(QETApp::commonTitleBlockTemplatesDir().toLatin1());
|
||||
qInfo()<< " Custom Elements Dir:"<< QString(QETApp::customElementsDir().toLatin1());
|
||||
|
||||
+30
-3
@@ -197,6 +197,26 @@ QETApp *QETApp::instance()
|
||||
return m_qetapp;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETApp::loadedQetTranslationFile
|
||||
@return path of the QET .qm file actually loaded, empty if none
|
||||
(diagnostic helper for the startup log, see MachineInfo)
|
||||
*/
|
||||
QString QETApp::loadedQetTranslationFile()
|
||||
{
|
||||
return m_qetapp ? m_qetapp->qetTranslator.filePath() : QString();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETApp::loadedQtTranslationFile
|
||||
@return path of the Qt .qm file actually loaded, empty if none
|
||||
(diagnostic helper for the startup log, see MachineInfo)
|
||||
*/
|
||||
QString QETApp::loadedQtTranslationFile()
|
||||
{
|
||||
return m_qetapp ? m_qetapp->qtTranslator.filePath() : QString();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETApp::setLanguage
|
||||
Change the language used by the application.
|
||||
@@ -234,14 +254,21 @@ void QETApp::setLanguage(const QString &desired_language) {
|
||||
// desired_language may be a full locale such as "pt_BR": try that exact
|
||||
// translation, then the base language ("pt"), then fall back to English.
|
||||
// French is the application's source language and needs no translation.
|
||||
// A .qm compiled from an untranslated .ts (0% done) loads "successfully"
|
||||
// but is empty: treat it as missing, so the user falls back to English
|
||||
// instead of silently getting the French source strings.
|
||||
const QString base_language = desired_language.section('_', 0, 0);
|
||||
bool loaded = qetTranslator.load("qet_" + desired_language, languages_path);
|
||||
auto loadQet = [this, &languages_path](const QString &name) {
|
||||
return qetTranslator.load(name, languages_path)
|
||||
&& !qetTranslator.isEmpty();
|
||||
};
|
||||
bool loaded = loadQet("qet_" + desired_language);
|
||||
if (!loaded && base_language != desired_language)
|
||||
loaded = qetTranslator.load("qet_" + base_language, languages_path);
|
||||
loaded = loadQet("qet_" + base_language);
|
||||
if (!loaded && base_language != "fr") {
|
||||
// use of the English version by default
|
||||
// utilisation de la version anglaise par defaut
|
||||
if(!qetTranslator.load("qet_en", languages_path))
|
||||
if(!loadQet("qet_en"))
|
||||
qWarning() << "failed to load"
|
||||
<< "qet_en" << languages_path << "(" << __FILE__
|
||||
<< __LINE__ << __FUNCTION__ << ")";
|
||||
|
||||
@@ -102,6 +102,8 @@ class QETApp : public QObject
|
||||
static QString documentDir();
|
||||
static QString pictureDir();
|
||||
static QString languagesPath();
|
||||
static QString loadedQetTranslationFile();
|
||||
static QString loadedQtTranslationFile();
|
||||
static QString realPath(const QString &);
|
||||
static QString symbolicPath(const QString &);
|
||||
static QStringList handledFileExtensions();
|
||||
|
||||
Reference in New Issue
Block a user