feat(i18n): auto-detect browser language with localStorage persistence (closes #29) — v2 rebase#51
Open
zqleslie wants to merge 1 commit into
Open
Conversation
closes davz7#29) — v2 rebase
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.
Summary (v2 — clean rebase on latest main)
Auto-detects the user's browser language on init and persists manual language toggles in
localStorage, so the app remembers the user's preference across sessions.Replaces PR #50 which became dirty after main received new commits.
Changes
1.
CreditRoot/src/i18n/index.jsi18next-browser-languagedetectorvia.use(LanguageDetector)lng: 'es'order: ['localStorage', 'navigator']— readslocalStorage.getItem('ms-lang')first, falls back tonavigator.languagelookupLocalStorage: 'ms-lang'convertDetectedLanguage— if browser language starts withen, useen; otherwise default toesfallbackLngstayses2.
CreditRoot/package.json"i18next-browser-languagedetector": "^8.2.1"to dependencies3.
CreditRoot/src/components/layout/AppHeader.jsxtoggleLang()to persist user choice:localStorage.setItem('ms-lang', next)Acceptance Criteria (Issue #29)
localStorage.getItem('ms-lang')firstnavigator.language— if starts withen, useen; else defaulteslocalStorage.setItem('ms-lang', lang)fallbackLngstaysesi18next-browser-languagedetectorto dependenciesCloses #29.
Replaces #50 (v2 clean rebase after main received new commits).