Skip to content

Conversation

@GongHeng2017
Copy link
Contributor

@GongHeng2017 GongHeng2017 commented Dec 18, 2025

-- Translation method does not conform to standards -- Adjust translation

Log: fix issue
Task: https://pms.uniontech.com/task-view-384577.html

Summary by Sourcery

Standardize CPU-related UI translations and add tooling support for updating translation files.

Enhancements:

  • Replace custom translation helper with Qt's tr() for CPU labels and number words to align with project translation standards.

Build:

  • Add lupdate helper script to regenerate translation source files for all supported locales.

-- Translation method does not conform to standards
-- Adjust translation

Log: fix issue
Task: https://pms.uniontech.com/task-view-384577.html
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 18, 2025

Reviewer's Guide

This PR standardizes CPU-related UI translations by switching from a custom translateStr helper to Qt's native tr() for all relevant strings and adds a helper script to regenerate Qt translation files for multiple locales.

Flow diagram for lupdate translation regeneration script

flowchart TD
    A[Developer runs lupdate_sh] --> B[Invoke lupdate on src]
    B --> C[Generate deepin-devicemanager_ts]
    B --> D[Generate deepin-devicemanager_zh_CN_ts]
    B --> E[Generate deepin-devicemanager_zh_TW_ts]
    B --> F[Generate deepin-devicemanager_zh_HK_ts]
    B --> G[Generate deepin-devicemanager_ug_ts]
    B --> H[Generate deepin-devicemanager_bo_ts]
    C --> I[Updated translation sources]
    D --> I
    E --> I
    F --> I
    G --> I
    H --> I
Loading

File-Level Changes

Change Details Files
Standardize CPU-related string translation using Qt's tr() instead of a custom helper.
  • Replace translateStr("Processor") and translateStr("Core(s)") with tr("Processor") and tr("Core(s)") in the CPU subtitle and overview text construction.
  • Update the CPU core-count translation map to use tr() for all number words so they are discoverable by Qt's translation tools.
deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp
Introduce a script to regenerate Qt translation (.ts) files for all supported locales.
  • Add lupdate.sh to run lupdate on ./src with -no-obsolete for each target translation file, including default and multiple Chinese, Uyghur, and Tibetan locales.
  • Include SPDX copyright and license headers in the new script for compliance.
deepin-devicemanager/lupdate.sh

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

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

  1. 代码逻辑和功能:
  • 主要改动是将自定义的translateStr()函数替换为Qt标准的tr()函数来实现国际化
  • 添加了新的lupdate.sh脚本用于更新翻译文件
  • 这个改动是合理的,使用Qt标准的tr()函数更符合Qt框架的设计规范
  1. 代码质量:
  • lupdate.sh脚本:
    • 建议在脚本开头添加set -e,确保任何命令失败时脚本立即退出
    • 建议添加错误处理,检查目录是否存在
    • 可以考虑使用变量定义源码和翻译目录路径,便于维护
  1. 代码性能:
  • 使用tr()替代translateStr()不会有性能影响
  • m_trNumber的初始化方式可以优化,考虑使用QMap的初始化列表
  1. 代码安全:
  • lupdate.sh脚本:
    • 建议检查文件权限
    • 建议添加输入验证

改进建议:

  1. lupdate.sh脚本改进:
#!/bin/bash
set -e

# SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

SRC_DIR="./src"
TRANS_DIR="../translations"

# 检查目录是否存在
if [ ! -d "$SRC_DIR" ]; then
    echo "Source directory $SRC_DIR does not exist"
    exit 1
fi

if [ ! -d "$TRANS_DIR" ]; then
    echo "Translation directory $TRANS_DIR does not exist"
    exit 1
fi

# 更新翻译文件
lupdate "$SRC_DIR" -ts -no-obsolete "$TRANS_DIR/deepin-devicemanager.ts"
lupdate "$SRC_DIR" -ts -no-obsolete "$TRANS_DIR/deepin-devicemanager_zh_CN.ts"
lupdate "$SRC_DIR" -ts -no-obsolete "$TRANS_DIR/deepin-devicemanager_zh_TW.ts"
lupdate "$SRC_DIR" -ts -no-obsolete "$TRANS_DIR/deepin-devicemanager_zh_HK.ts"
lupdate "$SRC_DIR" -ts -no-obsolete "$TRANS_DIR/deepin-devicemanager_ug.ts"
lupdate "$SRC_DIR" -ts -no-obsolete "$TRANS_DIR/deepin-devicemanager_bo.ts"
  1. DeviceCpu.cpp中m_trNumber初始化改进:
void DeviceCpu::getTrNumber()
{
    // 使用初始化列表方式
    static const QMap<int, QString> numberMap = {
        {1, tr("One")}, {2, tr("Two")}, {4, tr("Four")},
        // ... 其他映射 ...
    };
    m_trNumber = numberMap;
}
  1. 其他建议:
  • 考虑将数字翻译移到单独的翻译文件中,便于维护
  • 可以考虑使用Q_DECLARE_TR_FUNCTIONS宏来支持非QObject类的翻译功能
  • 建议添加单元测试来验证翻译功能的正确性

总体来说,这个改动是积极的,使用Qt标准的tr()函数更有利于代码维护和国际化支持。主要的改进空间在于脚本的安全性和错误处理,以及数字翻译的实现方式。

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:

  • In getTrNumber(), since the only change is swapping translateStr for tr, this might be a good opportunity to replace the large hard-coded map of spelled-out numbers with a more compact helper (e.g., a generic number-to-text routine or at least a data-driven table) to reduce repetition and maintenance overhead.
  • The new lupdate.sh script hardcodes multiple nearly identical lupdate calls and assumes it is run from a specific directory; consider iterating over the translation files in a loop and basing paths on $(dirname "$0") to make the script more maintainable and robust to different working directories.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `getTrNumber()`, since the only change is swapping `translateStr` for `tr`, this might be a good opportunity to replace the large hard-coded map of spelled-out numbers with a more compact helper (e.g., a generic number-to-text routine or at least a data-driven table) to reduce repetition and maintenance overhead.
- The new `lupdate.sh` script hardcodes multiple nearly identical `lupdate` calls and assumes it is run from a specific directory; consider iterating over the translation files in a loop and basing paths on `$(dirname "$0")` to make the script more maintainable and robust to different working directories.

## Individual Comments

### Comment 1
<location> `deepin-devicemanager/lupdate.sh:7-12` </location>
<code_context>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+lupdate ./src -ts -no-obsolete ../translations/deepin-devicemanager.ts
+lupdate ./src -ts -no-obsolete ../translations/deepin-devicemanager_zh_CN.ts
+lupdate ./src -ts -no-obsolete ../translations/deepin-devicemanager_zh_TW.ts
+lupdate ./src -ts -no-obsolete ../translations/deepin-devicemanager_zh_HK.ts
+lupdate ./src -ts -no-obsolete ../translations/deepin-devicemanager_ug.ts
+lupdate ./src -ts -no-obsolete ../translations/deepin-devicemanager_bo.ts
\ No newline at end of file
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Script assumes a fixed working directory and lacks basic safety options.

This will fail if run outside the project root, and failed `lupdate` calls won’t stop the rest. Consider adding `set -euo pipefail`, resolving paths relative to the script location (e.g. `SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"` then `"$SCRIPT_DIR"/src` and `"$SCRIPT_DIR"/../translations/...`), and consistently quoting paths to handle spaces/odd characters.
</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.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 18, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 2e60f5f into linuxdeepin:develop/eagle Dec 18, 2025
16 of 18 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