feat(i18n): translate the interface and the journal at runtime

The language setting was plumbing with nothing behind it: no catalogue
shipped, and every label was a bare QStringLiteral, so picking English
changed nothing.

A catalogue is now a JSON file read as it is, translations/<code>.json,
keyed by the French source string. No Linguist, no lrelease, no build
step: a new language costs one file. The catalogues the application
ships with are compiled into the binary, so the chosen language works
whatever the install layout is, while one dropped into a translations
folder still wins over it.

"System" reads what the FWS install left behind — LC_ALL, LC_MESSAGES,
LANG, then the LANG= line of /etc/locale.conf — so the interface follows
the language chosen at install time without the user configuring anything.

Fixes #16
This commit is contained in:
BlackAngelTV committed 2026-09-29 21:17:27 +02:00
1 parent b6f51a76ff
commit a26051795f
9 files changed
+882 -42

No files matched your search

+38 -6
View File
@@ -92,7 +92,10 @@ add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PRIVATE include pages)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Widgets Qt6::Network ZLIB::ZLIB)
target_compile_definitions(${PROJECT_NAME} PRIVATE
FWSPACMANAGE_VERSION="${PACMANAGER_VERSION}")
FWSPACMANAGE_VERSION="${PACMANAGER_VERSION}"
# LanguageManager walks the widgets to retranslate them, which only the
# Widgets module provides; the headless test target leaves it out.
PACMANAGER_HAS_WIDGETS)
# Copy the version file next to the executable so UpdateManager can read the
# running build's version at runtime.
@@ -223,13 +226,42 @@ target_include_directories(app-settings-test PRIVATE include)
target_link_libraries(app-settings-test PRIVATE Qt6::Core)
add_test(NAME app-settings-test COMMAND app-settings-test)
# LanguageManager: which language the setting resolves to (including the one
# an FWS install left in the environment or in /etc/locale.conf), and that a
# JSON catalogue read at runtime really translates. The last test walks the
# sources and checks translations/en.json covers every string they ask for.
add_executable(language-manager-test tests/language-manager.test.cpp
src/language-manager.cpp src/app-settings.cpp
include/language-manager.h include/app-settings.h
resources/resources.qrc)
target_include_directories(language-manager-test PRIVATE include)
target_link_libraries(language-manager-test PRIVATE Qt6::Core)
# The resources come along so the test reads the catalogue exactly where the
# application does, compiled in, rather than a copy that could drift.
target_compile_definitions(language-manager-test PRIVATE
PACMANAGER_TRANSLATIONS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/translations")
add_test(NAME language-manager-test COMMAND language-manager-test)
# ---- Translations ----
#
# The language setting loads Qt catalogues named pacmanager_<code>.qm, looked up
# at runtime next to the settings or next to the binary (see
# src/language-manager.cpp). Compiling the .ts sources into .qm needs Qt
# Linguist, which is not always installed: when it is missing the app simply
# runs untranslated, so the build must not depend on it.
# The language setting loads a catalogue named <code>.json out of a
# "translations" folder, looked up at runtime next to the settings or next to
# the binary (see src/language-manager.cpp). A catalogue is read as it is, so
# a new language is one text file and no build step: the copy below is a plain
# file copy and never fails the build.
#
# A .qm compiled from a .ts by Qt Linguist is still accepted at runtime, for a
# translator who prefers that tool. Compiling one needs Qt Linguist, which is
# not always installed, so it stays optional.
# The catalogues are compiled into the binary by resources/resources.qrc, so
# nothing has to be copied or installed next to it: a language the application
# ships with is always there. A catalogue dropped into a "translations" folder
# at runtime is still read, and wins over the built-in one.
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/translations)
message(FATAL_ERROR "translations/ is missing: the catalogues live in "
"resources/resources.qrc")
endif()
find_package(Qt6 QUIET COMPONENTS LinguistTools)
if(Qt6LinguistTools_FOUND AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/translations)
file(GLOB PACMANAGER_TS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/translations/*.ts)