1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-06-25 22:09:35 +00:00

Implement internalization suppport.

This commit is contained in:
Sergey Lipskiy 2015-04-29 15:50:38 +06:00
parent 4d87fb6833
commit 3fa7756fd9
8 changed files with 87 additions and 43 deletions

View File

@ -18,6 +18,8 @@ struct Config
{
u32 version;
std::string translationFile;
struct
{
u32 fullscreen;

View File

@ -1,3 +1,4 @@
#include <QDir>
#include <QFileDialog>
#include <QFontDialog>
#include <QColorDialog>
@ -199,6 +200,41 @@ void ConfigDialog::_init()
ui->blurStrengthSlider->setValue(config.bloomFilter.blurStrength);
}
void ConfigDialog::_getTranslations(QStringList & _translationFiles) const
{
QDir pluginFolder(m_strIniPath);
QStringList nameFilters("gliden64_*.qm");
_translationFiles = pluginFolder.entryList(nameFilters, QDir::Files, QDir::Name);
}
void ConfigDialog::setIniPath(const QString & _strIniPath)
{
m_strIniPath = _strIniPath;
QStringList translationFiles;
_getTranslations(translationFiles);
const QString currentTranslation = getTranslationFile();
int listIndex = 0;
QStringList translationLanguages("English");
for (int i = 0; i < translationFiles.size(); ++i) {
// get locale extracted by filename
QString locale = translationFiles[i]; // "TranslationExample_de.qm"
const bool bCurrent = locale == currentTranslation;
locale.truncate(locale.lastIndexOf('.')); // "TranslationExample_de"
locale.remove(0, locale.indexOf('_') + 1); // "de"
QString language = QLocale::languageToString(QLocale(locale).language());
if (bCurrent) {
listIndex = i + 1;
}
translationLanguages << language;
}
ui->translationsComboBox->insertItems(0, translationLanguages);
ui->translationsComboBox->setCurrentIndex(listIndex);
}
ConfigDialog::ConfigDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ConfigDialog),
@ -237,6 +273,15 @@ void ConfigDialog::accept()
else if (ui->jpegRadioButton->isChecked())
config.texture.screenShotFormat = 1;
const int lanuageIndex = ui->translationsComboBox->currentIndex();
if (lanuageIndex == 0) // English
config.translationFile.clear();
else {
QStringList translationFiles;
_getTranslations(translationFiles);
config.translationFile = translationFiles[lanuageIndex-1].toLocal8Bit().constData();
}
// Emulation settings
config.generalEmulation.enableLOD = ui->emulateLodCheckBox->isChecked() ? 1 : 0;
config.generalEmulation.enableNoise = ui->emulateNoiseCheckBox->isChecked() ? 1 : 0;

View File

@ -16,7 +16,7 @@ public:
explicit ConfigDialog(QWidget *parent = 0);
~ConfigDialog();
void setIniPath(const QString & _strIniPath) { m_strIniPath = _strIniPath; }
void setIniPath(const QString & _strIniPath);
bool isAccepted() const { return m_accepted; }
public Q_SLOTS:
@ -35,6 +35,7 @@ private slots:
private:
void _init();
void _getTranslations(QStringList & _translationFiles) const;
Ui::ConfigDialog *ui;
QFont m_font;

View File

@ -1,5 +1,6 @@
#include <thread>
#include <QApplication>
#include <QTranslator>
#include "GLideNUI.h"
#include "AboutDialog.h"
@ -26,6 +27,10 @@ int openConfigDialog(const wchar_t * _strFileName, bool & _accepted)
char * argv = 0;
QApplication a(argc, &argv);
QTranslator translator;
if (translator.load(getTranslationFile(), strIniFileName))
a.installTranslator(&translator);
ConfigDialog w;
w.setIniPath(strIniFileName);

View File

@ -13,23 +13,27 @@ TEMPLATE = lib
CONFIG += staticlib
SOURCES += \
ConfigDialog.cpp \
GLideNUI.cpp \
FullscreenResolutions_windows.cpp \
Settings.cpp \
ScreenShot.cpp \
AboutDialog.cpp
ConfigDialog.cpp \
GLideNUI.cpp \
FullscreenResolutions_windows.cpp \
Settings.cpp \
ScreenShot.cpp \
AboutDialog.cpp
HEADERS += \
ConfigDialog.h \
GLideNUI.h \
FullscreenResolutions.h \
Settings.h \
AboutDialog.h
ConfigDialog.h \
GLideNUI.h \
FullscreenResolutions.h \
Settings.h \
AboutDialog.h
RESOURCES += \
icon.qrc
icon.qrc
FORMS += \
configDialog.ui \
AboutDialog.ui
configDialog.ui \
AboutDialog.ui
TRANSLATIONS = gliden64_fr.ts \
gliden64_de.ts \
gliden64_ru.ts

View File

@ -17,6 +17,8 @@ static const char * strCustomSettingsFileName = "GLideN64.custom.ini";
static
void _loadSettings(QSettings & settings)
{
config.translationFile = settings.value("translation", config.translationFile.c_str()).toString().toLocal8Bit().constData();
settings.beginGroup("video");
config.video.fullscreenWidth = settings.value("fullscreenWidth", config.video.fullscreenWidth).toInt();
config.video.fullscreenHeight = settings.value("fullscreenHeight", config.video.fullscreenHeight).toInt();
@ -114,6 +116,8 @@ void writeSettings(const QString & _strIniFolder)
QSettings settings(_strIniFolder + "/" + strIniFileName, QSettings::IniFormat);
settings.setValue("version", config.version);
settings.setValue("translation", config.translationFile.c_str());
settings.beginGroup("video");
settings.setValue("fullscreenWidth", config.video.fullscreenWidth);
settings.setValue("fullscreenHeight", config.video.fullscreenHeight);
@ -226,3 +230,8 @@ void loadCustomRomSettings(const QString & _strIniFolder, const char * _strRomNa
_loadSettings(settings);
settings.endGroup();
}
QString getTranslationFile()
{
return config.translationFile.c_str();
}

View File

@ -4,6 +4,7 @@
void loadSettings(const QString & _strIniFolder);
void writeSettings(const QString & _strIniFolder);
void loadCustomRomSettings(const QString & _strIniFolder, const char * _strRomName);
QString getTranslationFile();
#endif // SETTINGS_H

View File

@ -36,7 +36,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="videoTab">
<attribute name="title">
@ -535,7 +535,7 @@
<item>
<widget class="QLabel" name="label_15">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Language select:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Press the button to invoke language selection dialog. Selected language will be activated after restart of the configuration dialog.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -546,30 +546,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_14">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Language select:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Press the button to invoke language selection dialog. Selected language will be activated after restart of the configuration dialog.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>English</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="selectLangButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Language select:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Press the button to invoke language selection dialog. Selected language will be activated after restart of the configuration dialog.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Change</string>
</property>
</widget>
<widget class="QComboBox" name="translationsComboBox"/>
</item>
</layout>
</item>
@ -1394,10 +1371,10 @@
</connection>
</connections>
<buttongroups>
<buttongroup name="bloomBlendModeButtonGroup"/>
<buttongroup name="bilinearButtonGroup"/>
<buttongroup name="screenshotButtonGroup"/>
<buttongroup name="validityCheckbuttonGroup"/>
<buttongroup name="bilinearButtonGroup"/>
<buttongroup name="bloomBlendModeButtonGroup"/>
<buttongroup name="aspectButtonGroup"/>
</buttongroups>
</ui>