Logging: add a breadcrumb on locale switch - #212
Open
greatest0fallt1me wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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`:
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