#pragma once #include #include // 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/.json" in, in order: // // 1. /translations (user's own, survives an update); // 2. /translations (next to the config); // 3. /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(); };