Repository navigation
fix(ui): translate aria-label attributes and repair the search-clear tooltips - #167
Merged
Merged
Conversation
…tooltips
`applyStatic()` rewrites exactly three hooks - `[data-i18n]` (text),
`[data-i18n-ph]` (placeholder) and `[data-i18n-title]` (title). There was no
hook for `aria-label`, so the nine `aria-label` attributes written in the static
markup stayed Chinese in English mode. Because `aria-label` outranks `title`
when the accessible name is computed, an English screen-reader user heard
Chinese while the visible tooltip was English - the two attributes contradicted
each other on the same element.
Add a fourth pass to `applyStatic()`: `[data-i18n-label]` -> `setAttribute(
"aria-label", t(key))`, mirroring the existing title pass, and tag the nine
sites. All three keys involved already exist in both packs, so no translations
are added - this was missing wiring, not missing text:
- `#login-theme-toggle`, `#theme-toggle` -> `theme.toggle.title`
- six `button.search-clear` -> `mk.clear`
- `#help-panel` (role="dialog") -> `help.title`
While wiring those up, two adjacent defects on the same buttons surfaced and are
fixed here:
- the clear button inside `#ak-search` carried `data-i18n-title=
"common.search"`, so its tooltip read "Search" (搜索) on a *clear* button -
wrong in both languages; its sibling on `#mk-search` correctly uses
`mk.clear`.
- four clear buttons (`#emp-search`, `#od-search`, `#model-search`,
`#ops-search`) had a bare `title="清空搜索"` with no i18n hook at all and
stayed Chinese in English mode.
Cache-bust bump `?v=20260911-11` -> `?v=20260911-12` (5 references).
Verified in a headless browser against a baseline built by the same generator
(`git archive HEAD ui`), EN and ZH, on two surfaces (login and an authenticated
view), with the pre-existing `[data-i18n-title]` hook kept as a built-in
negative control (CJK-free in EN in the *baseline* too, so the probe demonstrably
sees translations). 24/24 assertions pass:
- EN aria-label sites still Chinese: 9 -> 0; sites carrying the hook: 0 -> 9
- EN unhooked Chinese titles: 4 -> 0; hooked title sites: 10 -> 14
- ZH aria-labels still Chinese (9) - no regression
- EN values: theme toggles `Toggle light / dark theme`, clear buttons
`Clear search`, help panel `Shortcuts`; ZH now matches each element's own
tooltip
- the mislabel is gone: no `search-clear` aria-label says "Search"
A runtime `I18n.setLang("en")` switch with no reload confirms the baseline keeps
Chinese while its `title` goes English (the contradiction), and the fixed
attributes follow the switch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
applyStatic()rewrites exactly three hooks —[data-i18n](text),[data-i18n-ph](placeholder) and[data-i18n-title](title). There was no hook foraria-label, so the ninearia-labelattributes written in the static markup stayed Chinese in English mode.Because
aria-labeloutrankstitlewhen the accessible name is computed, an English screen-reader user heard Chinese while the visible tooltip was English — the two attributes contradicted each other on the same element:titlein EN (hook worked)aria-labelin EN (no hook)#theme-toggleToggle light / dark theme切换主题button.search-clearClear search清空搜索#help-panel(role="dialog")快捷键帮助Related Issue
(No issue — found by an i18n coverage audit; small, self-contained fix.)
Changes
applyStatic()inui/js/i18n.js:[data-i18n-label]→setAttribute("aria-label", t(key)), mirroring the existing title pass.aria-labelsites inui/index.html. All three keys already exist in both packs, so no translations are added — this is missing wiring, not missing text:#login-theme-toggle,#theme-toggle→theme.toggle.titlebutton.search-clear→mk.clear#help-panel(role="dialog") →help.title#ak-searchcarrieddata-i18n-title="common.search", so its tooltip read "Search"(搜索)on a clear button — wrong in both languages; its sibling on#mk-searchcorrectly usesmk.clear.#emp-search,#od-search,#model-search,#ops-search) had a baretitle="清空搜索"with no i18n hook at all, so they stayed Chinese in English mode.?v=20260911-11→?v=20260911-12(5 references).Note on
placeholder/value/alt, checked in the same audit:placeholderis already fully wired (18/18 CJK placeholders), andvalue(38 attrs) andalt(0 attrs) contain no CJK — no work needed there.Tests
cargo test— 148 passed, 0 failedcargo fmt --check— cleancargo clippy --all-targets -- -D warnings— cleannode --check ui/js/i18n.js— cleani18n.jsmodule) with zero added keysVerified in a headless browser. Baseline and fixed trees were produced by the same generator (baseline =
git archive HEAD ui), measured in EN and ZH on two surfaces (login and an authenticated view). The pre-existing[data-i18n-title]hook is kept as a built-in negative control: it is CJK-free in EN in the baseline too, which proves the probe can see translations, so the aria-label zeros are meaningful. 24/24 assertions pass:aria-labelsites still Chinese: 9 → 0; sites carrying the hook: 0 → 9aria-labelsites still Chinese (9) — no regressionToggle light / dark theme, clear buttonsClear search, help panelShortcuts; in ZH each now matches its own tooltipsearch-cleararia-label says "Search"A runtime
I18n.setLang("en")switch with no reload confirms the baseline keeps a Chinesearia-labelwhile itstitlegoes English (the contradiction), and the fixed attributes follow the switch.Checklist
fix/)fix(ui): ...)