From 0eb3e1e436b2afdadea7d354b30be032e43dc419 Mon Sep 17 00:00:00 2001 From: Shane Ringrose Date: Fri, 12 Jun 2026 05:58:04 +1200 Subject: [PATCH] Fix regional system locale loading the wrong translation (#421) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit langFromSetting() truncated the system locale to two letters (QLocale::system().name().left(2)), so a user on the default 'Système' language whose locale is regional got the base-language translation instead of their regional one. QET ships qet_pt_BR, qet_nl_BE and qet_nl_NL, so e.g. a Brazilian user saw European Portuguese (and untranslated strings fell back to the French source). Keep the full locale name and, in setLanguage(), try the exact translation, then the base language, then English (French stays the native source). Brazilian/Belgian/Dutch users on 'system' now get their regional translation; everyone else is unaffected. Refs #421. --- sources/qetapp.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index aaa462fc5..eb138b666 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -226,20 +226,20 @@ void QETApp::setLanguage(const QString &desired_language) { // load translations for the QET application // charge les traductions pour l'application QET - if (!qetTranslator.load("qet_" + desired_language, languages_path)) { - /* in case of failure, - * we fall back on the native channels for French - * en cas d'echec, - * on retombe sur les chaines natives pour le francais - */ - if (desired_language != "fr") { - // use of the English version by default - // utilisation de la version anglaise par defaut - if(!qetTranslator.load("qet_en", languages_path)) - qWarning() << "failed to load" - << "qet_en" << languages_path << "(" << __FILE__ - << __LINE__ << __FUNCTION__ << ")"; - } + // 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. + const QString base_language = desired_language.section('_', 0, 0); + bool loaded = qetTranslator.load("qet_" + desired_language, languages_path); + if (!loaded && base_language != desired_language) + loaded = qetTranslator.load("qet_" + base_language, languages_path); + 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)) + qWarning() << "failed to load" + << "qet_en" << languages_path << "(" << __FILE__ + << __LINE__ << __FUNCTION__ << ")"; } qApp->installTranslator(&qetTranslator); @@ -263,7 +263,11 @@ QString QETApp::langFromSetting() QSettings settings; system_language = settings.value("lang", "system").toString(); if(system_language == "system") { - system_language = QLocale::system().name().left(2); + // Keep the full locale (e.g. "pt_BR"), not just the base language + // ("pt"): QET ships regional translations (pt_BR, nl_BE, nl_NL) and + // truncating here loaded the wrong one. setLanguage() falls back to + // the base language when no regional translation exists. + system_language = QLocale::system().name(); } lang_is_set = true; }