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
53 lines
2.3 KiB
C++
53 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <QString>
|
|
#include <QStringList>
|
|
|
|
// Installs the translation matching the language preference, and swaps it when
|
|
// the user picks another one on the Settings screen.
|
|
//
|
|
// 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).
|
|
//
|
|
// 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 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
|
|
// screen can say so instead of pretending a choice will change something.
|
|
static bool isTranslationAvailable(const QString& code);
|
|
|
|
// Where a catalogue is looked up, for the screen to display.
|
|
static QString searchPathHint();
|
|
|
|
// Installs the catalogue for `code` (see resolve) and asks every widget to
|
|
// retranslate itself. Returns true when a catalogue was installed.
|
|
static bool apply(const QString& code);
|
|
|
|
// Catalogue currently installed, empty when the interface is untranslated.
|
|
static QString activeCode();
|
|
|
|
// 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();
|
|
};
|