Skip to content

fix(pad): restore Accept-Language auto-detect on pad UI (#7586)#7588

Merged
JohnMcLear merged 1 commit intoether:developfrom
JohnMcLear:fix-locale-autodetect-7586
Apr 23, 2026
Merged

fix(pad): restore Accept-Language auto-detect on pad UI (#7586)#7588
JohnMcLear merged 1 commit intoether:developfrom
JohnMcLear:fix-locale-autodetect-7586

Conversation

@JohnMcLear
Copy link
Copy Markdown
Member

Summary

Fixes #7586. In v2.7.0 the pad UI stopped honouring the browser's Accept-Language / locale, always rendering English regardless of system language. The index page and the timeslider were unaffected; only the pad route regressed.

Root cause

The regression was introduced by #7545 ("Add creator-owned pad settings defaults"), which added this line to Pad.normalizePadSettings():

lang: typeof rawPadSettings.lang === 'string' ? rawPadSettings.lang : 'en',

That default propagates into clientVars.padOptions.lang. On the client, getParams() in src/static/js/pad.ts reads padOptions.lang and fires the per-setting callback, which is html10n.localize([val, 'en']). So every pad forced English at load time, defeating the existing auto-detect chain in src/static/js/l10n.ts:

html10n.localize([regexpLang, navigator.language, 'en']);

Fix

Default lang to null instead of 'en'. The client-side flow already handles null correctly — getParams() at pad.ts:172 short-circuits with if (serverValue == null) continue;, so the forced-localize callback simply doesn't fire, and l10n.ts's browser-language chain takes over. The pad-settings dropdown consumer at pad.ts:489 already uses padOptions.lang || 'en' so it renders 'en' visually when no override is set, matching prior behaviour.

PadSettings.lang is widened from string to string | null to match.

Creator override (explicit rawPadSettings.lang = 'de') continues to work — that's still a string, so it's preserved verbatim.

Tests

Added three backend regression tests under normalizePadSettings lang in tests/backend/specs/Pad.ts:

  • defaults to null when lang is absent (so client auto-detects)
  • preserves an explicit string lang (creator override still works)
  • drops non-string lang values to null rather than coercing to 'en'

Test plan

  • mocha tests/backend/specs/Pad.ts — 23 passing
  • Full backend suite — 802 passing, 0 failing (+3 from this PR)
  • tsc --noEmit clean in our code
  • Manual: Firefox with German locale → fresh pad renders in German. Index and timeslider unchanged. ?lang=de URL param and language cookie continue to override browser detection.

🤖 Generated with Claude Code

ether#7586)

`Pad.normalizePadSettings()` was defaulting `lang` to the literal string
'en' when `rawPadSettings.lang` was not a string. That value flowed into
`clientVars.padOptions.lang` and then into `getParams()` in pad.ts,
which calls `html10n.localize([serverValue, 'en'])` as a callback for
the `lang` setting. The result: every pad forced English on load,
overriding the browser's Accept-Language and the existing auto-detect
chain in l10n.ts (cookie -> navigator.language -> 'en').

The regression was introduced in ether#7545 ("Add creator-owned pad settings
defaults", commit e0ccdb4). 2.6.1 did not have this default, so
auto-detect worked there. 2.7.0 broke it.

Fix: default `lang` to null. The client's existing flow already handles
null correctly — getParams() at pad.ts:172 has
`if (serverValue == null) continue;`, so the forced-localize callback
simply does not fire, and l10n.ts's browser-language auto-detect runs.
Pad-settings dropdown consumer at pad.ts:489 already uses
`padOptions.lang || 'en'` so null renders fine there too.

`PadSettings.lang` is now typed `string | null` to match.

Added three backend regression tests under `normalizePadSettings lang`:
  * defaults to null when lang is absent (so client auto-detects)
  * preserves an explicit string lang (creator override still works)
  * drops non-string lang values to null rather than coercing to 'en'

Manual verification: with Firefox set to German, loading a fresh pad
now renders the UI in German. Index and timeslider continued to work
as before. Setting `?lang=de` or a language cookie continues to
override browser detection, as intended.

Fixes ether#7586
@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Review Summary by Qodo

Restore Accept-Language auto-detect on pad UI

🐞 Bug fix 🧪 Tests

Grey Divider

Walkthroughs

Description
• Restore browser locale auto-detection on pad UI by defaulting lang to null
• Prevent hardcoded English from overriding Accept-Language and cookie settings
• Add three regression tests for normalizePadSettings lang handling
• Widen PadSettings.lang type to string | null for proper null handling
Diagram
flowchart LR
  A["Pad.normalizePadSettings()"] -->|"lang default changed"| B["lang: null instead of 'en'"]
  B -->|"client-side flow"| C["getParams() skips callback"]
  C -->|"l10n auto-detect runs"| D["cookie → navigator.language → 'en'"]
  E["Creator override lang='de'"] -->|"preserved as string"| F["Works as before"]
Loading

Grey Divider

File Changes

1. src/node/db/Pad.ts 🐞 Bug fix +6/-2

Change lang default from 'en' to null

• Changed PadSettings.lang type from string to string | null
• Modified normalizePadSettings() to default lang to null instead of 'en'
• Added explanatory comment about the fix for issue #7586
• Preserves explicit string values for creator overrides

src/node/db/Pad.ts


2. src/tests/backend/specs/Pad.ts 🧪 Tests +19/-0

Add regression tests for lang normalization

• Added test suite for normalizePadSettings lang regression testing
• Test that lang defaults to null when not provided
• Test that explicit string lang values are preserved
• Test that non-string lang values are coerced to null rather than 'en'

src/tests/backend/specs/Pad.ts


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented Apr 23, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

@JohnMcLear JohnMcLear merged commit a1bb958 into ether:develop Apr 23, 2026
16 checks passed
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.

v2.7.0. breaks i10n auto-detect of language for pad UI

1 participant