yuzu: Port translation support from Citra

Co-Authored-By: Weiyi Wang <wwylele@gmail.com>
This commit is contained in:
FearlessTobi
2020-01-26 00:26:07 +01:00
parent 4a8cb9a706
commit 347b50ad43
17 changed files with 261 additions and 92 deletions

View File

@ -5,6 +5,7 @@
#include <array>
#include <utility>
#include <QDirIterator>
#include "common/common_types.h"
#include "core/settings.h"
#include "ui_configure_ui.h"
@ -28,6 +29,23 @@ constexpr std::array row_text_names{
ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureUi) {
ui->setupUi(this);
ui->language_combobox->addItem(tr("<System>"), QString{});
ui->language_combobox->addItem(tr("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);
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<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&ConfigureUi::OnLanguageChanged);
for (const auto& theme : UISettings::themes) {
ui->theme_combobox->addItem(QString::fromUtf8(theme.first),
@ -72,6 +90,8 @@ void ConfigureUi::RequestGameListUpdate() {
void ConfigureUi::SetConfiguration() {
ui->theme_combobox->setCurrentIndex(ui->theme_combobox->findData(UISettings::values.theme));
ui->language_combobox->setCurrentIndex(
ui->language_combobox->findData(UISettings::values.language));
ui->show_add_ons->setChecked(UISettings::values.show_add_ons);
ui->icon_size_combobox->setCurrentIndex(
ui->icon_size_combobox->findData(UISettings::values.icon_size));
@ -147,3 +167,10 @@ void ConfigureUi::UpdateSecondRowComboBox(bool init) {
ui->row_2_text_combobox->removeItem(
ui->row_2_text_combobox->findData(ui->row_1_text_combobox->currentData()));
}
void ConfigureUi::OnLanguageChanged(int index) {
if (index == -1)
return;
emit LanguageChanged(ui->language_combobox->itemData(index).toString());
}