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

+6 -2
View File
@@ -57,11 +57,15 @@ public:
void setDragDropEnabled(bool enabled);
// ---- Language ----
// "system" to follow the desktop, or one of knownLanguages(). Unknown codes
// fall back to "fr", the language the interface is written in.
// "system" to follow the language the system asks for, or one of
// knownLanguages(). Unknown codes fall back to "fr", the language the
// interface is written in.
QString language() const;
void setLanguage(const QString& code);
static QStringList knownLanguages();
// Endonym of a known code, so the list reads in its own language whatever
// the interface is set to. Falls back to the code itself.
static QString languageName(const QString& code);
static QString sanitizeLanguage(const QString& code);
// ---- Application updates (PacManager itself, not the system packages) ----
+18 -11
View File
@@ -3,27 +3,28 @@
#include <QString>
#include <QStringList>
class QTranslator;
// Installs the translation matching the language preference, and swaps it when
// the user picks another one on the Settings screen.
//
// The translation files are ordinary Qt .qm catalogues, looked up as
// "translations/pacmanager_<code>.qm" in, in order:
// A catalogue is a plain JSON object mapping the source string to its
// translation, looked up as "translations/<code>.json" in, in order:
//
// 1. <AppSettings log directory>/translations (user's own, survives an update);
// 2. <AppDataLocation>/translations (next to the config);
// 3. <directory of the executable>/translations (running from a build tree).
//
// A code with no .qm on any of those paths simply stays untranslated: the
// interface is written in French, which is what apply() falls back to. That is
// deliberate — the setting is the plumbing, and shipping catalogues is a
// translation pass of its own.
// JSON rather than a Qt .qm on purpose: the catalogue is read as it is, so a
// new language costs one small text file and no build step, no lrelease, and
// no recompiling the application. A .qm compiled from a .ts stays supported for
// anyone who prefers Qt Linguist: it is tried first when present.
//
// A code with no catalogue on any of those paths simply stays untranslated: the
// interface is written in French, which is what apply() falls back to.
class LanguageManager {
public:
// Resolves "system" to the desktop's language and falls back to the
// interface's own language when the desktop asks for something no catalogue
// covers.
// Resolves "system" to the language chosen when FWS was installed and falls
// back to the interface's own language when the system asks for something no
// catalogue covers.
static QString resolve(const QString& code);
// True when a catalogue is actually installed for `code`, so the Settings
@@ -42,4 +43,10 @@ public:
// Directories actually searched, in order, existing ones only.
static QStringList searchPaths();
// The language the system is set to, which is what an FWS install leaves
// behind: LC_ALL, then LC_MESSAGES, then LANG, then the LANG= line of
// /etc/locale.conf, then the desktop locale. Public because the Settings
// screen names it when the user picks "system language".
static QString systemLanguage();
};