Skip to content

fix: unify save error messages with tr() - #422

Open
JWWTSL wants to merge 1 commit into
linuxdeepin:masterfrom
JWWTSL:agent/bug/afb156e4b65f
Open

JWWTSL wants to merge 1 commit into
linuxdeepin:masterfrom
JWWTSL:agent/bug/afb156e4b65f

Conversation

@JWWTSL

@JWWTSL JWWTSL commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

fix: unify save error messages with tr()

  1. Root cause: saveComposite() emitted raw Qt/OS errorString()
    via saveFailed signal, bypassing app-level tr() translation
    and producing English messages outside .ts control
  2. Fix: replace all three errorString() calls with unified
    tr("Failed to save the image. Please check the file path
    and permissions.") so messages go through app translation
  3. Impact: all save-failure paths now display consistent
    localized text, no behavior change for valid save paths

Log: Unify save failure error messages to use app-level translation

Influence:

  1. Test saving to a read-only system directory shows localized message
  2. Test saving to a folder without write permission shows localized message
  3. Verify normal save to a writable path still works correctly

fix: 统一保存失败提示语的翻译

  1. 根因:saveComposite() 通过 saveFailed 信号直接透传 Qt/OS 的
    errorString(),绕过应用级 tr() 翻译,产生不受 .ts 控制的英文提示
  2. 方案:将三处 errorString() 调用统一替换为 tr("Failed to save
    the image. Please check the file path and permissions."),
    使消息经过应用翻译体系
  3. 影响:所有保存失败路径均显示一致的本地化文本,对正常保存路径无行为变化

Log: 统一保存失败时的错误提示语翻译

Influence:

  1. 测试保存到只读系统目录时显示本地化提示
  2. 测试保存到无写入权限的文件夹时显示本地化提示
  3. 验证正常保存到可写路径仍可正常工作

PMS: BUG-376893

Summary by Sourcery

Use localized, consistent error messaging for failed image saves while preserving normal save behavior.

Bug Fixes:

  • Unify image save failure messages so all save error paths use a consistent application-translated message instead of raw system errors.

Chores:

  • Add and update translation entries for image save and related validation messages in English and Simplified Chinese.

1. Root cause: saveComposite() emitted raw Qt/OS errorString()
   via saveFailed signal, bypassing app-level tr() translation
   and producing English messages outside .ts control
2. Fix: replace all three errorString() calls with unified
   tr("Failed to save the image. Please check the file path
   and permissions.") so messages go through app translation
3. Impact: all save-failure paths now display consistent
   localized text, no behavior change for valid save paths

Log: Unify save failure error messages to use app-level translation

Influence:
1. Test saving to a read-only system directory shows localized message
2. Test saving to a folder without write permission shows localized message
3. Verify normal save to a writable path still works correctly

fix: 统一保存失败提示语的翻译

1. 根因:saveComposite() 通过 saveFailed 信号直接透传 Qt/OS 的
   errorString(),绕过应用级 tr() 翻译,产生不受 .ts 控制的英文提示
2. 方案:将三处 errorString() 调用统一替换为 tr("Failed to save
   the image. Please check the file path and permissions."),
   使消息经过应用翻译体系
3. 影响:所有保存失败路径均显示一致的本地化文本,对正常保存路径无行为变化

Log: 统一保存失败时的错误提示语翻译

Influence:
1. 测试保存到只读系统目录时显示本地化提示
2. 测试保存到无写入权限的文件夹时显示本地化提示
3. 验证正常保存到可写路径仍可正常工作

PMS: BUG-376893
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JWWTSL

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

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR standardizes all saveComposite() failure notifications by routing them through a single tr()-translated message instead of raw Qt/OS error strings, while updating translation catalogs; save control flow and successful saves remain unchanged.

Sequence diagram for localized image save failures

sequenceDiagram
    participant Controller as ImageEditController
    participant File as QSaveFile
    participant Writer as QImageWriter
    participant UI as Save failure UI

    Controller->>File: open(QIODevice::WriteOnly)
    alt open fails
        Controller->>UI: saveFailed(tr("Failed to save the image. Please check the file path and permissions."))
    else open succeeds
        Controller->>Writer: write(result)
        alt write fails
            Controller->>UI: saveFailed(tr("Failed to save the image. Please check the file path and permissions."))
        else write succeeds
            Controller->>File: commit()
            alt commit fails
                Controller->>UI: saveFailed(tr("Failed to save the image. Please check the file path and permissions."))
            end
        end
    end
Loading

File-Level Changes

Change Details Files
Replaced raw Qt/OS save errors with one application-translatable failure message across all save stages.
  • Use ImageEditController::tr() when file opening, image writing, or commit operations fail.
  • Preserve existing failure returns and cleanup behavior while standardizing emitted saveFailed text.
src/src/imageeditcontroller.cpp
Added and synchronized translation catalog entries for the new save-failure message and related ImageEditController strings.
  • Add the save-failure source string to German and Simplified Chinese catalogs.
  • Provide the Simplified Chinese translation and update source locations for existing entries.
  • Add the ImageEditController context entries to the German catalog.
src/translations/deepin-image-viewer.ts
src/translations/deepin-image-viewer_zh_CN.ts

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

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 ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交将 ImageEditController::saveComposite 中三处 saveFailed 信号的错误信息从原始系统字符串(errorString())统一替换为 tr() 包裹的可翻译字符串,并同步更新了 .ts 和 .zh_CN.ts 翻译文件。变更目的明确,语法逻辑正确,无安全漏洞,代码质量良好,仅存在一处轻微的字符串重复问题。OCR 审查与启发式扫描均未发现问题。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['建议将重复的提示字符串提取为局部常量,如 const QString errorMsg = tr("Failed to save the image. Please check the file path and permissions."); 然后在三处 Q_EMIT saveFailed(errorMsg) 中复用,提高可维护性']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 建议优化:提取重复字符串为局部常量
bool ImageEditController::saveComposite(const QUrl &destination, const QVariantList &extra)
{
    // ... 前置逻辑 ...

    QSaveFile file(targetPath);
    if (!file.open(QIODevice::WriteOnly)) {
        const QString errorMsg = tr("Failed to save the image. Please check the file path and permissions.");
        Q_EMIT saveFailed(errorMsg);
        return false;
    }
    QImageWriter writer(&file, normalizedSource);
    if (!writer.write(result)) {
        const QString errorMsg = tr("Failed to save the image. Please check the file path and permissions.");
        Q_EMIT saveFailed(errorMsg);
        file.cancelWriting();
        return false;
    }
    if (!file.commit()) {
        const QString errorMsg = tr("Failed to save the image. Please check the file path and permissions.");
        Q_EMIT saveFailed(errorMsg);
        return false;
    }
    return true;
}

本报告由 AI 代码审查工具自动生成

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.

2 participants