fix(pad): show detected language in settings dropdown (#7925)#7928
Conversation
When the UI language was auto-detected from the browser (no language cookie and no pad-wide lang set), refreshMyViewControls() and refreshPadSettingsControls() set the language dropdown to `<option>.lang || 'en'`. Since the detected language lives only in html10n (not in padOptions/effectiveOptions), the value was undefined and the dropdown fell back to hardcoded English — even though the pad UI itself rendered correctly in the detected language. Fall back to html10n.getLanguage() before 'en' so the dropdown reflects the language actually rendered. getLanguage() returns the matched lowercase locale key, which matches the <option value> keys. Adds a regression test that loads a pad under a de-DE browser locale and asserts the dropdown reads "Deutsch" without any manual selection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Code Review by Qodo
1.
|
PR Summary by QodoFix language dropdown to reflect auto-detected UI language WalkthroughsUser DescriptionProblemFixes #7925 (follow-up to #7586). The pad UI correctly auto-detects the browser language and renders in it (e.g. German), but the Language dropdown in Settings still shows English. Root causeTwo code paths set the dropdown value and disagree when the language is auto-detected (no
FixFall back to the detected language before $('#languagemenu').val(effectiveOptions.lang || html10n.getLanguage() || 'en');
$('#padsettings-languagemenu').val(padOptions.lang || html10n.getLanguage() || 'en');
TestingAdded a regression test that loads a pad under a RED-green verified against a running server:
🤖 Generated with Claude Code AI Description• Make language dropdowns fall back to html10n-detected language before defaulting to English. • Prevent handshake-time refresh logic from clobbering the correct auto-detected language. • Add frontend regression test covering browser-locale auto-detection with no explicit language set. Diagramgraph TD
A{{"Browser locale"}} --> B(["html10n"]) --> C["pad.ts refresh"] --> D["Language dropdowns"]
E["language.spec.ts"] --> F["Playwright browser context"] --> A
subgraph Legend
direction LR
_ext{{"External input"}} ~~~ _svc(["Client service"]) ~~~ _mod["Module/file"]
end
High-Level AssessmentThe following are alternative approaches to this PR: 1. Persist detected language into effectiveOptions/padOptions
2. Unify refresh logic to only set dropdowns from one event path
Recommendation: Keep the PR’s lightweight fallback to html10n.getLanguage() as the best near-term fix: it resolves the clobbering issue without changing option persistence semantics, and it’s protected by a regression test. The more invasive alternatives (persisting detection or refactoring refresh ownership) can be considered later if additional language-state inconsistencies emerge. File ChangesBug fix (1)
Tests (1)
|
The detection-works precondition computed a boolean via locator.evaluate() but never asserted it, so it could not fail. Assert the bold button's parent title is the German "Fett (Strg-B)" with toHaveAttribute instead. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks @qodo — good catch. The "detection works" check computed a boolean via |
Problem
Fixes #7925 (follow-up to #7586).
The pad UI correctly auto-detects the browser language and renders in it (e.g. German), but the Language dropdown in Settings still shows English.
Root cause
Two code paths set the dropdown value and disagree when the language is auto-detected (no
languagecookie, no pad-widelang):pad_editor.ts(on html10n'slocalizedevent) correctly sets both dropdowns tohtml10n.getLanguage()(e.g.de).pad.tsrefreshMyViewControls()/refreshPadSettingsControls()set them toeffectiveOptions.lang || 'en'/padOptions.lang || 'en'. When nothing is explicitly chosen,getMyViewOverrides()deletesoverrides.lang, so the value isundefinedand the dropdown falls back to hardcoded'en'. These refreshes run after thelocalizedhandler (during handshake), clobbering the correct value back to English.Fix
Fall back to the detected language before
'en':getLanguage()returns the matched lowercase locale key, which matches the<option value>keys built from the available locales — so the right option is selected. An explicit user choice (cookie/pad option) still takes precedence.Testing
Added a regression test that loads a pad under a
de-DEbrowser locale and asserts the dropdown reads "Deutsch" with no manual selection.RED-green verified against a running server:
English(reproduces language dropdown shows English instead of detected language #7925).language.spec.tstests pass.🤖 Generated with Claude Code