Skip to content

chore: [translate] support lupdate auto#556

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
add-uos:master
Nov 28, 2025
Merged

chore: [translate] support lupdate auto#556
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
add-uos:master

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Nov 28, 2025

support lupdate auto

Log: support lupdate auto

Bug: https://pms.uniontech.com/task-view-368603.html

Summary by Sourcery

Enhancements:

  • Introduce a generatorTranslate helper in DeviceBaseInfo that centralizes translatable device information strings for automatic extraction by lupdate.

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 28, 2025

Reviewer's Guide

Adds a private helper method to DeviceBaseInfo that collects all device-related user-visible strings into tr() calls so Qt lupdate can automatically pick them up for translation, without changing runtime behavior.

File-Level Changes

Change Details Files
Add a private translation helper method to aggregate all device-related strings into tr() calls for lupdate.
  • Introduce DeviceBaseInfo::generatorTranslate() that builds a QStringList populated with many tr("...") calls for device information labels and properties
  • Mark generatorTranslate() as a private method in the DeviceBaseInfo class interface
  • Ensure the method is currently unused at runtime and serves solely as an lupdate placeholder to generate translation entries
deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp
deepin-devicemanager/src/DeviceManager/DeviceInfo.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!

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

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个代码变更进行审查:

  1. 代码功能:
    这段代码添加了一个新的私有方法 generatorTranslate(),主要用于生成翻译字符串,以便 lupdate 工具能够自动提取这些字符串用于国际化。

  2. 语法和逻辑:

  • 语法正确,没有明显的语法错误
  • 使用了 Qt 的 tr() 函数来标记需要翻译的字符串
  • 使用了 QStringList 来存储所有翻译字符串
  1. 代码质量改进建议:

a) 代码组织:

  • 建议将翻译字符串移到单独的 .cpp 文件中,而不是放在类的实现文件中
  • 可以考虑将翻译字符串按照功能模块分组,提高可维护性

b) 性能优化:

  • 当前方法每次调用都会创建一个新的 QStringList,但实际上这个方法可能只需要在初始化时调用一次
  • 建议将 translationStrings 设为静态变量,避免重复创建

c) 安全性:

  • 没有明显的安全问题

d) 可维护性:

  • 建议添加注释说明这些翻译字符串的用途
  • 可以考虑使用更结构化的方式组织翻译字符串,比如使用枚举或常量来索引
  1. 改进后的代码建议:
// 在 DeviceInfo.h 中
private:
    static void generatorTranslate();

// 在 DeviceInfo.cpp 中
void DeviceBaseInfo::generatorTranslate()
{
    // 这些字符串用于设备信息的国际化显示
    static const QStringList translationStrings = {
        tr("Core(s)"),
        tr("Processor"),
        // ... 其他翻译字符串
        tr("Processor")
    };
    
    // 避免编译器警告,实际不需要使用这些字符串
    Q_UNUSED(translationStrings);
}
  1. 其他建议:
  • 考虑使用宏或工具自动生成这些翻译字符串,减少手动维护的工作量
  • 可以添加单元测试来验证所有翻译字符串都能正确提取
  • 考虑添加文档说明翻译字符串的使用规范

总的来说,这个变更实现了其预期功能,但在代码组织和可维护性方面还有改进空间。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

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

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 there - I've reviewed your changes - here's some feedback:

  • The private generatorTranslate() method is never called; consider using QT_TRANSLATE_NOOP/QT_TR_NOOP macros or a dedicated translation context instead of a dead member function to register strings for lupdate.
  • Inside generatorTranslate(), translationStrings is constructed but never used, which may trigger warnings; either mark it with Q_UNUSED(translationStrings) or refactor to a compile-time only mechanism for translation extraction.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The private `generatorTranslate()` method is never called; consider using `QT_TRANSLATE_NOOP`/`QT_TR_NOOP` macros or a dedicated translation context instead of a dead member function to register strings for `lupdate`.
