Qt: Add language selector

This commit is contained in:
Vicki Pfau 2017-06-30 11:00:58 -07:00
parent f91a4195b6
commit 4d3d579cae
7 changed files with 73 additions and 30 deletions

View File

@ -150,6 +150,8 @@ Misc:
Bugfixes: Bugfixes:
- Qt: Fix memory search close button (fixes mgba.io/i/769) - Qt: Fix memory search close button (fixes mgba.io/i/769)
- Qt: Fix window icon being stretched - Qt: Fix window icon being stretched
Misc:
- Qt: Add language selector
0.6 beta 1: (2017-06-29) 0.6 beta 1: (2017-06-29)
- Initial beta for 0.6 - Initial beta for 0.6

View File

@ -14,6 +14,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QFileOpenEvent> #include <QFileOpenEvent>
#include <QIcon> #include <QIcon>
#include <QLibraryInfo>
#include <QTranslator> #include <QTranslator>
#include <mgba/core/version.h> #include <mgba/core/version.h>
@ -44,11 +45,19 @@ GBAApp::GBAApp(int& argc, char* argv[])
setWindowIcon(QIcon(":/res/mgba-512.png")); setWindowIcon(QIcon(":/res/mgba-512.png"));
#endif #endif
QTranslator* translator = new QTranslator(this); QLocale locale;
if (translator->load(QLocale(), QLatin1String(binaryName), QLatin1String("-"), QLatin1String(":/translations"))) {
installTranslator(translator); if (!m_configController.getQtOption("language").isNull()) {
locale = QLocale(m_configController.getQtOption("language").toString());
} }
QTranslator qtTranslator;
qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
installTranslator(&qtTranslator);
QTranslator langTranslator;
langTranslator.load(locale, binaryName, "-", ":/translations/");
installTranslator(&langTranslator);
SocketSubsystemInit(); SocketSubsystemInit();
qRegisterMetaType<const uint32_t*>("const uint32_t*"); qRegisterMetaType<const uint32_t*>("const uint32_t*");

View File

@ -14,6 +14,7 @@
#include "ShortcutView.h" #include "ShortcutView.h"
#include <mgba/core/serialize.h> #include <mgba/core/serialize.h>
#include <mgba/core/version.h>
#include <mgba/internal/gba/gba.h> #include <mgba/internal/gba/gba.h>
using namespace QGBA; using namespace QGBA;
@ -164,6 +165,19 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
} }
}); });
m_ui.languages->setItemData(0, QLocale("en"));
QDir ts(":/translations/");
for (auto name : ts.entryList()) {
if (!name.endsWith(".qm")) {
continue;
}
QLocale locale(name.remove(QString("%0-").arg(binaryName)).remove(".qm"));
m_ui.languages->addItem(locale.nativeLanguageName(), locale);
if (locale == QLocale()) {
m_ui.languages->setCurrentIndex(m_ui.languages->count() - 1);
}
}
ShortcutView* shortcutView = new ShortcutView(); ShortcutView* shortcutView = new ShortcutView();
shortcutView->setController(shortcutController); shortcutView->setController(shortcutController);
shortcutView->setInputController(inputController); shortcutView->setInputController(inputController);
@ -253,6 +267,12 @@ void SettingsView::updateConfig() {
emit displayDriverChanged(); emit displayDriverChanged();
} }
QLocale language = m_ui.languages->itemData(m_ui.languages->currentIndex()).toLocale();
if (language != m_controller->getQtOption("language").toLocale() && !(language.bcp47Name() == QLocale::system().bcp47Name() && m_controller->getQtOption("language").isNull())) {
m_controller->setQtOption("language", language.bcp47Name());
emit languageChanged();
}
m_controller->write(); m_controller->write();
emit pathsChanged(); emit pathsChanged();

View File

@ -29,6 +29,7 @@ signals:
void audioDriverChanged(); void audioDriverChanged();
void displayDriverChanged(); void displayDriverChanged();
void pathsChanged(); void pathsChanged();
void languageChanged();
void libraryCleared(); void libraryCleared();
private slots: private slots:

View File

