Bug 464694 - Mixed language in UI when using application-specific override language on Windows
Summary: Mixed language in UI when using application-specific override language on Win...
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kxmlgui
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Other Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: kdelibs bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-23 14:17 UTC by Ingo Klöcker
Modified: 2023-02-27 10:05 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 5.104
Sentry Crash Report:


Attachments
Configure Language dialog in Kate showing mixed language UI (56.51 KB, image/png)
2023-01-23 14:17 UTC, Ingo Klöcker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ingo Klöcker 2023-01-23 14:17:51 UTC
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.
Comment 1 Ingo Klöcker 2023-01-23 14:58:01 UTC
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.
Comment 2 Bug Janitor Service 2023-01-25 16:51:27 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kxmlgui/-/merge_requests/145
Comment 3 Ingo Klöcker 2023-01-27 16:16:05 UTC
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).
Comment 4 Ingo Klöcker 2023-01-30 14:35:35 UTC
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
Comment 5 Bug Janitor Service 2023-01-30 14:45:14 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ki18n/-/merge_requests/78
Comment 6 Bug Janitor Service 2023-01-30 15:13:51 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/extra-cmake-modules/-/merge_requests/333
Comment 7 Ingo Klöcker 2023-02-21 16:17:49 UTC
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
Comment 8 Ingo Klöcker 2023-02-21 16:26:37 UTC
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
Comment 9 Bug Janitor Service 2023-02-27 08:20:18 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/extra-cmake-modules/-/merge_requests/342
Comment 10 Ingo Klöcker 2023-02-27 09:40:31 UTC
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
Comment 11 Ingo Klöcker 2023-02-27 09:51:21 UTC
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
Comment 12 Ingo Klöcker 2023-02-27 10:01:43 UTC
This issue is now fixed in ki18n and in the code generated by ecm_create_qm_loader for libraries using Qt's translation functionality.