NOISSUE fix translation listing in settings and translation loading
It was impossible to select and load translations properly.
This commit is contained in:
parent
7a14b63957
commit
295c6e808a
@ -406,15 +406,17 @@ void MultiMC::initNetwork()
|
||||
|
||||
void MultiMC::initTranslations()
|
||||
{
|
||||
QLocale locale(m_settings->get("Language").toString());
|
||||
auto bcp47Name = m_settings->get("Language").toString();
|
||||
QLocale locale(bcp47Name);
|
||||
QLocale::setDefault(locale);
|
||||
qDebug() << "Your language is" << locale.bcp47Name();
|
||||
qDebug() << "Your language is" << bcp47Name;
|
||||
// FIXME: this is likely never present.
|
||||
m_qt_translator.reset(new QTranslator());
|
||||
if (m_qt_translator->load("qt_" + locale.bcp47Name(),
|
||||
if (m_qt_translator->load("qt_" + bcp47Name,
|
||||
QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
||||
{
|
||||
qDebug() << "Loading Qt Language File for"
|
||||
<< locale.bcp47Name().toLocal8Bit().constData() << "...";
|
||||
<< bcp47Name.toLocal8Bit().constData() << "...";
|
||||
if (!installTranslator(m_qt_translator.get()))
|
||||
{
|
||||
qCritical() << "Loading Qt Language File failed.";
|
||||
@ -427,10 +429,10 @@ void MultiMC::initTranslations()
|
||||
}
|
||||
|
||||
m_mmc_translator.reset(new QTranslator());
|
||||
if (m_mmc_translator->load("mmc_" + locale.bcp47Name(), FS::PathCombine(QDir::currentPath(), "translations")))
|
||||
if (m_mmc_translator->load("mmc_" + bcp47Name, FS::PathCombine(QDir::currentPath(), "translations")))
|
||||
{
|
||||
qDebug() << "Loading MMC Language File for"
|
||||
<< locale.bcp47Name().toLocal8Bit().constData() << "...";
|
||||
<< bcp47Name.toLocal8Bit().constData() << "...";
|
||||
if (!installTranslator(m_mmc_translator.get()))
|
||||
{
|
||||
qCritical() << "Loading MMC Language File failed.";
|
||||
|
@ -262,8 +262,7 @@ void MultiMCPage::applySettings()
|
||||
auto s = MMC->settings();
|
||||
|
||||
// Language
|
||||
s->set("Language",
|
||||
ui->languageBox->itemData(ui->languageBox->currentIndex()).toLocale().bcp47Name());
|
||||
s->set("Language", ui->languageBox->itemData(ui->languageBox->currentIndex()).toString());
|
||||
|
||||
if (ui->resetNotificationsBtn->isChecked())
|
||||
{
|
||||
@ -352,15 +351,32 @@ void MultiMCPage::loadSettings()
|
||||
{
|
||||
auto s = MMC->settings();
|
||||
// Language
|
||||
ui->languageBox->clear();
|
||||
ui->languageBox->addItem(tr("English"), QLocale(QLocale::English));
|
||||
for(const QString & lang: QDir("translations").entryList(QStringList() << "*.qm", QDir::Files))
|
||||
{
|
||||
QLocale locale(lang.section(QRegExp("[_\\.]"), 1));
|
||||
ui->languageBox->addItem(QLocale::languageToString(locale.language()), locale);
|
||||
using LanguageItem = std::pair<QString, QString>;
|
||||
std::vector<LanguageItem> items;
|
||||
|
||||
QLocale english("en");
|
||||
items.push_back(std::make_pair(english.nativeLanguageName(), "en"));
|
||||
for(QString lang: QDir("translations").entryList(QStringList() << "*.qm", QDir::Files))
|
||||
{
|
||||
lang.remove(".qm");
|
||||
lang.remove("mmc_");
|
||||
QLocale locale(lang);
|
||||
QString fullLangName = locale.nativeLanguageName();
|
||||
qDebug() << fullLangName << lang;
|
||||
items.push_back(std::make_pair(fullLangName, lang));
|
||||
}
|
||||
std::sort(items.begin(), items.end(), [](const LanguageItem & a, const LanguageItem & b)
|
||||
{
|
||||
return a.first.localeAwareCompare(b.first) < 0;
|
||||
});
|
||||
ui->languageBox->clear();
|
||||
for(auto & item: items)
|
||||
{
|
||||
ui->languageBox->addItem(item.first, item.second);
|
||||
}
|
||||
ui->languageBox->setCurrentIndex(ui->languageBox->findData(s->get("Language").toString()));
|
||||
}
|
||||
ui->languageBox->setCurrentIndex(
|
||||
ui->languageBox->findData(QLocale(s->get("Language").toString())));
|
||||
|
||||
// Updates
|
||||
ui->autoUpdateCheckBox->setChecked(s->get("AutoUpdate").toBool());
|
||||
|
Loading…
Reference in New Issue
Block a user