Skip to main content

IdlingLocaleProvider

What this does: mounts typesafe-i18n for idling.app client UI — English boots synchronously on first paint; other locales load asynchronously when the player picks a language in the footer (or from localStorage / cookie), without blocking the app shell.

Context API​

useIdlingLocale() returns:

FieldMeaning
localeIdActive IdlingLocaleId from canon catalog
llTranslation function object (TranslationFunctions)
loadingtrue while a non-English chunk fetches
setLocaleIdPersists to storage + cookie, kicks off loadLocaleAsync
catalogIDLING_LOCALE_CATALOG rows for picker labels

Boot sequence​

  1. initIdlingI18n(IDLING_BASE_LOCALE) runs immediately — first paint uses English ll.
  2. On mount, resolveIdlingLocaleFromStorage() may schedule a deferred locale if the user previously chose one (idling-ui-locale key).
  3. loadLocaleAsync imports the locale module; on success, context updates and writeIdlingLocaleCookie runs for future metadata experiments.
  4. Tests short-circuit to testLocaleContext() — no async locale fetch in Vitest.

Policy matches Mappy site: no auto-switch from browser Accept-Language alone. See /guides/i18n and /guides/i18n-ssr-metadata.

Usage​

import { IdlingLocaleProvider, useIdlingLocale } from '@app/components/locale/IdlingLocaleProvider';

// In root client shell (SiteChromeProviders)
<IdlingLocaleProvider>{children}</IdlingLocaleProvider>;

function Example() {
const { ll, localeId } = useIdlingLocale();
return <span>{ll.common.backHome()}</span>;
}

Area-specific copy providers (admin, settings, tools) may wrap subtrees with catalogs resolved from ll — see resolveCatalogFromLl molecule.

Integration​

ModuleRole
$i18n/idling-i18nSync English seam, same shape as Mappy mappy-i18n
@molecules/quotes/idlingLocaleCatalogCanon locale list
writeIdlingLocaleCookieFooter picker persistence

Failure modes​

SymptomCause
Flash of English then switchExpected when stored locale ≠ EN
Stuck EnglishLocale chunk failed — check network tab for dynamic import
Hook throwsProvider missing above component tree