Created attachment 155529 [details] Configure Language dialog in Kate showing mixed language UI On Windows, changing the application language results in a mixed language UI STEPS TO REPRODUCE 1. Start Kate on Windows 2. Open Settings->Configure Language and select a different primary language (should be different from the system language). 3. Close the dialog with OK and restart Kate. 4. Open Settings->Configure Language dialog OBSERVED RESULT The Configure Language dialog is partially using German translation (German is the Windows system language) and partially using the configure language (e.g. Spanish). EXPECTED RESULT The configured language is used for the whole UI. SOFTWARE/OS VERSIONS Windows: 10 KDE Frameworks Version: 5.102 Qt Version: 5.15.8 ADDITIONAL INFORMATION Looks like the system language is used for translations coming from Qt while the configured language is used for translations coming from KDE. With procmon I checked which language files Kate loads (in which order): * Kate looks for/loads .qm files from bin\data\locale\{en,de}, i.e. English and German translations, for some KF5 libraries * Kate looks for/loads qt*_en.qm and qt*_de.qm files from bin\translations for the Qt libraries * Kate looks for/loads .mo files from bin\data\locale\es, i.e. Spanish translations This confirms my assumption that all Qt translations (.qm) are German, the system language, (with English as fallback) while all KDE/gettext translations (.mo) are Spanish, i.e. the configured language. Hypothesis: KXMLGui's initializeLanguages() runs after the initialization function of ki18n and therefore ki18n loads the German translations.
This problem does not exist in Krita 5.1.5 (which uses copies of many KF5 frameworks). On startup Krita also first loads the German (and English) .qm files, but later it also loads the Spanish .qm files.
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kxmlgui/-/merge_requests/145
Analysis: * kxmlgui prepends the application-specific languages to the LANGUAGE environment variable. * ki18n uses QLocale::system().name() to know which translations to load. * This works on Unix because Qt considers LANGUAGE when (re-)initializing the system locale. * This doesn't work on Windows because Qt completely ignores LANGUAGE on Windows. On Windows, Qt does consider LANG, but unfortunately LANG is stored in a function static, i.e. once it has been initialized changes to LANG will be ignored. Therefore, my naïve attempt with https://invent.kde.org/frameworks/kxmlgui/-/merge_requests/145 doesn't work. The result is that on Windows all .qm files are loaded for the system language and not for the application-specific language. Possible (Windows-specific) solutions: a) Replace all usage of QLocale::system().name() in ki18n and in the ECM-generated qm loader with QLocale(first language in LANGUAGE).name(). This could be a performance problem if creating a custom QLocale is very slow. (QLocale::system() is a singleton.) b) Set LANG before QLocale::system() is initialized the first time which means before Q*Application is created. This creates a chicken-egg-problem which may not be solvable without touching all applications because the code that loads the application-specific language needs to know the name of the application (and currently uses qAppName() which requires Q*Application to be created already). I'll go for a).
Git commit b614a60a2e5bcca6c40675e3a1a9de3000911066 by Ingo Klöcker, on behalf of Ingo Klöcker. Committed on 30/01/2023 at 14:35. Pushed by kloecker into branch 'fix-language-override-on-win-and-mac'. Load translations for application-specific language also on Win and Mac On Windows and Apple OSs, we cannot use QLocale::system() because on those OSs Qt ignores LANGUAGE (which is set by kxmlgui to the application-specific languages configured by the user). We need to check LANGUAGE ourselves. M +19 -1 src/i18n/main.cpp https://invent.kde.org/frameworks/ki18n/commit/b614a60a2e5bcca6c40675e3a1a9de3000911066
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ki18n/-/merge_requests/78
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/extra-cmake-modules/-/merge_requests/333
Git commit fb7d5e2a0433f171229ef58393cbfbf0e23ab2b6 by Ingo Klöcker. Committed on 21/02/2023 at 16:17. Pushed by kloecker into branch 'master'. Load translations for application-specific language also on Win and Mac On Windows and Apple OSs, we cannot use QLocale::system() because on those OSs Qt ignores LANGUAGE (which is set by kxmlgui to the application-specific languages configured by the user). We need to check LANGUAGE ourselves. This MR replaces kxmlgui!145. It fixes the bug for the translations provided by Qt. To fix the bug also for translations coming from .qm files in KF libraries a similar change in ecm is needed. I have tested this MR (for KF5) with Kate on Windows. M +20 -2 src/i18n/main.cpp https://invent.kde.org/frameworks/ki18n/commit/fb7d5e2a0433f171229ef58393cbfbf0e23ab2b6
Git commit fb5d9bdbdc6fb832c53078cd72a6b4b62660c9e6 by Ingo Klöcker. Committed on 21/02/2023 at 16:26. Pushed by kloecker into branch 'kf5'. Load translations for application-specific language also on Win and Mac On Windows and Apple OSs, we cannot use QLocale::system() because on those OSs Qt ignores LANGUAGE (which is set by kxmlgui to the application-specific languages configured by the user). We need to check LANGUAGE ourselves. (cherry picked from commit fb7d5e2a0433f171229ef58393cbfbf0e23ab2b6) M +20 -2 src/i18n/main.cpp https://invent.kde.org/frameworks/ki18n/commit/fb5d9bdbdc6fb832c53078cd72a6b4b62660c9e6
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/extra-cmake-modules/-/merge_requests/342
Git commit 7cdbd9789d3b7beeb5acda22c3e940f0235f438a by Ingo Klöcker, on behalf of Ingo Klöcker. Committed on 27/02/2023 at 08:19. Pushed by kloecker into branch 'kf5'. Load translations for application-specific language also on Win and Mac On Windows and Apple OSs, we cannot use QLocale::system() because on those OSs Qt ignores LANGUAGE (which is set by kxmlgui to the application-specific languages configured by the user). We need to check LANGUAGE ourselves. (cherry picked from commit bc92a8611b2c93ec0c4b3ae13b7b8c021845f483) M +24 -4 modules/ECMQmLoader.cpp.in https://invent.kde.org/frameworks/extra-cmake-modules/commit/7cdbd9789d3b7beeb5acda22c3e940f0235f438a
Git commit bc92a8611b2c93ec0c4b3ae13b7b8c021845f483 by Ingo Klöcker, on behalf of Ingo Klöcker. Committed on 27/02/2023 at 08:15. Pushed by kloecker into branch 'master'. Load translations for application-specific language also on Win and Mac On Windows and Apple OSs, we cannot use QLocale::system() because on those OSs Qt ignores LANGUAGE (which is set by kxmlgui to the application-specific languages configured by the user). We need to check LANGUAGE ourselves. M +24 -4 modules/ECMQmLoader.cpp.in https://invent.kde.org/frameworks/extra-cmake-modules/commit/bc92a8611b2c93ec0c4b3ae13b7b8c021845f483
This issue is now fixed in ki18n and in the code generated by ecm_create_qm_loader for libraries using Qt's translation functionality.