Skip to content

fix(i18n): make rule category dictionaries reactive to language changes#833

Open
actiontech-bot wants to merge 2 commits into
mainfrom
feature-99
Open

fix(i18n): make rule category dictionaries reactive to language changes#833
actiontech-bot wants to merge 2 commits into
mainfrom
feature-99

Conversation

@actiontech-bot
Copy link
Copy Markdown
Member

Summary

修复 SQLE UI 中 DB2 规则分类(category)在中英文切换时未跟随更新的回归缺陷,配合 sqle-db2-plugin-j Issue #99(DB2 插件 I18n 支持)的端到端联调。

Changes

  1. useRuleCategories:将 RuleCategoryDictionary 等静态导出改为按调用时机执行 t() 的 getter 函数,并通过 Proxy 提供向后兼容别名;hook 内部把 i18n.language 加入 useMemo 依赖,确保语言切换后立即重算。
  2. en-US/rule.ts:补全 category 字段缺失的英文翻译(auditAccuracy / auditPurpose / operand / sql / performanceCost 以及全部 tag 项),消除英文环境下分类标签回退为中文的问题。

Related

Test plan

  • 已通过 docs/test/case-002.md(英文环境下 DB2 规则列表 desc/annotation/category 显示)
  • 已通过 docs/test/case-005.md(语言切换后即时生效)
  • CI: pnpm checker + pnpm test 通过

RuleCategoryDictionary and related exports were static module-level
constants that captured t() translations at import time, so switching
the UI language from Chinese to English left category labels ("在线",
"DML", "可维护性" etc.) untranslated.

Root cause: t() was called once during module initialization instead
of on every render. This made the category display language-insensitive
while desc/annotation (fetched from the API per-language) worked fine.

Fix: Convert all dictionary constants to getter functions that call
t() at invocation time; add Proxy-based backward-compatible aliases
so existing imports continue to compile. In useRuleCategories hook,
call getRuleCategoryDictionaryGroup() inside useMemo and add
i18n.language to the dependency array so the memo recalculates when
the user switches language.

Closes CASE-002 (AC-3.2, AC-4.3 regression).
The English locale file was missing the entire `category` section that
exists in zh-CN/rule.ts, causing t('rule.category.tag.*') to fall back
to Chinese text when the UI is in English mode. This made category tags
like "Online", "DML", "DDL", "Maintainability" display in Chinese even
after switching to English.

Added complete English translations for all category fields including
auditAccuracy, auditPurpose, operand, sql, performanceCost, and all
tag entries (online, offline, database, table, column, index, etc.).

Fixes CASE-002 regression-1 failure.
@github-actions
Copy link
Copy Markdown

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 80.71% 29369/36387
🟡 Branches 63.06% 11000/17443
🟢 Functions 84.08% 9881/11752
🟢 Lines 84.7% 28060/33130

Test suite run success

3711 tests passing in 814 suites.

Report generated by 🧪jest coverage report action from 396e584

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