Skip to content

Fix: [translate] Add translate for storage type.#612

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
GongHeng2017:202603031556-dev-eagle-fix
Mar 3, 2026
Merged

Fix: [translate] Add translate for storage type.#612
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
GongHeng2017:202603031556-dev-eagle-fix

Conversation

@GongHeng2017
Copy link
Contributor

--Add transalte for storage type.

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-350425.html

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.

Sorry @GongHeng2017, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要对 DeviceInfo.cpp 中的翻译字符串处理方式进行了优化,并添加了几个新的翻译项。以下是对代码的详细审查和改进建议:

1. 语法逻辑

优点:

  • 将原来的 QStringList 配合 tr() 的方式改为使用 QT_TR_NOOP() 宏的静态数组,这是正确的做法。
  • 使用 Q_UNUSED 宏来避免编译器警告,这是正确的做法。
  • 新增的翻译字符串(Unknown, SSD, HDD)格式正确,与现有代码风格一致。

建议:

  • DeviceInfo.cpp 中,translationStrings 数组定义为 static const char* const,这是很好的做法,因为它确保了字符串字面量的不可变性。但可以考虑使用 QLatin1StringQStringLiteral 来进一步优化(见性能部分)。

2. 代码质量

优点:

  • 代码风格统一,缩进和格式规范。
  • 注释清晰,说明了代码的目的。
  • 使用了 QT_TR_NOOP() 宏来标记需要翻译的字符串,这是 Qt 推荐的做法。

建议:

  • 虽然使用了 QT_TR_NOOP(),但代码中仍然保留了 generatorTranslate() 函数。这个函数的唯一目的是为了触发 lupdate 工具提取翻译字符串。可以考虑使用更明确的方式,比如将这些字符串放在一个专门的翻译文件中,或者使用 Qt 的翻译系统提供的其他机制。

3. 代码性能

优点:

  • 使用 QT_TR_NOOP() 宏避免了运行时构造 QStringList 和调用 tr() 函数的开销。
  • 将字符串数组定义为 static const,确保了在程序运行期间只初始化一次。

建议:

  • 可以考虑使用 QStringLiteral 来替代 QT_TR_NOOP(),这样可以进一步减少运行时字符串构造的开销。例如:
    static const char* const translationStrings[] = {
        QT_TRANSLATE_NOOP("Context", "Core(s)"),
        QT_TRANSLATE_NOOP("Context", "Processor"),
        // ...
    };
    这样可以在需要翻译时使用 QCoreApplication::translate("Context", "Core(s)") 来获取翻译后的字符串。

4. 代码安全

优点:

  • 没有明显的安全隐患。
  • 字符串字面量是静态的,不会导致缓冲区溢出或其他内存问题。

建议:

  • 确保所有翻译字符串都正确地使用了 QT_TR_NOOP()QT_TRANSLATE_NOOP() 宏,避免遗漏。

5. 其他建议

  • 翻译上下文:当前的翻译字符串没有明确的上下文(context),这可能导致某些翻译在不同上下文中出现歧义。建议使用 QT_TRANSLATE_NOOP("Context", "String") 来为翻译字符串添加上下文。
  • 代码组织:如果翻译字符串数量继续增加,可以考虑将它们移到一个单独的头文件中,以保持 DeviceInfo.cpp 的简洁性。

总结

这段代码的改进是积极的,主要优化了翻译字符串的处理方式,提高了性能和代码质量。建议进一步考虑使用 QT_TRANSLATE_NOOP() 来添加翻译上下文,以及使用 QStringLiteral 来进一步优化性能。整体上,代码是安全、规范且高效的。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, GongHeng2017, max-lvs

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

@GongHeng2017
Copy link
Contributor Author

/merge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Mar 3, 2026

This pr cannot be merged! (status: unstable)

@GongHeng2017
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Mar 3, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 1aa47ca into linuxdeepin:develop/eagle Mar 3, 2026
16 of 17 checks passed
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