Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Apr 17, 2025

Configure name retrieval in three levels

fix-Bug-translation

Summary by Sourcery

Improve language translation handling for desktop file parsing by adding a more flexible language code matching mechanism

Bug Fixes:

  • Enhance language translation retrieval to handle language codes with region specifiers (e.g., en_US) by falling back to base language code (en) if an exact match is not found

Enhancements:

  • Introduce a new method getLocaleName() to provide more robust language code matching for application names, actions, and generic names

@sourcery-ai
Copy link

sourcery-ai bot commented Apr 17, 2025

Reviewer's Guide by Sourcery

This pull request introduces a fallback mechanism for retrieving localized names within the DesktopFileAMParser class. It configures name retrieval in three levels: first, it attempts to match the full locale name; second, if the first fails and the locale name contains a country code, it attempts to match only the language code; and third, if both of the previous attempts fail, it falls back to the default name. This change improves the application's ability to find the correct translation based on the system's locale.

Sequence diagram for localized name retrieval

sequenceDiagram
  participant DesktopFileAMParser
  participant QLocale
  participant ApplicationInterface

  DesktopFileAMParser->>QLocale: system().name()
  QLocale-->>DesktopFileAMParser: currentLanguageCode
  DesktopFileAMParser->>ApplicationInterface: name()
  ApplicationInterface-->>DesktopFileAMParser: names
  DesktopFileAMParser->>DesktopFileAMParser: getLocaleName(currentLanguageCode, names)
  alt currentLanguageCode contains country code AND names does not contain currentLanguageCode
    DesktopFileAMParser->>DesktopFileAMParser: prefix = currentLanguageCode.split('_')[0]
    alt names contains prefix
      DesktopFileAMParser->>ApplicationInterface: names.value(prefix)
      ApplicationInterface-->>DesktopFileAMParser: localeName = names.value(prefix)
    else names does not contain prefix
      DesktopFileAMParser->>ApplicationInterface: names.value(currentLanguageCode)
      ApplicationInterface-->>DesktopFileAMParser: localeName = names.value(currentLanguageCode)
    end
  else currentLanguageCode does not contain country code OR names contains currentLanguageCode
    DesktopFileAMParser->>ApplicationInterface: names.value(currentLanguageCode)
    ApplicationInterface-->>DesktopFileAMParser: localeName = names.value(currentLanguageCode)
  end
  DesktopFileAMParser-->>DesktopFileAMParser: return localeName
  alt localeName.isEmpty()
    DesktopFileAMParser->>ApplicationInterface: names.value(DEFAULT_KEY)
    ApplicationInterface-->>DesktopFileAMParser: fallbackName
    DesktopFileAMParser-->>DesktopFileAMParser: m_name = fallbackName
  else localeName is not empty
    DesktopFileAMParser-->>DesktopFileAMParser: m_name = localeName
  end
Loading

File-Level Changes

Change Details Files
Implemented a three-level fallback mechanism for retrieving localized names in DesktopFileAMParser.
  • Added a getLocaleName method to handle the name retrieval logic.
  • Modified updateActions, updateLocalName, and updateLocalGenericName to use the new getLocaleName method.
  • The getLocaleName method first checks for an exact match of the current language code.
  • If an exact match is not found and the language code contains a country code, it checks for a match with just the language prefix.
  • If no match is found at either of the above levels, it returns an empty string, which will trigger the fallback to the default name.
panels/dock/taskmanager/desktopfileamparser.cpp
panels/dock/taskmanager/desktopfileamparser.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @wjyrich - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider extracting the language code retrieval to a separate method for better readability.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

wjyrich added a commit to wjyrich/dde-shell that referenced this pull request Apr 17, 2025
…deepin#1100

Configure name retrieval in three levels

fix-Bug-translation
wjyrich added a commit to wjyrich/dde-shell that referenced this pull request Apr 17, 2025
…deepin#1100

Configure name retrieval in three levels

fix-Bug-translation
@wjyrich wjyrich force-pushed the fix-bug-translation branch from 69273dc to 2fe3b01 Compare April 17, 2025 04:04
wjyrich added a commit to wjyrich/dde-shell that referenced this pull request Apr 17, 2025
…deepin#1100

Configure name retrieval in three levels

fix-Bug-translation
@wjyrich wjyrich force-pushed the fix-bug-translation branch from 2fe3b01 to 569d5f7 Compare April 17, 2025 04:07
wjyrich added a commit to wjyrich/dde-shell that referenced this pull request Apr 17, 2025
…deepin#1100

