fix: client locale inference (#10893)
* fix: client locale inference * Update I18nLanguageHandler.tsx * More fixes * Update I18nLanguageHandler.tsx * Update I18nLanguageHandler.tsx * Addressing feedback * Fix: first render issues * Update Credits.tsx * Fixed tests * fix: try without loose locale pick * Revert "fix: try without loose locale pick" This reverts commit 5ed649c13117fee8bc507098353de0f18e98d971. * fix: sorts locales so specifics are chosen first * fix: switches client locale matcher
This commit is contained in:
1 parent
38921e58cd
commit
c4b9a9e2f4
4 files changed
+13
-4
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import parser from "accept-language-parser";
|
||||
import { lookup } from "bcp-47-match";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import { useEffect } from "react";
|
||||
@@ -28,7 +28,7 @@ function useClientLocale(locales: string[]) {
|
||||
if (typeof window !== "undefined") {
|
||||
// This is the only way I found to ensure the prefetched locale is used on first render
|
||||
// FIXME: Find a better way to pick the best matching locale from the browser
|
||||
return parser.pick(locales, window.navigator.language, { loose: true }) || window.navigator.language;
|
||||
return lookup(locales, window.navigator.language) || window.navigator.language;
|
||||
}
|
||||
// If the browser is not available, use English
|
||||
return "en";
|
||||
|
||||
Reference in new issue
Block a user