mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-23 19:29:05 +02:00
Initial multi language support
This commit is contained in:
1 parent
2a8dcbd620
commit
88dd9e4b6a
4 files changed
+111
-1
No files matched your search
@@ -27,6 +27,9 @@ linux {
|
||||
}
|
||||
}
|
||||
|
||||
TRANSLATIONS = languages/PPSSPP_en.ts \
|
||||
languages/PPSSPP_pl.ts
|
||||
|
||||
# Main
|
||||
SOURCES += ../native/base/QtMain.cpp
|
||||
HEADERS += ../native/base/QtMain.h
|
||||
|
||||
@@ -778,3 +778,92 @@ void MainWindow::on_action_OptionsGamePadControls_triggered()
|
||||
QMessageBox::information(this,"Gamepad","You need to compile with SDL to have Gamepad support.", QMessageBox::Ok);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::on_language_changed(QAction *action)
|
||||
{
|
||||
if (0 != action)
|
||||
{
|
||||
loadLanguage(action->data().toString());
|
||||
}
|
||||
}
|
||||
|
||||
void switchTranslator(QTranslator &translator, const QString &filename)
|
||||
{
|
||||
qApp->removeTranslator(&translator);
|
||||
|
||||
if (translator.load(filename))
|
||||
qApp->installTranslator(&translator);
|
||||
}
|
||||
|
||||
void MainWindow::loadLanguage(const QString& language)
|
||||
{
|
||||
if (currentLanguage != language)
|
||||
{
|
||||
currentLanguage = language;
|
||||
QLocale locale = QLocale(currentLanguage);
|
||||
QLocale::setDefault(locale);
|
||||
QString languageName = QLocale::languageToString(locale.language());
|
||||
switchTranslator(translator, QString("PPSSPP_%l.qm").arg(language));
|
||||
switchTranslator(qtTranslator, QString("qt_%l.qm").arg(language));
|
||||
ui->statusbar->showMessage(tr("Current language changed to %l").arg(languageName));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::createLanguageMenu()
|
||||
{
|
||||
QActionGroup *langGroup = new QActionGroup(ui->menuLanguage);
|
||||
langGroup->setExclusive(true);
|
||||
|
||||
connect(langGroup, SIGNAL(triggered(QAction *)), this, SLOT(on_language_changed(QAction *)));
|
||||
|
||||
QString defaultLocale = QLocale::system().name();
|
||||
defaultLocale.truncate(defaultLocale.lastIndexOf('_'));
|
||||
languagePath = QApplication::applicationDirPath();
|
||||
languagePath.append("/languages");
|
||||
QDir langDir(languagePath);
|
||||
QStringList fileNames = langDir.entryList(QStringList("PPSSPP_*.qm"));
|
||||
|
||||
for (int i = 0; i < fileNames.size(); ++i)
|
||||
{
|
||||
QString locale = fileNames[i];
|
||||
locale.truncate(locale.lastIndexOf(','));
|
||||
locale.remove(0, locale.indexOf('_') + 1);
|
||||
|
||||
QString language = QLocale::languageToString(QLocale(locale).language());
|
||||
QAction *action = new QAction(language, this);
|
||||
action->setCheckable(true);
|
||||
action->setData(locale);
|
||||
|
||||
ui->menuLanguage->addAction(action);
|
||||
langGroup->addAction(action);
|
||||
|
||||
if (defaultLocale == locale)
|
||||
{
|
||||
action->setChecked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::changeEvent(QEvent *event)
|
||||
{
|
||||
if (0 != event)
|
||||
{
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
case QEvent::LocaleChange:
|
||||
{
|
||||
QString locale = QLocale::system().name();
|
||||
locale.truncate(locale.lastIndexOf('_'));
|
||||
loadLanguage(locale);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QMainWindow::changeEvent(event);
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QTranslator>
|
||||
|
||||
#include "Core/Core.h"
|
||||
#include "input/input_state.h"
|
||||
@@ -135,7 +136,18 @@ private slots:
|
||||
|
||||
void on_action_OptionsGamePadControls_triggered();
|
||||
|
||||
void on_language_changed(QAction *action);
|
||||
|
||||
private:
|
||||
void loadLanguage(const QString &language);
|
||||
void createLanguageMenu();
|
||||
void changeEvent(QEvent *);
|
||||
|
||||
QTranslator translator;
|
||||
QTranslator qtTranslator;
|
||||
QString currentLanguage;
|
||||
QString languagePath;
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
QtEmuGL* w;
|
||||
|
||||
+7
-1
@@ -44,7 +44,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>23</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menu_File">
|
||||
@@ -135,6 +135,11 @@
|
||||
<addaction name="action_OptionsScreen3x"/>
|
||||
<addaction name="action_OptionsScreen4x"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuLanguage">
|
||||
<property name="title">
|
||||
<string>Language</string>
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="action_OptionsControls"/>
|
||||
<addaction name="action_OptionsGamePadControls"/>
|
||||
<addaction name="separator"/>
|
||||
@@ -155,6 +160,7 @@
|
||||
<addaction name="action_OptionsFastMemory"/>
|
||||
<addaction name="action_OptionsIgnoreIllegalReadsWrites"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="menuLanguage"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Help">
|
||||
<property name="title">
|
||||
|
||||
Reference in new issue
Block a user