Skip to content

fix: use toUtf8() instead of toLatin1() for tr() calls#638

Merged
wyu71 merged 1 commit intolinuxdeepin:masterfrom
wyu71:master
Apr 9, 2026
Merged

fix: use toUtf8() instead of toLatin1() for tr() calls#638
wyu71 merged 1 commit intolinuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71
Copy link
Copy Markdown
Contributor

@wyu71 wyu71 commented Apr 9, 2026

Fix Chinese character corruption in translation lookup by using UTF-8 encoding instead of Latin-1 which cannot handle non-ASCII chars.

修复翻译查找中因Latin-1编码导致中文字符变为问号的问题,改用UTF-8编码。

Log: 修复中文界面下处理器表头显示问号的问题
PMS: BUG-351713
Influence: 修复translateStr()和getTableHeader()两处toLatin1()调用, 确保中文等非ASCII字符在翻译查找时正确保留,影响所有设备信息的中文显示。

Summary by Sourcery

Bug Fixes:

  • Fix corruption of non-ASCII characters (e.g. Chinese) in device info translations by using UTF-8-encoded keys for tr() lookups.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 9, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaces Latin-1 based translation lookups with UTF-8 to correctly handle non-ASCII (e.g., Chinese) characters in device info translations, specifically in generic translation helper and table header translation.

Sequence diagram for UTF-8 based translation lookup in table headers

sequenceDiagram
    actor User
    participant DeviceManagerUI
    participant DeviceBaseInfo
    participant QtTranslator

    User->>DeviceManagerUI: open device list view
    DeviceManagerUI->>DeviceBaseInfo: getTableHeader()
    loop for each item in m_TableHeader
        DeviceBaseInfo->>DeviceBaseInfo: item.toUtf8()
        DeviceBaseInfo->>QtTranslator: tr(utf8Bytes)
        QtTranslator-->>DeviceBaseInfo: translatedString or empty
        alt translation found
            DeviceBaseInfo->>DeviceBaseInfo: m_TableHeaderTr.append(translatedString)
        else translation missing
            DeviceBaseInfo->>DeviceBaseInfo: m_TableHeaderTr.append(item)
        end
    end
    DeviceBaseInfo-->>DeviceManagerUI: m_TableHeaderTr
    DeviceManagerUI-->>User: show correct non ASCII headers
Loading

Updated class diagram for DeviceBaseInfo translation methods

classDiagram
    class DeviceBaseInfo {
        +QString translateStr(QString inStr)
        +QString nameTr()
        +QStringList getTableHeader()
    }
Loading

File-Level Changes

Change Details Files
Switch translation helper function and table header translation from Latin-1 to UTF-8 encoded keys to avoid corruption of non-ASCII characters.
  • Update translateStr() to pass UTF-8 encoded strings into tr() instead of Latin-1.
  • Update getTableHeader() to derive translation keys from UTF-8 encoded header strings instead of Latin-1.
  • Preserve fallback behavior when translations are missing, now with correct handling of non-ASCII characters.
deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp

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

Fix Chinese character corruption in translation lookup by using
UTF-8 encoding instead of Latin-1 which cannot handle non-ASCII chars.

修复翻译查找中因Latin-1编码导致中文字符变为问号的问题,改用UTF-8编码。

Log: 修复中文界面下处理器表头显示问号的问题
PMS: BUG-351713
Influence: 修复translateStr()和getTableHeader()两处toLatin1()调用,
确保中文等非ASCII字符在翻译查找时正确保留,影响所有设备信息的中文显示。
Copy link
Copy Markdown

@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 - I've reviewed your changes and they look great!


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
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, wyu71

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

@wyu71 wyu71 merged commit d5e836d into linuxdeepin:master Apr 9, 2026
22 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