mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-06 14:15:41 +12:00
i18n but better
This commit is contained in:
parent
7b7f09f0a0
commit
8217316dbf
3 changed files with 31 additions and 25 deletions
|
@ -126,6 +126,7 @@ class MainWindow : public QMainWindow {
|
|||
void setupControllerSensors(SDL_GameController* controller);
|
||||
void sendMessage(const EmulatorMessage& message);
|
||||
void dispatchMessage(const EmulatorMessage& message);
|
||||
void loadTranslation();
|
||||
|
||||
// Tracks whether we are using an OpenGL-backed renderer or a Vulkan-backed renderer
|
||||
bool usingGL = false;
|
||||
|
|
|
@ -103,7 +103,7 @@ ConfigWindow::ConfigWindow(ConfigCallback configCallback, MainWindowCallback win
|
|||
updateConfig();
|
||||
|
||||
// Update main window title
|
||||
getMainWindow()->setWindowTitle(checked ? "Alber v" PANDA3DS_VERSION : "Alber");
|
||||
getMainWindow()->setWindowTitle(checked ? tr("Alber v%1").arg(PANDA3DS_VERSION) : tr("Alber"));
|
||||
});
|
||||
connectCheckbox(showAppVersion, config.windowSettings.showAppVersion);
|
||||
guiLayout->addRow(showAppVersion);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "version.hpp"
|
||||
|
||||
MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent), keyboardMappings(InputMappings::defaultKeyboardMappings()) {
|
||||
loadTranslation();
|
||||
setWindowTitle(tr("Alber"));
|
||||
|
||||
// Enable drop events for loading ROMs
|
||||
|
@ -79,30 +80,6 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||
emu = new Emulator();
|
||||
emu->setOutputSize(screen->surfaceWidth, screen->surfaceHeight);
|
||||
|
||||
QTranslator* translator = nullptr;
|
||||
auto language = QString::fromStdString("el");
|
||||
const QString baseDir = QStringLiteral(":/translations");
|
||||
QString basePath = QStringLiteral("%1/%2.qm").arg(baseDir).arg(language);
|
||||
|
||||
if (QFile::exists(basePath)) {
|
||||
if (translator != nullptr) {
|
||||
qApp->removeTranslator(translator);
|
||||
}
|
||||
|
||||
translator = new QTranslator(qApp);
|
||||
if (!translator->load(basePath)) {
|
||||
QMessageBox::warning(
|
||||
nullptr, QStringLiteral("Translation Error"),
|
||||
QStringLiteral("Failed to find load translation file for '%1':\n%2").arg(language).arg(basePath)
|
||||
);
|
||||
delete translator;
|
||||
} else {
|
||||
qApp->installTranslator(translator);
|
||||
}
|
||||
} else {
|
||||
printf("%s does not exist\n", basePath.toStdString().c_str());
|
||||
}
|
||||
|
||||
// Set up misc objects
|
||||
aboutWindow = new AboutWindow(nullptr);
|
||||
cheatsEditor = new CheatsWindow(emu, {}, this);
|
||||
|
@ -704,3 +681,31 @@ void MainWindow::setupControllerSensors(SDL_GameController* controller) {
|
|||
SDL_GameControllerSetSensorEnabled(controller, SDL_SENSOR_ACCEL, SDL_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadTranslation() {
|
||||
// TODO: This should become a member variable when we allow changing language at runtime.
|
||||
QTranslator* translator = nullptr;
|
||||
|
||||
auto language = QString::fromStdString("el");
|
||||
const QString baseDir = QStringLiteral(":/translations");
|
||||
QString basePath = QStringLiteral("%1/%2.qm").arg(baseDir).arg(language);
|
||||
|
||||
if (QFile::exists(basePath)) {
|
||||
if (translator != nullptr) {
|
||||
qApp->removeTranslator(translator);
|
||||
}
|
||||
|
||||
translator = new QTranslator(qApp);
|
||||
if (!translator->load(basePath)) {
|
||||
QMessageBox::warning(
|
||||
nullptr, QStringLiteral("Translation Error"),
|
||||
QStringLiteral("Failed to find load translation file for '%1':\n%2").arg(language).arg(basePath)
|
||||
);
|
||||
delete translator;
|
||||
} else {
|
||||
qApp->installTranslator(translator);
|
||||
}
|
||||
} else {
|
||||
printf("Language file %s does not exist\n", basePath.toStdString().c_str());
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue