This commit is contained in:
OpenSauce 2026-06-05 18:01:42 +02:00 committed by GitHub
commit 5c589ed39b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 13 deletions

View file

@ -218,7 +218,8 @@ if (ENABLE_QT_UPDATE_CHECKER)
endif()
if (ENABLE_QT_TRANSLATION)
set(CITRA_QT_LANGUAGES "${PROJECT_SOURCE_DIR}/dist/languages" CACHE PATH "Path to the translation bundle for the Qt frontend")
set(BASE_QT_LANGUAGES "${QT_HOST_PATH}/translations" CACHE PATH "Path to the Qt's base translations")
set(CITRA_QT_LANGUAGES "${PROJECT_SOURCE_DIR}/dist/languages" CACHE PATH "Path to Citra's translations for the Qt frontend")
option(GENERATE_QT_TRANSLATION "Generate en.ts as the translation source file" OFF)
# Update source TS file if enabled
@ -235,17 +236,23 @@ if (ENABLE_QT_TRANSLATION)
add_custom_target(translation ALL DEPENDS citra_qt_lupdate)
endif()
# Find all TS files except en.ts
file(GLOB_RECURSE LANGUAGES_TS ${CITRA_QT_LANGUAGES}/*.ts)
list(REMOVE_ITEM LANGUAGES_TS ${CITRA_QT_LANGUAGES}/en.ts)
# Find all TS files for Citra translations except en.ts
file(GLOB_RECURSE CITRA_LANGUAGES_TS ${CITRA_QT_LANGUAGES}/*.ts)
list(REMOVE_ITEM CITRA_LANGUAGES_TS ${CITRA_QT_LANGUAGES}/en.ts)
# Compile TS files to QM files
qt_add_lrelease(citra_qt TS_FILES ${LANGUAGES_TS} NO_GLOBAL_TARGET QM_FILES_OUTPUT_VARIABLE LANGUAGES_QM)
# Compile Citra TS files to QM files
qt_add_lrelease(citra_qt TS_FILES ${CITRA_LANGUAGES_TS} NO_GLOBAL_TARGET QM_FILES_OUTPUT_VARIABLE CITRA_LANGUAGES_QM)
# Find all QM files for Qt translations
file(GLOB_RECURSE QT_LANGUAGES_QM ${BASE_QT_LANGUAGES}/qtbase_*.qm)
# Copy base QT QM files into build directory
file(COPY ${QT_LANGUAGES_QM} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
# Build a QRC file from the QM file list
set(LANGUAGES_QRC ${CMAKE_CURRENT_BINARY_DIR}/languages.qrc)
file(WRITE ${LANGUAGES_QRC} "<RCC><qresource prefix=\"languages\">\n")
foreach (QM ${LANGUAGES_QM})
foreach (QM ${QT_LANGUAGES_QM} ${CITRA_LANGUAGES_QM})
get_filename_component(QM_FILE ${QM} NAME)
file(APPEND ${LANGUAGES_QRC} "<file>${QM_FILE}</file>\n")
endforeach (QM)

View file

@ -7,6 +7,7 @@
#include <memory>
#include <optional>
#include <thread>
#include <unordered_map>
#include <QFileDialog>
#include <QFutureWatcher>
#include <QIcon>
@ -4087,16 +4088,22 @@ void GMainWindow::LoadTranslation() {
bool loaded;
const QString qtbase_prefix = QStringLiteral("qtbase_");
if (UISettings::values.language.isEmpty()) {
// Use the system's default locale
loaded = translator.load(QLocale::system(), {}, {}, QStringLiteral(":/languages/"));
qtTranslator.load(qtbase_prefix + QLocale::system().name(), {}, {},
QStringLiteral(":/languages/"));
loaded = citraTranslator.load(QLocale::system(), {}, {}, QStringLiteral(":/languages/"));
} else {
// Otherwise load from the specified file
loaded = translator.load(UISettings::values.language, QStringLiteral(":/languages/"));
qtTranslator.load(qtbase_prefix + UISettings::values.language,
QStringLiteral(":/languages/"));
loaded = citraTranslator.load(UISettings::values.language, QStringLiteral(":/languages/"));
}
if (loaded) {
qApp->installTranslator(&translator);
qApp->installTranslator(&qtTranslator);
qApp->installTranslator(&citraTranslator);
} else {
UISettings::values.language = QStringLiteral("en");
}
@ -4104,7 +4111,8 @@ void GMainWindow::LoadTranslation() {
void GMainWindow::OnLanguageChanged(const QString& locale) {
if (UISettings::values.language != QStringLiteral("en")) {
qApp->removeTranslator(&translator);
qApp->removeTranslator(&qtTranslator);
qApp->removeTranslator(&citraTranslator);
}
UISettings::values.language = locale;

View file

@ -439,7 +439,8 @@ private:
QAction* action_secondary_swap_screen;
QAction* action_secondary_rotate_screen;
QTranslator translator;
QTranslator qtTranslator;
QTranslator citraTranslator;
// stores default icon theme search paths for the platform
QStringList default_theme_paths;

View file

@ -24,12 +24,17 @@ ConfigureUi::~ConfigureUi() = default;
void ConfigureUi::InitializeLanguageComboBox() {
ui->language_combobox->addItem(tr("<System>"), QString{});
ui->language_combobox->addItem(tr("English"), QStringLiteral("en"));
ui->language_combobox->addItem(QStringLiteral("English"), QStringLiteral("en"));
QDirIterator it(QStringLiteral(":/languages"), QDirIterator::NoIteratorFlags);
while (it.hasNext()) {
QString locale = it.next();
locale.truncate(locale.lastIndexOf(QLatin1Char{'.'}));
locale.remove(0, locale.lastIndexOf(QLatin1Char{'/'}) + 1);
if (locale.startsWith(QStringLiteral("qtbase"))) {
// The Qt Base QM translation files are lumped in with ours,
// so don't show them in the language list!
continue;
}
QString lang = QLocale::languageToString(QLocale(locale).language());
const QString country = QLocale::territoryToString(QLocale(locale).territory());
if (locale == QString::fromStdString("ca_ES_valencia")) {