Skip to content

Commit

Permalink
fix: Incorrect language modification prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakueeen authored and deepin-mozart committed Jan 6, 2025
1 parent eb9bf5f commit 64af9a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>() << QLocale(name));
Expand Down
22 changes: 15 additions & 7 deletions src/plugins/option/optioncore/mainframe/profilesettingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 64af9a3

Please sign in to comment.