Configure name retrieval in three levels

fix-Bug-translation
@wjyrich wjyrich force-pushed the fix-bug-translation branch from 569d5f7 to a4c9f03 Compare April 17, 2025 04:10
wjyrich added a commit to wjyrich/dde-shell that referenced this pull request Apr 17, 2025
…deepin#1100

Configure name retrieval in three levels

fix-Bug-translation
@wjyrich wjyrich force-pushed the fix-bug-translation branch from a4c9f03 to 4ef0d8d Compare April 17, 2025 04:16
wjyrich added a commit to wjyrich/dde-shell that referenced this pull request Apr 17, 2025
…deepin#1100

Configure name retrieval in three levels

fix-Bug-translation
@wjyrich wjyrich force-pushed the fix-bug-translation branch from 4ef0d8d to 2cd2584 Compare April 17, 2025 04:19
yixinshark pushed a commit to wjyrich/dde-shell that referenced this pull request Apr 17, 2025
…deepin#1100

Configure name retrieval in three levels

fix-Bug-translation
@yixinshark yixinshark force-pushed the fix-bug-translation branch from 2cd2584 to 5e474b8 Compare April 17, 2025 09:23
QString DesktopFileAMParser::getLocaleName(const QString& currentLanguageCode, const QStringMap& names)
{
auto localeName = names.value(currentLanguageCode);
if( currentLanguageCode.contains('_') && !(names.contains(currentLanguageCode)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (currentLanguageCode.contains('_')

yixinshark pushed a commit that referenced this pull request Apr 17, 2025
Configure name retrieval in three levels

fix-Bug-translation
@github-actions
Copy link

github-actions bot commented Apr 17, 2025

CLA Assistant Lite bot:

如果你是以企业贡献者的身份进行提交,请联系我们签署企业贡献者许可协议
If you submit as corporate contributor, please contact us to sign our Corporate Contributor License Agreement

感谢您的提交,我们非常感谢。 像许多开源项目一样,在接受您的贡献之前,我们要求您签署我们的个人贡献者许可协议。 您只需发布与以下格式相同的评论即可签署个人贡献者许可协议
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Individual Contributor License Agreement before we can accept your contribution. You can sign the Individual Contributor License Agreement by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA.

1 out of 2 committers have signed the CLA.
@wjyrich
@yixinshark
You can retrigger this bot by commenting recheck in this Pull Request

@yixinshark yixinshark force-pushed the fix-bug-translation branch from 6eb57a2 to e7d9e9d Compare April 17, 2025 09:51
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. 代码重复getLocaleName函数在updateLocalNameupdateLocalGenericName中被重复调用,可以考虑将这部分逻辑提取到一个公共函数中,以减少代码重复。

  2. 错误处理getLocaleName函数中,如果currentLanguageCode不包含下划线或者names不包含currentLanguageCodeprefixlocaleName将保持为names.value(currentLanguageCode)的值,这可能不是预期的行为。建议添加错误处理逻辑,例如返回一个默认值或者抛出异常。

  3. 性能优化:在getLocaleName函数中,currentLanguageCode.split('_')[0]每次调用都会创建一个新的QString对象,如果这个函数被频繁调用,可能会导致性能问题。可以考虑将prefix缓存起来,避免重复计算。

  4. 代码可读性getLocaleName函数中的条件判断逻辑可以进一步优化,以提高代码的可读性。例如,可以将条件判断逻辑提取到单独的函数中,或者使用更清晰的变量名。

  5. 注释缺失getLocaleName函数缺少注释,应该添加注释说明函数的用途、参数和返回值。

  6. 默认值问题:在updateActions函数中,如果localeName为空,则使用fallbackDefaultName作为默认值。但是,如果fallbackDefaultName也为空,则m_actions.append可能会添加一个无效的Action对象。建议在添加Action对象之前检查fallbackDefaultName是否为空。

  7. 命名规范getLocaleName函数的参数names应该使用更具描述性的名称,例如nameMap,以提高代码的可读性。

综上所述,建议对代码进行重构,以提高代码质量、可读性和性能。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wjyrich, yixinshark

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@yixinshark
Copy link
Contributor

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Apr 17, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 6fb0275 into linuxdeepin:master Apr 17, 2025
5 of 10 checks passed
deepin-bot bot pushed a commit that referenced this pull request Apr 17, 2025
Configure name retrieval in three levels

fix-Bug-translation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants