Skip to content

Commit 0a8bf8e

Browse files
committed
fix(i18n): drop the dead module-scope localStorage read, restore key-marker fallback
The stored value fed only init({lng}), but every lookup passes an explicit lng, so it never affected output — while adding a SecurityError path at module scope, where it takes down the whole module graph instead of one component. I18nContext already owns the preference behind a try/catch. returnedObjectHandler restores the old loader's behaviour for a non-leaf key: fall through to the 'namespace.key' marker rather than rendering i18next's English developer message into the UI.
1 parent b177d24 commit 0a8bf8e

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/i18n/loader.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,22 @@ const resources = Object.fromEntries(
2828
availableLocales.map((locale) => [locale, byLocale[locale] as Resource[string]]),
2929
) as Resource;
3030

31-
const stored =
32-
typeof localStorage !== "undefined" ? localStorage.getItem("openscreen-locale") : null;
33-
const initialLng = stored && availableLocales.includes(stored) ? stored : DEFAULT_LOCALE;
34-
31+
// `lng` is inert here: every lookup below passes an explicit `lng`, so the init
32+
// language never reaches the output. Reading localStorage at module scope would
33+
// add a failure mode for no gain — it can throw SecurityError, and at module
34+
// scope that takes down the whole graph rather than one component. The user's
35+
// stored preference is applied by I18nContext, which guards its access.
3536
await i18next.init({
36-
lng: initialLng,
37+
lng: DEFAULT_LOCALE,
3738
fallbackLng: DEFAULT_LOCALE,
3839
defaultNS: "common",
3940
resources,
4041
interpolation: { escapeValue: false },
42+
// A non-leaf key would otherwise render i18next's English developer message
43+
// ("key 'x' returned an object instead of string") straight into the UI.
44+
// Returning undefined keeps the old loader's behaviour: fall through to the
45+
// `namespace.key` marker.
46+
returnedObjectHandler: () => undefined,
4147
});
4248

4349
function tAt(

0 commit comments

Comments
 (0)