-
Notifications
You must be signed in to change notification settings - Fork 55
fix: desktop menu actions shows English instead of locale language #1261
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
Conversation
任务栏右键菜单,应用自己的 action 未显示成当前用户的系统语言对应的文案 PMS: BUG-333955 Log:
deepin pr auto review我对这段代码进行了仔细审查,以下是我的分析和改进建议: 1. 语法逻辑问题:
改进建议:
2. 代码质量问题:
改进建议:
示例改进: QString AMAppItem::getLocaleOrDefaultValue(const QStringMap &value, const QString &preferredLocale, const QString &fallbackKey)
{
Q_ASSERT_X(!value.isEmpty(), "getLocaleOrDefaultValue", "Value map cannot be empty");
Q_ASSERT_X(!fallbackKey.isEmpty(), "getLocaleOrDefaultValue", "Fallback key cannot be empty");
if (value.contains(preferredLocale)) {
return value.value(preferredLocale);
}
// 处理带区域设置的locale(如zh_CN)
if (preferredLocale.contains('_')) {
QString baseLocale = preferredLocale.split('_').first();
if (value.contains(baseLocale)) {
return value.value(baseLocale);
}
}
return value.value(fallbackKey);
}3. 代码性能问题:
改进建议:
4. 代码安全问题:
改进建议:
示例改进: QString AMAppItem::getLocaleOrDefaultValue(const QStringMap &value, const QString &preferredLocale, const QString &fallbackKey)
{
// 参数验证
if (value.isEmpty() || fallbackKey.isEmpty()) {
return QString();
}
// 检查首选locale是否存在
if (value.contains(preferredLocale)) {
return value.value(preferredLocale);
}
// 安全地处理带区域设置的locale
if (!preferredLocale.isEmpty() && preferredLocale.contains('_')) {
QStringList localeParts = preferredLocale.split('_', Qt::SkipEmptyParts);
if (!localeParts.isEmpty()) {
QString baseLocale = localeParts.first();
if (value.contains(baseLocale)) {
return value.value(baseLocale);
}
}
}
// 返回fallback值
return value.value(fallbackKey);
}5. 其他建议
这些改进将有助于提高代码的可维护性、可读性和健壮性。 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnhance locale resolution for desktop menu actions and application icons by refactoring utility logic, updating method parameters, and simplifying lookups to ensure UI labels match the user’s current language settings. Class diagram for updated AMAppItem locale resolution methodsclassDiagram
class AMAppItem {
+void setOnDesktop(bool on)
-QString getLocaleOrDefaultValue(const QStringMap &value, const QString &localeCode, const QString &fallbackKey)
-void updateActions(const QStringList &actions, const PropMap &actionName)
}
AMAppItem --|> Application
AMAppItem --|> AppItem
Flow diagram for locale-based action name resolutionflowchart TD
A["User triggers desktop menu action"] --> B["updateActions() called"]
B --> C["getLocaleOrDefaultValue() called with locale code"]
C --> D{Does value contain localeCode?}
D -- Yes --> E["Return value for localeCode"]
D -- No --> F{Does localeCode contain '_'?}
F -- Yes --> G["Extract prefix and check value for prefix"]
G -- Found --> H["Return value for prefix"]
G -- Not found --> I["Return fallback value"]
F -- No --> I["Return fallback value"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, BLumia The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
任务栏右键菜单,应用自己的 action 未显示成当前用户的系统语言对应的文案
Summary by Sourcery
Update AMAppItem localization logic to ensure desktop menu actions and icons display in the current user's locale
Bug Fixes:
Enhancements: