Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Incorrect language modification prompt #1041

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@
+ QDir::separator() + "deepin-unioncode.json";

Settings settings("", configFile);
auto map = settings.value("General", "Language").toMap();

Check warning on line 75 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'map' shadows outer variable

Check warning on line 75 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Local variable 'map' shadows outer variable
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
Loading