CoatiSoftware / Sourcetrail

Sourcetrail - free and open-source interactive source explorer
https://www.sourcetrail.com/
GNU General Public License v3.0
14.94k stars 1.41k forks source link

Research spike: QTranslator support, UI in multiple languages/locales #979

Open LouisStAmour opened 4 years ago

LouisStAmour commented 4 years ago

Besides the fact that we probably don't use translation functions everywhere we'd need to...

I haven't yet looked at non-Windows platforms, but Qt5 has a significant limitation when it comes to localization -- it by default encourages and only supports localization using one language for both interface (UI) strings and locale formatting (dates/numbers, etc.)

This is a problem when users on a different locale OS, let's say French, have set their date preferences to French, but their system display language to English. By default the Qt5 System locale will return French, as it should, but the user's UI is actually English, so we shouldn't be showing French strings. This is also described at https://devblogs.microsoft.com/setup/the-differences-between-locales-and-languages/ and https://stackoverflow.com/questions/18594380/qlocale-detects-system-language-incorrectly-on-windows-with-language-pack-instal

The default steps for localization in Qt5 are described at https://doc.qt.io/qt-5/qtlinguist-arrowpad-example.html however it highlights again the confusion over loading QTranslator UI strings using the system locale, as if they're one and the same.

In reality, on Windows, one should be using the MUI-based APIs and only fall back to locale if they aren't supported (which should be rare). Actually, a lot of decisions around Qt5 locale support were made at a time when localization was rapidly improving, so Qt5 may have a lot of legacy baked in to its APIs. https://wiki.qt.io/Locale_Support_in_Qt_5 (note concerns over supporting Vista and Windows 7 which are still valid but likely only another year or two)

The best example I can find, with Qt specific notes, for getting the current system locale on Windows is https://stackoverflow.com/questions/52849233/getuserpreferreduilanguages-never-returns-more-than-two-languages that said there's also QLocale::system().uiLanguages() so we should check if it uses the same functions or not.

As an implementation note, Qt5 doesn't rely on ICU binaries on Mac or Windows, but they do on Linux. https://doc.qt.io/qt-5/windows-requirements.html#icu Relying on ICU is banned on the Mac App Store.

The best CMake example I could find for translations so far is https://github.com/cmakespark/cmake/blob/91d5ddf945486a4c3aab9d2040d0a4bc1d334da4/src/Translations.cmake however I have yet to find translations that use language and country code (and CMake).

Other examples that use Qt's uiLanguages() function:

Mixxx: https://github.com/mixxxdj/mixxx/blob/522e868ef42ec8d08bbc193386e698900d995dd7/src/util/translations.h#L14 (which uses Python to run lupdate rather than the CMake functions) KeepassXC: https://github.com/keepassxreboot/keepassxc/blob/develop/src/core/Translator.cpp#L40

I can confirm that calling system locale's uiLanguages appears to use the user's preferred language order using https://codereview.qt-project.org/gitweb?p=qt/qt.git;a=blob;f=src/corelib/tools/qlocale_win.cpp;hb=HEAD#l525 I'd confirm the API calls are the same, but it looks close enough at a glance.

egraether commented 4 years ago

We currently don't plan to support other languages than English in our UI.

I think it's too much work in regards to QA, maintenance and supporting resources (webpage and documentation). And in 4 years we never had anyone request another language (maybe because they don't speak English)

I think the only place where we show a date is on the overview screen, where we display date & time when the index was last built. If you want to standardize this, feel free to do so.