Merge pull request #3297 from wwylele/translation-tx

citra-qt: add translation support; link translation with transifex
This commit is contained in:
James Rowe 2018-01-18 09:01:00 -07:00 committed by GitHub
commit e1ffcde355
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 248 additions and 8 deletions

View file

@ -97,6 +97,8 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
// register size_t to use in slots and signals
qRegisterMetaType<size_t>("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