diff --git a/.travis.yml b/.travis.yml index 9624d4483..111d89528 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,22 @@ matrix: install: "./.travis/linux/deps.sh" script: "./.travis/linux/build.sh" after_success: "./.travis/linux/upload.sh" + - if: branch = master AND type = push + os: linux + env: NAME="transifex push" + sudo: required + dist: trusty + addons: + apt: + packages: + - libsdl2-dev + - qtbase5-dev + - libqt5opengl5-dev + - qttools5-dev + - qttools5-dev-tools + install: "./.travis/transifex/deps.sh" + script: "./.travis/transifex/build.sh" + after_success: "./.travis/transifex/upload.sh" - os: osx env: NAME="macos build" sudo: false diff --git a/.travis/linux/docker.sh b/.travis/linux/docker.sh index e27af5600..ac8940719 100755 --- a/.travis/linux/docker.sh +++ b/.travis/linux/docker.sh @@ -3,7 +3,7 @@ cd /citra apt-get update -apt-get install -y build-essential libsdl2-dev qtbase5-dev libqt5opengl5-dev libcurl4-openssl-dev libssl-dev wget git +apt-get install -y build-essential libsdl2-dev qtbase5-dev libqt5opengl5-dev qttools5-dev qttools5-dev-tools libcurl4-openssl-dev libssl-dev wget git # Get a recent version of CMake wget https://cmake.org/files/v3.9/cmake-3.9.0-Linux-x86_64.sh @@ -11,7 +11,7 @@ echo y | sh cmake-3.9.0-Linux-x86_64.sh --prefix=cmake export PATH=/citra/cmake/cmake-3.9.0-Linux-x86_64/bin:$PATH mkdir build && cd build -cmake .. -DUSE_SYSTEM_CURL=ON -DCMAKE_BUILD_TYPE=Release +cmake .. -DUSE_SYSTEM_CURL=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_QT_TRANSLATION=ON make -j4 ctest -VV -C Release diff --git a/.travis/macos/build.sh b/.travis/macos/build.sh index c957cdf21..37e84f6e8 100755 --- a/.travis/macos/build.sh +++ b/.travis/macos/build.sh @@ -6,7 +6,7 @@ export MACOSX_DEPLOYMENT_TARGET=10.9 export Qt5_DIR=$(brew --prefix)/opt/qt5 mkdir build && cd build -cmake .. -DUSE_SYSTEM_CURL=ON -DCMAKE_OSX_ARCHITECTURES="x86_64;x86_64h" -DCMAKE_BUILD_TYPE=Release +cmake .. -DUSE_SYSTEM_CURL=ON -DCMAKE_OSX_ARCHITECTURES="x86_64;x86_64h" -DCMAKE_BUILD_TYPE=Release -DENABLE_QT_TRANSLATION=ON make -j4 ctest -VV -C Release diff --git a/.travis/transifex/build.sh b/.travis/transifex/build.sh new file mode 100755 index 000000000..2e9822360 --- /dev/null +++ b/.travis/transifex/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash -ex + +mkdir build && cd build +cmake .. -DENABLE_QT_TRANSLATION=ON -DGENERATE_QT_TRANSLATION=ON -DCMAKE_BUILD_TYPE=Release +make translation + diff --git a/.travis/transifex/deps.sh b/.travis/transifex/deps.sh new file mode 100755 index 000000000..3fa6b1109 --- /dev/null +++ b/.travis/transifex/deps.sh @@ -0,0 +1,4 @@ +#!/bin/bash -ex + +sudo pip install transifex-client +echo $'[https://www.transifex.com]\nhostname = https://www.transifex.com\nusername = api\npassword = '"$TRANSIFEX_API_TOKEN"$'\n' > ~/.transifexrc diff --git a/.travis/transifex/upload.sh b/.travis/transifex/upload.sh new file mode 100755 index 000000000..f51847850 --- /dev/null +++ b/.travis/transifex/upload.sh @@ -0,0 +1,5 @@ +#!/bin/bash -ex + +cd dist/languages +tx push -s + diff --git a/CMakeLists.txt b/CMakeLists.txt index 25a5ef57e..734ff08b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,10 +10,12 @@ option(ENABLE_SDL2 "Enable the SDL2 frontend" ON) option(CITRA_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" OFF) option(ENABLE_QT "Enable the Qt frontend" ON) +option(ENABLE_QT_TRANSLATION "Enable translations for the Qt frontend" OFF) option(CITRA_USE_BUNDLED_QT "Download bundled Qt binaries" OFF) option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON) option(CITRA_USE_BUNDLED_CURL "FOR MINGW ONLY: Download curl configured against winssl instead of openssl" OFF) + if (ENABLE_WEB_SERVICE AND CITRA_USE_BUNDLED_CURL AND WINDOWS AND MSVC) message("Turning off use bundled curl as msvc can compile curl on cpr") SET(CITRA_USE_BUNDLED_CURL OFF CACHE BOOL "" FORCE) @@ -232,6 +234,10 @@ if (ENABLE_QT) endif() find_package(Qt5 REQUIRED COMPONENTS Widgets OpenGL ${QT_PREFIX_HINT}) + + if (ENABLE_QT_TRANSLATION) + find_package(Qt5 REQUIRED COMPONENTS LinguistTools ${QT_PREFIX_HINT}) + endif() endif() if (ENABLE_WEB_SERVICE) diff --git a/README.md b/README.md index ad2f03a56..9b249f126 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ Most of the development happens on GitHub. It's also where [our central reposito If you want to contribute please take a look at the [Contributor's Guide](CONTRIBUTING.md) and [Developer Information](https://github.com/citra-emu/citra/wiki/Developer-Information). You should as well contact any of the developers in the forum in order to know about the current state of the emulator because the [TODO list](https://docs.google.com/document/d/1SWIop0uBI9IW8VGg97TAtoT_CHNoP42FzYmvG1F4QDA) isn't maintained anymore. +If you want to contribute to the user interface translation, please checkout [citra project on transifex](https://www.transifex.com/citra/citra). We centralize the translation work there, and periodically upstream translation. + ### Building * __Windows__: [Windows Build](https://github.com/citra-emu/citra/wiki/Building-For-Windows) diff --git a/appveyor.yml b/appveyor.yml index dfa77c97b..58038b8b5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -45,7 +45,7 @@ before_build: # redirect stderr and change the exit code to prevent powershell from cancelling the build if cmake prints a warning cmd /C 'cmake -G "Visual Studio 15 2017 Win64" -DCITRA_USE_BUNDLED_QT=1 -DCITRA_USE_BUNDLED_SDL2=1 -DCMAKE_USE_OPENSSL=0 .. 2>&1 && exit 0' } else { - C:\msys64\usr\bin\bash.exe -lc "cmake -G 'MSYS Makefiles' -DUSE_SYSTEM_CURL=1 -DCITRA_USE_BUNDLED_CURL=1 -DCMAKE_BUILD_TYPE=Release .. 2>&1" + C:\msys64\usr\bin\bash.exe -lc "cmake -G 'MSYS Makefiles' -DUSE_SYSTEM_CURL=1 -DCITRA_USE_BUNDLED_CURL=1 -DCMAKE_BUILD_TYPE=Release -DENABLE_QT_TRANSLATION=ON .. 2>&1" } - cd .. diff --git a/dist/languages/.gitignore b/dist/languages/.gitignore new file mode 100644 index 000000000..8fc7e6a17 --- /dev/null +++ b/dist/languages/.gitignore @@ -0,0 +1,3 @@ +# Ignore the source language file +en.ts + diff --git a/dist/languages/.tx/config b/dist/languages/.tx/config new file mode 100644 index 000000000..84d8896b4 --- /dev/null +++ b/dist/languages/.tx/config @@ -0,0 +1,9 @@ +[main] +host = https://www.transifex.com + +[citra.emulator] +file_filter = .ts +source_file = en.ts +source_lang = en +type = QT + diff --git a/dist/languages/README.md b/dist/languages/README.md new file mode 100644 index 000000000..2156fd386 --- /dev/null +++ b/dist/languages/README.md @@ -0,0 +1 @@ +This directory stores translation patches (TS files) for citra Qt frontend. This directory is linked with [citra project on transifex](https://www.transifex.com/citra/citra), so you can update the translation by executing `tx pull -a`. If you want to contribute to the translation, please go the transifex link and submit your translation there. This directory on the main repo will be synchronized with transifex periodically. Do not directly open PRs on github to modify the translation. diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index 9da384620..ac472ad5c 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -87,12 +87,46 @@ file(GLOB_RECURSE THEMES ${CMAKE_SOURCE_DIR}/dist/qt_themes/*) qt5_wrap_ui(UI_HDRS ${UIS}) +if (ENABLE_QT_TRANSLATION) + set(CITRA_QT_LANGUAGES "${CMAKE_SOURCE_DIR}/dist/languages" CACHE PATH "Path to the translation bundle for the Qt frontend") + option(GENERATE_QT_TRANSLATION "Generate en.ts as the translation source file" OFF) + + # Update source TS file if enabled + if (GENERATE_QT_TRANSLATION) + get_target_property(SRCS citra-qt SOURCES) + qt5_create_translation(QM_FILES ${SRCS} ${UIS} ${CITRA_QT_LANGUAGES}/en.ts) + add_custom_target(translation ALL DEPENDS ${CITRA_QT_LANGUAGES}/en.ts) + 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) + + # Compile TS files to QM files + qt5_add_translation(LANGUAGES_QM ${LANGUAGES_TS}) + + # Build a QRC file from the QM file list + set(LANGUAGES_QRC ${CMAKE_CURRENT_BINARY_DIR}/languages.qrc) + file(WRITE ${LANGUAGES_QRC} "\n") + foreach (QM ${LANGUAGES_QM}) + get_filename_component(QM_FILE ${QM} NAME) + file(APPEND ${LANGUAGES_QRC} "${QM_FILE}\n") + endforeach (QM) + file(APPEND ${LANGUAGES_QRC} "") + + # Add the QRC file to package in all QM files + qt5_add_resources(LANGUAGES ${LANGUAGES_QRC}) +else() + set(LANGUAGES) +endif() + target_sources(citra-qt PRIVATE ${ICONS} ${THEMES} ${UI_HDRS} ${UIS} + ${LANGUAGES} ) if (APPLE) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index d96405110..7e64fbaaf 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -184,6 +184,7 @@ void Config::ReadValues() { UISettings::values.gamedir = qt_config->value("gameListRootDir", ".").toString(); UISettings::values.gamedir_deepscan = qt_config->value("gameListDeepScan", false).toBool(); UISettings::values.recent_files = qt_config->value("recentFiles").toStringList(); + UISettings::values.language = qt_config->value("language", "").toString(); qt_config->endGroup(); qt_config->beginGroup("Shortcuts"); @@ -335,6 +336,7 @@ void Config::SaveValues() { qt_config->setValue("gameListRootDir", UISettings::values.gamedir); qt_config->setValue("gameListDeepScan", UISettings::values.gamedir_deepscan); qt_config->setValue("recentFiles", UISettings::values.recent_files); + qt_config->setValue("language", UISettings::values.language); qt_config->endGroup(); qt_config->beginGroup("Shortcuts"); diff --git a/src/citra_qt/configuration/configure_audio.cpp b/src/citra_qt/configuration/configure_audio.cpp index 8f020c0e8..af58df308 100644 --- a/src/citra_qt/configuration/configure_audio.cpp +++ b/src/citra_qt/configuration/configure_audio.cpp @@ -76,3 +76,7 @@ void ConfigureAudio::updateAudioDevices(int sink_index) { ui->audio_device_combo_box->addItem(device.c_str()); } } + +void ConfigureAudio::retranslateUi() { + ui->retranslateUi(this); +} diff --git a/src/citra_qt/configuration/configure_audio.h b/src/citra_qt/configuration/configure_audio.h index 8190e694f..d4790db5c 100644 --- a/src/citra_qt/configuration/configure_audio.h +++ b/src/citra_qt/configuration/configure_audio.h @@ -19,6 +19,7 @@ public: ~ConfigureAudio(); void applyConfiguration(); + void retranslateUi(); public slots: void updateAudioDevices(int sink_index); diff --git a/src/citra_qt/configuration/configure_debug.cpp b/src/citra_qt/configuration/configure_debug.cpp index 263f73f38..48f57739e 100644 --- a/src/citra_qt/configuration/configure_debug.cpp +++ b/src/citra_qt/configuration/configure_debug.cpp @@ -24,3 +24,7 @@ void ConfigureDebug::applyConfiguration() { Settings::values.gdbstub_port = ui->gdbport_spinbox->value(); Settings::Apply(); } + +void ConfigureDebug::retranslateUi() { + ui->retranslateUi(this); +} diff --git a/src/citra_qt/configuration/configure_debug.h b/src/citra_qt/configuration/configure_debug.h index d167eb996..fc95c91ca 100644 --- a/src/citra_qt/configuration/configure_debug.h +++ b/src/citra_qt/configuration/configure_debug.h @@ -19,6 +19,7 @@ public: ~ConfigureDebug(); void applyConfiguration(); + void retranslateUi(); private: void setConfiguration(); diff --git a/src/citra_qt/configuration/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp index b87dc0e6c..ca468bf81 100644 --- a/src/citra_qt/configuration/configure_dialog.cpp +++ b/src/citra_qt/configuration/configure_dialog.cpp @@ -10,6 +10,8 @@ ConfigureDialog::ConfigureDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ConfigureDialog) { ui->setupUi(this); this->setConfiguration(); + connect(ui->generalTab, &ConfigureGeneral::languageChanged, this, + &ConfigureDialog::onLanguageChanged); } ConfigureDialog::~ConfigureDialog() {} @@ -26,3 +28,15 @@ void ConfigureDialog::applyConfiguration() { ui->webTab->applyConfiguration(); Settings::Apply(); } + +void ConfigureDialog::onLanguageChanged(const QString& locale) { + emit languageChanged(locale); + ui->retranslateUi(this); + ui->generalTab->retranslateUi(); + ui->systemTab->retranslateUi(); + ui->inputTab->retranslateUi(); + ui->graphicsTab->retranslateUi(); + ui->audioTab->retranslateUi(); + ui->debugTab->retranslateUi(); + ui->webTab->retranslateUi(); +} diff --git a/src/citra_qt/configuration/configure_dialog.h b/src/citra_qt/configuration/configure_dialog.h index 21fa1f501..481e30154 100644 --- a/src/citra_qt/configuration/configure_dialog.h +++ b/src/citra_qt/configuration/configure_dialog.h @@ -20,6 +20,12 @@ public: void applyConfiguration(); +private slots: + void onLanguageChanged(const QString& locale); + +signals: + void languageChanged(const QString& locale); + private: void setConfiguration(); diff --git a/src/citra_qt/configuration/configure_general.cpp b/src/citra_qt/configuration/configure_general.cpp index f8f6c305d..ad008a011 100644 --- a/src/citra_qt/configuration/configure_general.cpp +++ b/src/citra_qt/configuration/configure_general.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include "citra_qt/configuration/configure_general.h" #include "citra_qt/ui_settings.h" #include "core/core.h" @@ -12,6 +13,23 @@ ConfigureGeneral::ConfigureGeneral(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureGeneral) { ui->setupUi(this); + ui->language_combobox->addItem(tr(""), QString("")); + ui->language_combobox->addItem(tr("English"), QString("en")); + QDirIterator it(":/languages", QDirIterator::NoIteratorFlags); + while (it.hasNext()) { + QString locale = it.next(); + locale.truncate(locale.lastIndexOf('.')); + locale.remove(0, locale.lastIndexOf('/') + 1); + QString lang = QLocale::languageToString(QLocale(locale).language()); + ui->language_combobox->addItem(lang, locale); + } + + // Unlike other configuration changes, interface language changes need to be reflected on the + // interface immediately. This is done by passing a signal to the main window, and then + // retranslating when passing back. + connect(ui->language_combobox, + static_cast(&QComboBox::currentIndexChanged), this, + &ConfigureGeneral::onLanguageChanged); for (auto theme : UISettings::themes) { ui->theme_combobox->addItem(theme.first, theme.second); @@ -37,6 +55,8 @@ void ConfigureGeneral::setConfiguration() { ui->region_combobox->setCurrentIndex(Settings::values.region_value + 1); ui->theme_combobox->setCurrentIndex(ui->theme_combobox->findData(UISettings::values.theme)); + ui->language_combobox->setCurrentIndex( + ui->language_combobox->findData(UISettings::values.language)); } void ConfigureGeneral::applyConfiguration() { @@ -52,3 +72,14 @@ void ConfigureGeneral::applyConfiguration() { Settings::values.use_cpu_jit = ui->toggle_cpu_jit->isChecked(); Settings::Apply(); } + +void ConfigureGeneral::onLanguageChanged(int index) { + if (index == -1) + return; + + emit languageChanged(ui->language_combobox->itemData(index).toString()); +} + +void ConfigureGeneral::retranslateUi() { + ui->retranslateUi(this); +} diff --git a/src/citra_qt/configuration/configure_general.h b/src/citra_qt/configuration/configure_general.h index 447552d8c..55fd93890 100644 --- a/src/citra_qt/configuration/configure_general.h +++ b/src/citra_qt/configuration/configure_general.h @@ -19,6 +19,13 @@ public: ~ConfigureGeneral(); void applyConfiguration(); + void retranslateUi(); + +private slots: + void onLanguageChanged(int index); + +signals: + void languageChanged(const QString& locale); private: void setConfiguration(); diff --git a/src/citra_qt/configuration/configure_general.ui b/src/citra_qt/configuration/configure_general.ui index 00e5b49f5..c2bf24b52 100644 --- a/src/citra_qt/configuration/configure_general.ui +++ b/src/citra_qt/configuration/configure_general.ui @@ -6,8 +6,8 @@ 0 0 - 300 - 377 + 345 + 493 @@ -38,6 +38,20 @@ + + + + + + Interface language + + + + + + + + diff --git a/src/citra_qt/configuration/configure_graphics.cpp b/src/citra_qt/configuration/configure_graphics.cpp index b5a5ab1e1..d1546f3aa 100644 --- a/src/citra_qt/configuration/configure_graphics.cpp +++ b/src/citra_qt/configuration/configure_graphics.cpp @@ -113,3 +113,7 @@ void ConfigureGraphics::applyConfiguration() { Settings::values.swap_screen = ui->swap_screen->isChecked(); Settings::Apply(); } + +void ConfigureGraphics::retranslateUi() { + ui->retranslateUi(this); +} diff --git a/src/citra_qt/configuration/configure_graphics.h b/src/citra_qt/configuration/configure_graphics.h index 5497a55f7..36bdef890 100644 --- a/src/citra_qt/configuration/configure_graphics.h +++ b/src/citra_qt/configuration/configure_graphics.h @@ -19,6 +19,7 @@ public: ~ConfigureGraphics(); void applyConfiguration(); + void retranslateUi(); private: void setConfiguration(); diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 5a7d269cd..64a22cb03 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -277,3 +277,7 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) { } setPollingResult({}, true); } + +void ConfigureInput::retranslateUi() { + ui->retranslateUi(this); +} diff --git a/src/citra_qt/configuration/configure_input.h b/src/citra_qt/configuration/configure_input.h index a0bef86d5..2efebf20d 100644 --- a/src/citra_qt/configuration/configure_input.h +++ b/src/citra_qt/configuration/configure_input.h @@ -33,6 +33,7 @@ public: /// Save all button configurations to settings file void applyConfiguration(); + void retranslateUi(); private: std::unique_ptr ui; diff --git a/src/citra_qt/configuration/configure_system.cpp b/src/citra_qt/configuration/configure_system.cpp index 88a067c12..6793fb50d 100644 --- a/src/citra_qt/configuration/configure_system.cpp +++ b/src/citra_qt/configuration/configure_system.cpp @@ -167,3 +167,7 @@ void ConfigureSystem::refreshConsoleID() { Service::CFG::UpdateConfigNANDSavegame(); ui->label_console_id->setText("Console ID: 0x" + QString::number(console_id, 16).toUpper()); } + +void ConfigureSystem::retranslateUi() { + ui->retranslateUi(this); +} diff --git a/src/citra_qt/configuration/configure_system.h b/src/citra_qt/configuration/configure_system.h index f13de17d4..094887791 100644 --- a/src/citra_qt/configuration/configure_system.h +++ b/src/citra_qt/configuration/configure_system.h @@ -20,6 +20,7 @@ public: void applyConfiguration(); void setConfiguration(); + void retranslateUi(); public slots: void updateBirthdayComboBox(int birthmonth_index); diff --git a/src/citra_qt/configuration/configure_web.cpp b/src/citra_qt/configuration/configure_web.cpp index bf8c21ac7..8bfbb94c3 100644 --- a/src/citra_qt/configuration/configure_web.cpp +++ b/src/citra_qt/configuration/configure_web.cpp @@ -100,3 +100,7 @@ void ConfigureWeb::OnLoginVerified() { "correctly, and that your internet connection is working.")); } } + +void ConfigureWeb::retranslateUi() { + ui->retranslateUi(this); +} diff --git a/src/citra_qt/configuration/configure_web.h b/src/citra_qt/configuration/configure_web.h index ad2d58f6e..b8e71ffdd 100644 --- a/src/citra_qt/configuration/configure_web.h +++ b/src/citra_qt/configuration/configure_web.h @@ -20,6 +20,7 @@ public: ~ConfigureWeb(); void applyConfiguration(); + void retranslateUi(); public slots: void RefreshTelemetryID(); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 1067c5064..7ecd9b742 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -97,6 +97,8 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) { // register size_t to use in slots and signals qRegisterMetaType("size_t"); + LoadTranslation(); + Pica::g_debug_context = Pica::DebugContext::Construct(); setAcceptDrops(true); ui.setupUi(this); @@ -114,8 +116,8 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) { ConnectMenuEvents(); ConnectWidgetEvents(); - setWindowTitle(QString("Citra %1| %2-%3") - .arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc)); + SetupUIStrings(); + show(); game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan); @@ -871,6 +873,8 @@ void GMainWindow::ToggleWindowMode() { void GMainWindow::OnConfigure() { ConfigureDialog configureDialog(this); + connect(&configureDialog, &ConfigureDialog::languageChanged, this, + &GMainWindow::OnLanguageChanged); auto result = configureDialog.exec(); if (result == QDialog::Accepted) { configureDialog.applyConfiguration(); @@ -1085,6 +1089,45 @@ void GMainWindow::UpdateUITheme() { } } +void GMainWindow::LoadTranslation() { + // If the selected language is English, no need to install any translation + if (UISettings::values.language == "en") { + return; + } + + bool loaded; + + if (UISettings::values.language.isEmpty()) { + // If the selected language is empty, use system locale + loaded = translator.load(QLocale(), "", "", ":/languages/"); + } else { + // Otherwise load from the specified file + loaded = translator.load(UISettings::values.language, ":/languages/"); + } + + if (loaded) { + qApp->installTranslator(&translator); + } else { + UISettings::values.language = "en"; + } +} + +void GMainWindow::OnLanguageChanged(const QString& locale) { + if (UISettings::values.language != "en") { + qApp->removeTranslator(&translator); + } + + UISettings::values.language = locale; + LoadTranslation(); + ui.retranslateUi(this); + SetupUIStrings(); +} + +void GMainWindow::SetupUIStrings() { + setWindowTitle( + tr("Citra %1| %2-%3").arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc)); +} + #ifdef main #undef main #endif diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 70fb309e7..b0bceaac5 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "core/core.h" #include "core/hle/service/am/am.h" #include "ui_main.h" @@ -151,9 +152,12 @@ private slots: void OnUpdateFound(bool found, bool error); void OnCheckForUpdates(); void OnOpenUpdater(); + void OnLanguageChanged(const QString& locale); private: void UpdateStatusBar(); + void LoadTranslation(); + void SetupUIStrings(); Ui::MainWindow ui; @@ -192,6 +196,8 @@ private: QAction* actions_recent_files[max_recent_files_item]; + QTranslator translator; + protected: void dropEvent(QDropEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override; diff --git a/src/citra_qt/ui_settings.h b/src/citra_qt/ui_settings.h index dba4c5d3c..caf6aea6a 100644 --- a/src/citra_qt/ui_settings.h +++ b/src/citra_qt/ui_settings.h @@ -48,6 +48,7 @@ struct Values { QString gamedir; bool gamedir_deepscan; QStringList recent_files; + QString language; QString theme;