Skip to content

Commit

Permalink
lang firefox support
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamics committed Nov 15, 2023
1 parent edef43e commit 2e021f6
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/pages/user-settings/account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,23 @@ const Account = () => {

const ChangeLanguage = async (locale: string) => {
if (locale === "default") {
localStorage.removeItem("ztnet-language"); // Remove the local storage value for 'default' selection
localStorage.removeItem("ztnet-language");

// Detect the browser locale and fallback to the defaultLocale if it's not supported
const browserLocale = navigator.language.split("-")[0];
const isLocaleSupported = supportedLocales.includes(browserLocale);
// Use navigator.languages for better cross-browser support
const browserLocales = navigator.languages.map((lang) => lang.split("-")[0]);
const isLocaleSupported = browserLocales.some((lang) =>
supportedLocales.includes(lang),
);
// Find the first supported locale or fallback to defaultLocale
const matchedLocale =
browserLocales.find((lang) => supportedLocales.includes(lang)) || defaultLocale;

await push(asPath, asPath, {
locale: isLocaleSupported ? browserLocale : defaultLocale,
locale: isLocaleSupported ? matchedLocale : defaultLocale,
});
} else {
localStorage.setItem("ztnet-language", locale); // Save the selected locale in local storage
await push(asPath, asPath, { locale }); // Navigate to the current path with the new locale
localStorage.setItem("ztnet-language", locale);
await push(asPath, asPath, { locale });
}
};

Expand Down

0 comments on commit 2e021f6

Please sign in to comment.