[Translation] Name languages without reading the translation files (#7662)
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 cover (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Desktop / Prune caches (push) Waiting to run
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions

* [Translation] Name languages without reading the translation files

The language selector derived every label from the language's own .qm file:
it loaded the file and translated the literal "English" in the "i18n"
context. lupdate could never extract that literal from the callers, which
pass the DEFAULT_LANG_NAME macro, so a dummy QT_TRANSLATE_NOOP in
cache_settings.cpp existed to give it something to extract. #7050 deleted
that dummy, the next lupdate push dropped the string from Transifex, and
the following pull rewrote the .ts files without it. lrelease only emits
translated messages, so 22 of 25 .qm files returned an empty name.

The names are data, not translations: a selector has to be readable before
any translation is loaded, and a label must not depend on the translation
of the language it names. TranslationLoader::languageDisplayName now holds
them next to availableLanguages, falling back to Qt's native language name
and then to the code, so a language added later still gets a label.

Also select the configured language by item data instead of by matching the
translated "English" string, which pointed at the wrong row whenever the
lookup came back empty, and restore that English entry's own name: en_US is
"English (United States)" so it can no longer be confused with the
untranslated default.

Oracle shared the code path, so its wizard language page is fixed too.

* [Translation] Name the default language selection once

Review follow-up: log the unresolvable language through the page's own
category, and move the en_US entry both selectors fall back to for an unset
setting into TranslationLoader::defaultLanguageCode.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-10-26 02:39:26 +01:00 • committed by GitHub
parent 858b270fa9
commit 675e1f7447
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 157 additions and 51 deletions

View file

@ -8,7 +8,6 @@
#include "update/client/release_channel.h"
#include <QByteArray>
#include <QCoreApplication>
#include <QDate>
#include <QDebug>
#include <QFile>
@ -22,7 +21,6 @@
#include <QPushButton>
#include <QSharedPointer>
#include <QSizePolicy>
#include <QTranslator>
#include <QVBoxLayout>
#include <QVariant>
#include <QVariantList>
@ -51,18 +49,24 @@ enum startupCardUpdateCheckBehaviorIndex
GeneralSettingsPage::GeneralSettingsPage()
{
// language settings
QStringList languageCodes = findQmFiles();
for (const QString &code : languageCodes) {
QString langName = languageName(code);
languageBox.addItem(langName, code);
for (const QString &code : findQmFiles()) {
languageBox.addItem(TranslationLoader::languageDisplayName(code), code);
}
QString setLanguage = QCoreApplication::translate("i18n", DEFAULT_LANG_NAME);
int index = languageBox.findText(setLanguage, Qt::MatchExactly);
if (index == -1) {
qWarning() << "could not find language" << setLanguage;
} else {
// Select the language the client runs with: its own entry, the base language for a variant without a
// file of its own (de_CH -> de), and the default language for an unset setting, which names no file.
const QString configuredLanguage = SettingsCache::instance().personal().getLang();
int index = languageBox.findData(configuredLanguage);
if (index < 0) {
index = languageBox.findData(configuredLanguage.section('_', 0, 0));
}
if (index < 0) {
index = languageBox.findData(TranslationLoader::defaultLanguageCode());
}
if (index >= 0) {
languageBox.setCurrentIndex(index);
} else {
qCWarning(GeneralSettingsPageLog) << "could not find language" << configuredLanguage;
}
advertiseTranslationPageLabel.setTextInteractionFlags(Qt::LinksAccessibleByMouse);
@ -384,18 +388,6 @@ QStringList GeneralSettingsPage::findQmFiles()
TranslationLoader::applicationTranslationPaths(translationPath));
}
QString GeneralSettingsPage::languageName(const QString &lang)
{
QTranslator qTranslator;
// Only the language name is needed here, so the file is loaded without logging a line per
// language: findQmFiles() asked for languages whose files exist in the first place.
TranslationLoader::loadFrom(qTranslator, translationPrefix + "_" + lang,
TranslationLoader::applicationTranslationPaths(translationPath));
return qTranslator.translate("i18n", DEFAULT_LANG_NAME);
}
void GeneralSettingsPage::deckPathButtonClicked()
{
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"), deckPathEdit->text());