@ -398,17 +398,30 @@
</widget> </widget>
<widget class="QWidget" name="interface_2"> <widget class="QWidget" name="interface_2">
<layout class="QFormLayout" name="formLayout_4"> <layout class="QFormLayout" name="formLayout_4">
<item row="1" column="1"> <item row="0" column="0">
<widget class="QCheckBox" name="showLibrary"> <widget class="QLabel" name="label_26">
<property name="text"> <property name="text">
<string>Show when no game open</string> <string>Language</string>
</property>
<property name="checked">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="languages">
<item>
<property name="text">
<string>English</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Library:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="libraryStyle"> <widget class="QComboBox" name="libraryStyle">
<item> <item>
<property name="text"> <property name="text">
@ -422,35 +435,38 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="3" column="1">
<widget class="QLabel" name="label_6"> <widget class="QCheckBox" name="showLibrary">
<property name="text"> <property name="text">
<string>Library:</string> <string>Show when no game open</string>
</property>
<property name="checked">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="4" column="1">
<widget class="QPushButton" name="clearCache"> <widget class="QPushButton" name="clearCache">
<property name="text"> <property name="text">
<string>Clear cache</string> <string>Clear cache</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="5" column="0" colspan="2">
<widget class="Line" name="line_8"> <widget class="Line" name="line_8">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="6" column="1">
<widget class="QCheckBox" name="allowOpposingDirections"> <widget class="QCheckBox" name="allowOpposingDirections">
<property name="text"> <property name="text">
<string>Allow opposing input directions</string> <string>Allow opposing input directions</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="7" column="1">
<widget class="QCheckBox" name="suspendScreensaver"> <widget class="QCheckBox" name="suspendScreensaver">
<property name="text"> <property name="text">
<string>Suspend screensaver</string> <string>Suspend screensaver</string>
@ -460,13 +476,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="8" column="1">
<widget class="QCheckBox" name="pauseOnFocusLost"> <widget class="QCheckBox" name="pauseOnFocusLost">
<property name="text"> <property name="text">
<string>Pause when inactive</string> <string>Pause when inactive</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2">
<widget class="Line" name="line_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="emulation"> <widget class="QWidget" name="emulation">

View File

@ -459,6 +459,7 @@ void Window::openSettingsWindow() {
connect(settingsWindow, &SettingsView::biosLoaded, m_controller, &GameController::loadBIOS); connect(settingsWindow, &SettingsView::biosLoaded, m_controller, &GameController::loadBIOS);
connect(settingsWindow, &SettingsView::audioDriverChanged, m_controller, &GameController::reloadAudioDriver); connect(settingsWindow, &SettingsView::audioDriverChanged, m_controller, &GameController::reloadAudioDriver);
connect(settingsWindow, &SettingsView::displayDriverChanged, this, &Window::mustRestart); connect(settingsWindow, &SettingsView::displayDriverChanged, this, &Window::mustRestart);
connect(settingsWindow, &SettingsView::languageChanged, this, &Window::mustRestart);
connect(settingsWindow, &SettingsView::pathsChanged, this, &Window::reloadConfig); connect(settingsWindow, &SettingsView::pathsChanged, this, &Window::reloadConfig);
connect(settingsWindow, &SettingsView::libraryCleared, m_libraryView, &LibraryController::clear); connect(settingsWindow, &SettingsView::libraryCleared, m_libraryView, &LibraryController::clear);
openView(settingsWindow); openView(settingsWindow);

View File

@ -10,9 +10,6 @@
#include "GBAApp.h" #include "GBAApp.h"
#include "Window.h" #include "Window.h"
#include <QLibraryInfo>
#include <QTranslator>
#include <mgba/core/version.h> #include <mgba/core/version.h>
#ifdef QT_STATIC #ifdef QT_STATIC
@ -31,15 +28,5 @@ int main(int argc, char* argv[]) {
#endif #endif
QGBA::GBAApp application(argc, argv); QGBA::GBAApp application(argc, argv);
QLocale locale = QLocale::system();
QTranslator qtTranslator;
qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
application.installTranslator(&qtTranslator);
QTranslator langTranslator;
langTranslator.load(locale, binaryName, "-", ":/translations/");
application.installTranslator(&langTranslator);
return application.exec(); return application.exec();
} }