Skip to content

feat(i18n): 将中文错误信息改为多语言 i18n,并新增 @grant 冲突校验 - #819

Merged
CodFrm merged 6 commits into
scriptscat:mainfrom
cyfung1031:pr-GM_editor_err_messages
Oct 10, 2025
Merged

CodFrm merged 6 commits into
scriptscat:mainfrom
cyfung1031:pr-GM_editor_err_messages

Conversation

@cyfung1031

Copy link
Copy Markdown
Collaborator

概要

本次 PR 将脚本处理逻辑中的所有中文硬编码错误信息替换为 i18n 多语言键值(以 error_ 为前缀),并新增对无效 @grant 声明的校验。

主要修改内容

  • 替换以下函数中的中文错误信息为 i18n 调用:

    • prepareScriptByCode
    • prepareSubscribeByCode
  • 新增 @grant 校验逻辑,防止同时声明 none 与 GM API:

    if (
      script.metadata?.grant?.includes("none") &&
      script.metadata?.grant?.some((s: string) => s.startsWith("GM"))
    ) {
      throw new Error(i18n_t("error_grant_conflict"));
    }
  • 新增多语言键值:

    • error_grant_conflict:@grant 同时声明了 none 和 GM API
  • 更新所有 7 个语言包:

    • zh-CN, zh-TW, en-US, ja-JP, vi-VN, de-DE, ru-RU,
  • 占位符格式统一为 {{expr}}。

影响

  • 提升错误提示的国际化一致性。
  • 防止脚本在声明 @grant none 时仍使用 GM API 的错误用法。
  • 不影响现有功能或接口,仅改进错误处理与校验逻辑。

测试

  • 已验证所有错误均能通过 i18n_t() 正确输出本地化信息。
  • 检查所有语言包翻译内容与占位符一致。

@cyfung1031
cyfung1031 force-pushed the pr-GM_editor_err_messages branch from 936094c to 4be5840 Compare October 8, 2025 15:08
@cyfung1031
cyfung1031 force-pushed the pr-GM_editor_err_messages branch from 89db07f to abbbeb6 Compare October 10, 2025 00:08
@CodFrm

CodFrm commented Oct 10, 2025

Copy link
Copy Markdown
Member

#532 (comment)

也许也可以把这个问题加入这个PR

@cyfung1031

Copy link
Copy Markdown
Collaborator Author

#532 (comment)

也许也可以把这个问题加入这个PR

改哪裡?我不熟。你可以直接加commit

Comment thread src/pkg/utils/script.ts Resolved
@CodFrm
CodFrm requested a review from Copilot October 10, 2025 15:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

本 PR 的目的是将脚本处理逻辑中的中文硬编码错误信息替换为多语言 i18n 键值,并新增对无效 @grant 声明的校验。

  • 替换了 prepareScriptByCode 和 prepareSubscribeByCode 函数中的所有中文硬编码错误信息为 i18n 调用
  • 新增了对同时声明 @grant none 和 GM API 的冲突校验逻辑,仅在编辑器更新时触发
  • 在所有 7 个语言包中添加了相应的错误信息翻译键值

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/pkg/utils/script.ts 核心修改:替换中文错误信息为 i18n 调用,新增 @grant 冲突校验逻辑,增加 options 参数
src/pages/options/routes/script/ScriptEditor.tsx 更新函数调用以传递 byEditor: true 选项,启用编辑器特定的校验
src/locales/*/translation.json 在所有 7 个语言包中添加新的错误信息翻译键值
src/app/service/service_worker/synchronize.ts 将硬编码的通知信息替换为 i18n 调用
src/app/service/service_worker/subscribe.ts 将硬编码的通知信息替换为 i18n 调用

Comment thread src/pkg/utils/script.ts Resolved
@CodFrm
CodFrm merged commit ef3482d into scriptscat:main Oct 10, 2025
2 of 3 checks passed
@CodFrm CodFrm mentioned this pull request Oct 10, 2025
7 tasks done
@cyfung1031
cyfung1031 deleted the pr-GM_editor_err_messages branch October 18, 2025 15:27
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