- Inside `generatorTranslate()`, `translationStrings` is constructed but never used, which may trigger warnings; either mark it with `Q_UNUSED(translationStrings)` or refactor to a compile-time only mechanism for translation extraction.

## Individual Comments

### Comment 1
<location> `deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp:1178-1180` </location>
<code_context>
 }
-
+//只是为了lupdate自动增加翻译而占位
+void DeviceBaseInfo::generatorTranslate()
+{
+    QStringList translationStrings;
+    translationStrings \
+    <<  tr("Core(s)") \
</code_context>

<issue_to_address>
**suggestion:** Avoid allocating an unused QStringList when only triggering lupdate; use simple tr() calls instead.

Given this is only for lupdate, you can replace the list construction with a simple sequence of `tr("...");` calls (optionally wrapped in `if (false)` or `#if 0`) so lupdate still sees the strings without runtime work. If you do keep the `QStringList`, consider adding `Q_UNUSED(translationStrings)` to avoid unused-variable warnings.

Suggested implementation:

```cpp
 //只是为了lupdate自动增加翻译而占位
void DeviceBaseInfo::generatorTranslate()
{
    // Only for lupdate: ensure these strings are picked up without doing runtime work
    if (false) {
        tr("Core(s)");
        tr("Processor");
        tr("ACL MTU");
        tr("Address");
        tr("Alias");
        tr("ansiversion");
        tr("Application");
        tr("Architecture");
        tr("Array Handle");
        tr("Asset Tag");
        tr("Auto Negotiation");

```

The original code snippet is truncated; there are likely additional `<< tr("...") \` entries following `"Auto Negotiation"`.  
You should:
1. Continue the pattern inside the `if (false) { ... }` block, adding a `tr("...");` line for each of the remaining strings that were originally in the `QStringList`.
2. Ensure the `if (false)` block is properly closed with a `}` and that the `generatorTranslate()` function itself is closed with a final `}` after the block.
This will keep lupdate behavior intact while avoiding allocation of an unused `QStringList` and eliminating unused-variable warnings.
</issue_to_address>

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.

Comment on lines +1178 to +1180
void DeviceBaseInfo::generatorTranslate()
{
QStringList translationStrings;
Copy link

Choose a reason for hiding this comment

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

suggestion: Avoid allocating an unused QStringList when only triggering lupdate; use simple tr() calls instead.

Given this is only for lupdate, you can replace the list construction with a simple sequence of tr("..."); calls (optionally wrapped in if (false) or #if 0) so lupdate still sees the strings without runtime work. If you do keep the QStringList, consider adding Q_UNUSED(translationStrings) to avoid unused-variable warnings.

Suggested implementation:

 //只是为了lupdate自动增加翻译而占位
void DeviceBaseInfo::generatorTranslate()
{
    // Only for lupdate: ensure these strings are picked up without doing runtime work
    if (false) {
        tr("Core(s)");
        tr("Processor");
        tr("ACL MTU");
        tr("Address");
        tr("Alias");
        tr("ansiversion");
        tr("Application");
        tr("Architecture");
        tr("Array Handle");
        tr("Asset Tag");
        tr("Auto Negotiation");

The original code snippet is truncated; there are likely additional << tr("...") \ entries following "Auto Negotiation".
You should:

  1. Continue the pattern inside the if (false) { ... } block, adding a tr("..."); line for each of the remaining strings that were originally in the QStringList.
  2. Ensure the if (false) block is properly closed with a } and that the generatorTranslate() function itself is closed with a final } after the block.
    This will keep lupdate behavior intact while avoiding allocation of an unused QStringList and eliminating unused-variable warnings.

@add-uos
Copy link
Contributor Author

add-uos commented Nov 28, 2025

/merge

@deepin-bot deepin-bot bot merged commit 0dcb032 into linuxdeepin:master Nov 28, 2025
15 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.

3 participants