Skip to content

Commit

Permalink
fix: infinite redirection in navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernankez committed Oct 18, 2024
1 parent 6014dda commit cb83281
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### v1.1.1

#### Bug Fixes

- 修复在iOS设备上无法打开的问题

### v1.1.0

#### Features
Expand Down
9 changes: 5 additions & 4 deletions src/utils/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ export async function setLocale(locale: AvailableLocales) {
document.querySelector("html")?.setAttribute("lang", locale);
}

export function inferPreferredLocale() {
export function inferPreferredLocale(): AvailableLocales {
const appStore = useAppStore();
if (appStore.locale) {
return appStore.locale;
}
const userLocale = (window.navigator.language || defaultLocale) as AvailableLocales;
if (availableLocales.indexOf(userLocale)) {
if (availableLocales.indexOf(userLocale) > 0) {
return userLocale;
}
const userLocaleWithoutRegion = userLocale.split("-")[0] as AvailableLocales;
if (availableLocales.indexOf(userLocaleWithoutRegion)) {
return userLocaleWithoutRegion;
const availableLocale = availableLocales.find(locale => locale.startsWith(userLocaleWithoutRegion));
if (availableLocale) {
return availableLocale;
}
return defaultLocale;
}

0 comments on commit cb83281

Please sign in to comment.