feat(i18n): auto-detect OS/browser locale on first launch#223
Conversation
- Desktop (Tauri): detect OS locale via os:allow-locale plugin - Website: detect browser locale via navigator.languages - Fallback chain: saved preference > URL path > OS/browser locale > English - Both app and website versions updated in sync
…rted - osLocale() returns a Promise in Tauri v2 — must await it - Validate localStorage locale against current supported set; clear it if the locale has been removed in an update
a1a2e3a to
741fc0b
Compare
|
/gemini review |
… empty set When the DOM is not yet parsed or the language switcher is not present on the current page, getSupportedLocales() returns an empty Set. Running validation against an empty set could: - delete a valid saved locale preference - redirect away from valid non-locale paths (e.g. /about) - prevent staying on a valid locale path (e.g. /de/) Fix: only validate and take destructive actions (clear, redirect) when supported.size > 0. When empty, trust the saved preference or URL path.
|
/gemini review |
|
Hi @tyrael-z. This completely breaks the application ( Why the cache in the |
… cache - Guard saved-preference redirect with !window.location.href.includes(locale) to stop constant reloads - Replace cached getSupportedLocales IIFE with a plain DOM query - Keep OS/browser auto-detection when no preference is saved - Mirror changes between app/ and website/
|
Hi @flick9000 Thanks for the review. You're right about the redirect loop in About the cache in Since this PR now has several iterative fix commits, I can squash them into a single commit before merging if you prefer. |
|
It looks fine now, but i think variables names could be more explicit, like here Maybe here change |
|
Hi @flick9000 I’ve applied both naming suggestions:
While making the first change, I also renamed the imported @tauri-apps/plugin-os function from osLocale to getOsLocale to avoid shadowing the new local variable. |
PR Type
What kind of change does this PR introduce?
Description
Automatically detect the user's OS/browser locale on first launch and redirect to the corresponding localized page.
os:allow-localepluginnavigator.languagesde-AT→de)app/andwebsite/versions updated in sync