diff --git a/src/app/main.cpp b/src/app/main.cpp index 8c5dde769..49f1ea959 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -74,8 +74,12 @@ void installTranslator(DApplication &a) Settings settings("", configFile); auto map = settings.value("General", "Language").toMap(); QString language = map.value("path").toString(); - if (language.isEmpty()) + if (language.isEmpty()) { language = QLocale().name() + ".qm"; + QVariantMap map; + map.insert("path", language); + settings.setValue("General", "Language", map); + } QString name = language.left(language.indexOf(".")); a.loadTranslator(QList() << QLocale(name)); diff --git a/src/plugins/option/optioncore/mainframe/profilesettingwidget.cpp b/src/plugins/option/optioncore/mainframe/profilesettingwidget.cpp index 89b6c9baa..ef3f66dbf 100644 --- a/src/plugins/option/optioncore/mainframe/profilesettingwidget.cpp +++ b/src/plugins/option/optioncore/mainframe/profilesettingwidget.cpp @@ -66,11 +66,17 @@ void ProfileSettingWidget::saveConfig() { QVariantMap map = OptionManager::getInstance()->getValue(kGeneralGroup, kLanguageKey).toMap(); auto languageName = d->cbChooseLanguage->currentText(); - if (map.value(kName) == languageName) + auto path = d->cbChooseLanguage->currentData().toString(); + if (map.value(kName) == languageName) { return; + } else if (map.value(kPath) == path) { + map.insert(kName, languageName); + OptionManager::getInstance()->setValue(kGeneralGroup, kLanguageKey, map); + return; + } map.insert(kName, languageName); - map.insert(kPath, d->languagePaths.value(languageName)); + map.insert(kPath, path); OptionManager::getInstance()->setValue(kGeneralGroup, kLanguageKey, map); DDialog msgBox; @@ -99,6 +105,10 @@ void ProfileSettingWidget::readConfig() } else { const auto &map = OptionManager::getInstance()->getValue(kGeneralGroup, kLanguageKey).toMap(); languageName = map.value(kName).toString(); + if (languageName.isEmpty()) { + auto path = map.value(kPath).toString(); + languageName = d->languagePaths.key(path); + } } d->cbChooseLanguage->setCurrentText(languageName); @@ -121,11 +131,9 @@ void ProfileSettingWidget::setupUi() d->cbChooseLanguage = new DComboBox(); d->cbChooseLanguage->setFixedWidth(200); - QStringList nameList = d->languagePaths.keys(); - int i = 0; - for (auto name : nameList) { - d->cbChooseLanguage->insertItem(i, name); - i++; + auto iter = d->languagePaths.cbegin(); + for (; iter != d->languagePaths.cend(); ++iter) { + d->cbChooseLanguage->addItem(iter.key(), iter.value()); } d->hlayout->setMargin(10);