Clean up/update translation code and made language selectable in the settings dialog
This commit is contained in:
parent
9bbbb05060
commit
7f6b344b49
30
MultiMC.cpp
30
MultiMC.cpp
@ -54,8 +54,6 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override)
|
|||||||
setOrganizationName("MultiMC");
|
setOrganizationName("MultiMC");
|
||||||
setApplicationName("MultiMC5");
|
setApplicationName("MultiMC5");
|
||||||
|
|
||||||
initTranslations();
|
|
||||||
|
|
||||||
setAttribute(Qt::AA_UseHighDpiPixmaps);
|
setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
// Don't quit on hiding the last window
|
// Don't quit on hiding the last window
|
||||||
this->setQuitOnLastWindowClosed(false);
|
this->setQuitOnLastWindowClosed(false);
|
||||||
@ -179,6 +177,9 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override)
|
|||||||
// load settings
|
// load settings
|
||||||
initGlobalSettings();
|
initGlobalSettings();
|
||||||
|
|
||||||
|
// load translations
|
||||||
|
initTranslations();
|
||||||
|
|
||||||
// initialize the updater
|
// initialize the updater
|
||||||
m_updateChecker.reset(new UpdateChecker());
|
m_updateChecker.reset(new UpdateChecker());
|
||||||
|
|
||||||
@ -281,18 +282,20 @@ MultiMC::~MultiMC()
|
|||||||
|
|
||||||
void MultiMC::initTranslations()
|
void MultiMC::initTranslations()
|
||||||
{
|
{
|
||||||
|
QLocale locale(m_settings->get("Language").toString());
|
||||||
|
QLocale::setDefault(locale);
|
||||||
|
QLOG_INFO() << "Your language is" << locale.bcp47Name();
|
||||||
m_qt_translator.reset(new QTranslator());
|
m_qt_translator.reset(new QTranslator());
|
||||||
if (m_qt_translator->load("qt_" + QLocale::system().name(),
|
if (m_qt_translator->load("qt_" + locale.bcp47Name(),
|
||||||
QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
||||||
{
|
{
|
||||||
std::cout << "Loading Qt Language File for "
|
QLOG_DEBUG() << "Loading Qt Language File for"
|
||||||
<< QLocale::system().name().toLocal8Bit().constData() << "...";
|
<< locale.bcp47Name().toLocal8Bit().constData() << "...";
|
||||||
if (!installTranslator(m_qt_translator.get()))
|
if (!installTranslator(m_qt_translator.get()))
|
||||||
{
|
{
|
||||||
std::cout << " failed.";
|
QLOG_ERROR() << "Loading Qt Language File failed.";
|
||||||
m_qt_translator.reset();
|
m_qt_translator.reset();
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -300,17 +303,15 @@ void MultiMC::initTranslations()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_mmc_translator.reset(new QTranslator());
|
m_mmc_translator.reset(new QTranslator());
|
||||||
if (m_mmc_translator->load("mmc_" + QLocale::system().name(),
|
if (m_mmc_translator->load("mmc_" + locale.bcp47Name(), MMC->root() + "/translations"))
|
||||||
QDir("translations").absolutePath()))
|
|
||||||
{
|
{
|
||||||
std::cout << "Loading MMC Language File for "
|
QLOG_DEBUG() << "Loading MMC Language File for"
|
||||||
<< QLocale::system().name().toLocal8Bit().constData() << "...";
|
<< locale.bcp47Name().toLocal8Bit().constData() << "...";
|
||||||
if (!installTranslator(m_mmc_translator.get()))
|
if (!installTranslator(m_mmc_translator.get()))
|
||||||
{
|
{
|
||||||
std::cout << " failed.";
|
QLOG_ERROR() << "Loading MMC Language File failed.";
|
||||||
m_mmc_translator.reset();
|
m_mmc_translator.reset();
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -410,6 +411,9 @@ void MultiMC::initGlobalSettings()
|
|||||||
// Editors
|
// Editors
|
||||||
m_settings->registerSetting("JsonEditor", QString());
|
m_settings->registerSetting("JsonEditor", QString());
|
||||||
|
|
||||||
|
// Language
|
||||||
|
m_settings->registerSetting("Language", QLocale(QLocale::system().language()).bcp47Name());
|
||||||
|
|
||||||
// Console
|
// Console
|
||||||
m_settings->registerSetting("ShowConsole", true);
|
m_settings->registerSetting("ShowConsole", true);
|
||||||
m_settings->registerSetting("AutoCloseConsole", true);
|
m_settings->registerSetting("AutoCloseConsole", true);
|
||||||
|
@ -219,6 +219,9 @@ void SettingsDialog::applySettings(SettingsObject *s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Language
|
||||||
|
s->set("Language", ui->languageBox->currentData().toLocale().bcp47Name());
|
||||||
|
|
||||||
// Updates
|
// Updates
|
||||||
s->set("AutoUpdate", ui->autoUpdateCheckBox->isChecked());
|
s->set("AutoUpdate", ui->autoUpdateCheckBox->isChecked());
|
||||||
|
|
||||||
@ -286,6 +289,19 @@ void SettingsDialog::applySettings(SettingsObject *s)
|
|||||||
|
|
||||||
void SettingsDialog::loadSettings(SettingsObject *s)
|
void SettingsDialog::loadSettings(SettingsObject *s)
|
||||||
{
|
{
|
||||||
|
// Language
|
||||||
|
ui->languageBox->clear();
|
||||||
|
ui->languageBox->addItem(tr("English"), QLocale(QLocale::English));
|
||||||
|
foreach(const QString & lang,
|
||||||
|
QDir(MMC->root() + "/translations").entryList(QStringList() << "*.qm", QDir::Files))
|
||||||
|
{
|
||||||
|
QLocale locale(lang.section(QRegExp("[_\.]"), 1));
|
||||||
|
ui->languageBox->addItem(
|
||||||
|
QLocale::languageToString(locale.language()),
|
||||||
|
locale);
|
||||||
|
}
|
||||||
|
ui->languageBox->setCurrentIndex(ui->languageBox->findData(QLocale(s->get("Language").toString())));
|
||||||
|
|
||||||
// Updates
|
// Updates
|
||||||
ui->autoUpdateCheckBox->setChecked(s->get("AutoUpdate").toBool());
|
ui->autoUpdateCheckBox->setChecked(s->get("AutoUpdate").toBool());
|
||||||
ui->devBuildsCheckBox->setChecked(s->get("UseDevBuilds").toBool());
|
ui->devBuildsCheckBox->setChecked(s->get("UseDevBuilds").toBool());
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>526</width>
|
<width>526</width>
|
||||||
<height>628</height>
|
<height>701</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -40,6 +40,20 @@
|
|||||||
<string>General</string>
|
<string>General</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Language (needs restart):</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="languageBox"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="sortingModeBox">
|
<widget class="QGroupBox" name="sortingModeBox">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
@ -644,7 +658,6 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>settingsTab</tabstop>
|
|
||||||
<tabstop>buttonBox</tabstop>
|
<tabstop>buttonBox</tabstop>
|
||||||
<tabstop>sortLastLaunchedBtn</tabstop>
|
<tabstop>sortLastLaunchedBtn</tabstop>
|
||||||
<tabstop>sortByNameBtn</tabstop>
|
<tabstop>sortByNameBtn</tabstop>
|
||||||
|
Loading…
Reference in New Issue
Block a user