Skip to content

Logging: add a breadcrumb on locale switch - #212

Open
greatest0fallt1me wants to merge 1 commit into
QuickLendX:mainfrom
greatest0fallt1me:feat/104-locale-switch-breadcrumb
Open

Logging: add a breadcrumb on locale switch#212
greatest0fallt1me wants to merge 1 commit into
QuickLendX:mainfrom
greatest0fallt1me:feat/104-locale-switch-breadcrumb

Conversation

@greatest0fallt1me

Copy link
Copy Markdown

Note on scope

This app has no locale-switching UI yet -- `t(key, locale)` takes the locale as an explicit parameter with no client-side preference state or persistence anywhere. Rather than skip the issue, I added the underlying preference-persistence piece a future locale switcher would call, with the breadcrumb wired into it, so it's ready to use as soon as that UI lands.

Change

`lib/i18n/localePreference.ts`:

  • `getStoredLocale()`: reads the persisted locale from `localStorage` (returns `null` on the server or for an unset/invalid value).
  • `setLocalePreference(next)`: persists the new locale and logs a structured breadcrumb (`event: "locale_switched"`, `from`/`to` locale codes, no free-form message) via the existing `log()` utility -- matching `lib/logger.ts`'s "structured fields only" convention already used by `useAlerts`/`ToastProvider`. No-ops (no log) when the locale is unchanged.

Tests

`lib/i18n/localePreference.test.ts`: returns `null` with nothing stored, ignores an invalid stored value, persists a new locale, logs the structured breadcrumb (asserting on the parsed JSON console output, matching `useAlerts.test.ts`'s style), and doesn't log when unchanged.

`npx vitest run lib/i18n/localePreference.test.ts`: 5 passed. `npx tsc --noEmit` / `npx eslint` on changed files: clean.

Closes #104

This app has no locale-switching UI yet (t() takes locale as an
explicit parameter with no client-side preference state), so there
was nowhere to log a locale switch. Add
lib/i18n/localePreference.ts (getStoredLocale/setLocalePreference) as
the underlying preference-persistence piece a future switcher UI can
call: setLocalePreference logs a structured breadcrumb
(event: "locale_switched", from/to locale codes, no free-form
message) whenever the persisted locale actually changes.
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.

Logging: add a breadcrumb on locale switch

1 participant