Skip to content

Commit a1bb958

Browse files
authored
fix(pad): stop hardcoding lang='en', let the client auto-detect locale (#7586) (#7588)
`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 #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 #7586
1 parent 9e352ca commit a1bb958

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/node/db/Pad.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type PadSettings = {
3939
showChat: boolean;
4040
alwaysShowChat: boolean;
4141
chatAndUsers: boolean;
42-
lang: string;
42+
lang: string | null;
4343
view: PadViewSettings;
4444
};
4545

@@ -91,7 +91,11 @@ class Pad {
9191
!!rawPadSettings.showChat,
9292
alwaysShowChat: !!rawPadSettings.alwaysShowChat,
9393
chatAndUsers: !!rawPadSettings.chatAndUsers,
94-
lang: typeof rawPadSettings.lang === 'string' ? rawPadSettings.lang : 'en',
94+
// Default to null (not 'en') so the client's l10n auto-detect chain
95+
// (cookie -> navigator.language -> 'en' fallback) runs. Hardcoding 'en'
96+
// forces English on every pad regardless of the browser's Accept-Language
97+
// and broke #7586 (German system saw English pad UI in v2.7.0).
98+
lang: typeof rawPadSettings.lang === 'string' ? rawPadSettings.lang : null,
9599
view: {
96100
showAuthorColors: rawView.showAuthorColors == null ? true : !!rawView.showAuthorColors,
97101
showLineNumbers: rawView.showLineNumbers == null ?

src/tests/backend/specs/Pad.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,23 @@ describe(__filename, function () {
159159
assert.equal(pad!.text(), `${want}\n`);
160160
});
161161
});
162+
163+
describe('normalizePadSettings lang (issue #7586)', function () {
164+
it('defaults lang to null when not provided, so client auto-detects locale', function () {
165+
const ps = Pad.Pad.normalizePadSettings({});
166+
assert.equal(ps.lang, null);
167+
});
168+
169+
it('preserves an explicit string lang (creator override)', function () {
170+
const ps = Pad.Pad.normalizePadSettings({lang: 'de'});
171+
assert.equal(ps.lang, 'de');
172+
});
173+
174+
it('drops non-string lang values to null rather than coercing to "en"', function () {
175+
for (const bogus of [42, true, {}, [], null, undefined]) {
176+
const ps = Pad.Pad.normalizePadSettings({lang: bogus});
177+
assert.equal(ps.lang, null, `bogus input ${JSON.stringify(bogus)}`);
178+
}
179+
});
180+
});
162181
});

0 commit comments

Comments
 (0)