feat: store language code#2481
Conversation
store language code in local storage
Greptile SummaryThis PR stores the selected language code in browser storage. The main changes are:
Confidence Score: 4/5The language persistence path can save stale or inconsistent state during settings changes.
src/lib/lang.js Important Files Changed
Reviews (1): Last reviewed commit: "feat: store language code" | Re-trigger Greptile |
| const lang = langMap[code] || langMap[code = "en-us"]; | ||
| const strings = await lang.strings(); | ||
| window.strings = strings.default; | ||
| window.localStorage["language"] = code; |
There was a problem hiding this comment.
When settings.applyLangSetting() fires lang.set(value) without awaiting it, two quick language changes can resolve out of order. The older lang.strings() import can finish last and this line then persists the stale code, so the next startup can restore a language different from the user's latest selection.
| const lang = langMap[code] || langMap[code = "en-us"]; | ||
| const strings = await lang.strings(); | ||
| window.strings = strings.default; | ||
| window.localStorage["language"] = code; |
There was a problem hiding this comment.
Storage Failure Leaves Split State
When storage is unavailable or throws, this new write rejects after window.strings has already been updated. The settings-change path does not await lang.set(value), so the saved setting, in-memory strings, and persisted language value can diverge without the caller seeing the failure.
| const lang = langMap[code] || langMap[code = "en-us"]; | ||
| const strings = await lang.strings(); | ||
| window.strings = strings.default; | ||
| window.localStorage["language"] = code; |
There was a problem hiding this comment.
Fallback Overwrites Requested Code
For an unsupported input such as a fresh-install navigator.language value of en or es, the fallback expression rewrites code to en-us before the new persistence step. That stores the fallback instead of the requested language code, so anything reading localStorage["language"] loses the original browser/user language value.
store language code in local storage