btlqql opened a new pull request, #5327:
URL: https://github.com/apache/rocketmq-dashboard/pull/5327
### Which Issue(s) This PR Fixes
- Fixes #5223
### Brief Description
`web/src/pages/ops/audit.tsx` is a localized page (`t('audit.*')`
throughout) but five strings were hardcoded Chinese and therefore rendered
Chinese for every viewer:
- `web/src/pages/ops/audit.tsx:166` — record-list load failure,
`message.error('审计日志加载失败,请稍后重试')`
- `web/src/pages/ops/audit.tsx:225` — summary load failure,
`message.error('审计概览加载失败,请稍后重试')`
- `web/src/pages/ops/audit.tsx:299` — cleanup failure,
`message.error('清理审计日志失败,请稍后重试')`
- `web/src/pages/ops/audit.tsx:310` — export failure,
`message.error('导出审计日志失败,请稍后重试')`
- `web/src/pages/ops/audit.tsx:580` — cleanup modal suffix,
`<span>天之前的日志</span>` (a broken fragment in English)
They now resolve through the translation table — `audit.loadFailed`,
`audit.summaryLoadFailed`, `audit.cleanupFailed`, `audit.exportFailed` and
`audit.cleanupDaysSuffix` — added next to the existing `audit.cleanup*` keys in
`web/src/i18n/translations.ts` with both `zh` and `en` entries. The two effects
that now call `t` list it in their dependency arrays, as the neighbouring pages
(`notificationDeliveries.tsx`, `alerts.tsx`) already do.
### How Did You Test This Change?
New test `web/src/pages/ops/__tests__/AuditPageLocalization.test.tsx`
renders the page with `rocketmq-studio-language = en` and pins the English
wording of all five strings (toasts via `vi.spyOn(message, 'error')`, the
suffix in the cleanup modal). Red on the unmodified tree, green after the fix.
```powershell
$ cd web && npx vitest run
src/pages/ops/__tests__/AuditPageLocalization.test.tsx
❯ src/pages/ops/__tests__/AuditPageLocalization.test.tsx (3 tests | 3
failed) 19295ms
× routes the record and summary load failures through the translation
table 6736ms
× routes the cleanup and export failures through the translation table
6273ms
× renders the cleanup-window suffix through the translation table 6281ms
FAIL ... > routes the record and summary load failures through the
translation table
AssertionError: expected "Mock" to be called with arguments: [ Array(1) ]
Received:
1st Mock call:
[
- "Failed to load audit logs. Try again later.",
+ "审计日志加载失败,请稍后重试",
]
2nd Mock call:
[
- "Failed to load audit logs. Try again later.",
+ "审计概览加载失败,请稍后重试",
]
FAIL ... > routes the cleanup and export failures through the translation
table
AssertionError: expected "Mock" to be called with arguments: [ Array(1) ]
+ "导出审计日志失败,请稍后重试",
FAIL ... > renders the cleanup-window suffix through the translation table
TestingLibraryElementError: Unable to find an element with the text: days of
logs.
Test Files 1 failed (1)
Tests 3 failed (3) <- before the fix
```
```powershell
$ cd web && npx vitest run
src/pages/ops/__tests__/AuditPageLocalization.test.tsx
src/pages/ops/__tests__/AuditPage.test.tsx
src/pages/ops/__tests__/AuditSummaryCards.test.tsx
src/i18n/__tests__/translations.test.ts
✓ src/pages/ops/__tests__/AuditPageLocalization.test.tsx (3 tests) 6454ms
✓ src/pages/ops/__tests__/AuditPage.test.tsx (11 tests) 27896ms
✓ src/pages/ops/__tests__/AuditSummaryCards.test.tsx (3 tests) 1074ms
✓ src/i18n/__tests__/translations.test.ts (2 tests) 20ms
Test Files 4 passed (4)
Tests 19 passed (19) <- after the fix
```
`npx tsc -b` passes and `npx eslint` reports 0 errors/0 warnings on the
three touched files.
### Checklist
- [x] One coherent change; unrelated modifications are not bundled in
- [x] Commit subject follows Conventional Commits
- [x] Tests added or updated for non-trivial changes
- [x] New UI text has both Chinese and English entries under `web/src/i18n/`
- [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit
checks) — not applicable: frontend-only change, no Java touched
- [x] New source files carry the ASF license header
- [ ] Documentation touched where behaviour changed — not applicable: no
documented behaviour changed, the strings are the documentation
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]