1#ifndef TRANSLATION_LOADER_HPP
2#define TRANSLATION_LOADER_HPP
13#include <QApplication>
15#include <QLibraryInfo>
40 const auto logInfo = [in_diagnosticsEnabled](
const auto&... args) {
41 if (in_diagnosticsEnabled) (qDebug().noquote() << ... << args);
44 const auto logSuccess =
45 [in_diagnosticsEnabled](
const auto&... args) {
46 if (in_diagnosticsEnabled) (qDebug() << ... << args);
49 const auto logWarning =
50 [in_diagnosticsEnabled](
const auto&... args) {
51 if (in_diagnosticsEnabled)
52 (qWarning().noquote() << ... << args);
55 const QStringList uiLanguages = QLocale::system().uiLanguages();
56 logSuccess(
"--- Translation Debug ---");
57 logSuccess(
"System UI Languages:", uiLanguages);
59 for (
const QString& locale : uiLanguages) {
60 logInfo(
"Attempting to load locale:", locale);
61 const QLocale qLocale(locale);
64 const QString appTranslationPath = QLatin1String(
":/i18n");
67 auto appTranslator =
new QTranslator(qApp);
68 logInfo(
" - App translator: loading 'pure-cpp_", locale,
69 "' from", appTranslationPath);
70 if (appTranslator->load(qLocale, QLatin1String(
"pure-cpp"),
72 appTranslationPath)) {
74 " -> Success: Application translator installed.");
75 QApplication::installTranslator(appTranslator);
78 auto qtTranslator =
new QTranslator(qApp);
79 const QString qtTranslationPath =
80 QLibraryInfo::path(QLibraryInfo::TranslationsPath);
81 logInfo(
" - Qt translator: loading 'qt_", locale,
"' from",
83 if (qtTranslator->load(qLocale, QLatin1String(
"qt"),
87 " -> Success: Qt base translator installed.");
88 QApplication::installTranslator(qtTranslator);
91 " -> Failed: Could not load Qt base "
97 " - App translator: Failed to load translation for",
100 delete appTranslator;
Provides a static method to load translation files for the application.
static void loadTranslations(bool in_diagnosticsEnabled)
Loads and installs the best-matching translation for the system’s locale.
Namespace for application-wide utility functions, primarily for exception handling.