Skip to content

i18n: add a language setting - #145

Open
Aceared0829 wants to merge 3 commits into
CachyOS:developfrom
Aceared0829:i18n/language-setting-develop
Open

Aceared0829 wants to merge 3 commits into
CachyOS:developfrom
Aceared0829:i18n/language-setting-develop

Conversation

@Aceared0829

@Aceared0829 Aceared0829 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This is the same work as #85, rebased onto develop after fresh was merged, as requested.

#85 targeted fresh and was closed (not merged) once that branch landed in develop. The three commits have been rebased again onto current develop (5796928). There were no conflicts: the only new upstream commit was a CI runner change (.github/workflows/ci.yml) that does not overlap this PR. An earlier rebase onto 2ad88fb had a README.md conflict (this PR inserts the Translations section where develop had removed the Packaging section in 5f83020); that was resolved by keeping the Translations section and not restoring Packaging. The layout table still has src/localization.*, and the removed packaging/ row stays gone.

Adds a language setting to the settings page. The translation catalogues are already on develop (including Greek #176, Japanese #187, Spanish #134, Catalan #161, Italian #164, Turkish #139 and Portuguese (Portugal) #138); this PR adds the selector, runtime switching, translations for the two new strings, and a small Vulkan build fix that is still useful on develop.

  • Localization (src/localization.*) is a QML singleton that owns the chosen language, the application/Qt translators and the default QLocale. main.cpp only wires languageChanged to engine.retranslate(), so the setting stays independent of the UI, the look and the backend.
  • The choice is stored in the app's QSettings ([language] language=) and installed before QML evaluates its first string, then re-installed at runtime — no restart needed.
  • The Language row lists every catalogue embedded by the build. Adding a cachyos-pi_<code>.ts file is enough; no UI change is needed. On current develop that includes ca, de, el, en, es, it, ja, pt_BR, pt_PT, ru, tr_TR, zh_CN and zh_TW.
  • Follow the system uses QLocale::system().uiLanguages() (which covers LANGUAGE, LC_ALL, LC_MESSAGES and LANG), takes the first embedded catalogue it matches and falls back to English. LANG is a second hint for the LC_ALL=C case. Exact regional catalogues such as pt_BR are preferred, then the base language such as de.
  • The appearance and language rows use Flow, so the pills wrap instead of being clipped at the 760 px minimum window width.
  • Navigation labels, the settings rows and the browse categories move from ListModel to plain arrays: qsTr() inside a ListElement is evaluated once, so those labels never followed a language change.

Vulkan compile fix

The second commit is the same __has_include guard as in #85: QT_CONFIG(vulkan) means Qt was built with Vulkan, not that <vulkan/vulkan.h> is present. CI now installs vulkan-headers (#163), so the official workflow can compile the Vulkan probe. The guard is still useful when building locally without those headers: the app then falls back to Qt's default renderer, instead of failing to compile. It rebases cleanly onto the GNOME session skip (03b086b); both checks remain in selectBackend().

Notes

  • Rebased on current develop (5796928). No conflict resolution was required for this rebase; CMakeLists.txt and src/graphics.cpp were unaffected.
  • I18N_TRANSLATED_LANGUAGES is not touched; develop already globs i18n/cachyos-pi_*.ts and embeds them.
  • src/localization.hpp / src/localization.cpp stay in qt_add_executable; they are needed to compile and register the QML singleton.
  • The two new strings (Language, Follow the system) are translated in every shipped catalogue in 227bac2.

Testing

  • desktop-file-validate and appstreamcli validate --no-net pass on this branch (those files are unchanged by this PR).
  • I could not re-run the application build or the unit tests in this environment: it does not have Qt 6.10+ or a C++26 compiler.
  • GitHub Actions Build and test on this head (227bac2) passed: configure, build, and 100% tests passed out of 17.

@Aceared0829
Aceared0829 force-pushed the i18n/language-setting-develop branch 2 times, most recently from 5817646 to 3756143 Compare November 27, 2026 01:58
The interface strings were already extracted, but there was no way to pick a
language.

Localization is a small QML singleton that owns the chosen language, the
translator and the locale, so the rest of the application only reacts to
languageChanged(). It is installed before the engine loads its first string
and re-installs the translator at runtime, so a language change needs no
restart.

"Follow the system" asks Qt for the session's preferred UI languages
(QLocale::system().uiLanguages(), which already covers LANGUAGE, LC_ALL,
LC_MESSAGES and LANG), takes the first one we ship a catalogue for and falls
back to English. LANG is a second hint for the LC_ALL=C case. It is resolved
when the application starts, so a language change in the desktop's settings
applies at the next start.

The settings page lists every catalogue embedded by the build, so a new
language needs no UI change. The navigation, the settings rows and the browse
categories move from ListModel to plain arrays: qsTr() inside a ListElement is
evaluated once, so those labels would never follow a language change.
QT_CONFIG(vulkan) says that Qt was built with Vulkan, not that the
application has <vulkan/vulkan.h>. Qt's headers provide dummy typedefs in
that case, but QVulkanInstance is not defined, so the probe failed to
compile on systems without vulkan-headers, including CI.

Use the same __has_include guard as Qt's own QVulkanInstance header, so
the app falls back to Qt's default renderer when the headers are missing.
Add the Language and Follow the system strings to every shipped catalogue so the new settings row is translated instead of falling back to English.
@Aceared0829
Aceared0829 force-pushed the i18n/language-setting-develop branch from fce4fc4 to 227bac2 Compare November 30, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant