Fix default locale to en-US locale (#3356)

This commit is contained in:
Krzysztof Żuraw 2023-03-14 14:25:40 +01:00 committed by GitHub
parent d7aa0200c2
commit 5c07ac0916
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 43 deletions

View file

@ -1,25 +0,0 @@
import { getMatchingLocale, Locale } from "./Locale";
describe("Matches locale to browser settings", () => {
it("if first language is an exact match", () => {
const locales = ["fr", "es", "en"];
expect(getMatchingLocale(locales)).toBe(Locale.FR);
});
it("if there is an exact match, but it's not first preference", () => {
const locales = ["does-not-exist", "tr", "de", "fr"];
expect(getMatchingLocale(locales)).toBe(Locale.TR);
});
it("or returns undefined if there is no match", () => {
const locales = [
"does-not-exist-1",
"does-not-exist-2",
"does-not-exist-3",
];
expect(getMatchingLocale(locales)).toBe(undefined);
});
});

View file

@ -111,20 +111,6 @@ function getKeyValueJson(messages: LocaleMessages): Record<string, string> {
}
}
export function getMatchingLocale(languages: readonly string[]): Locale {
const localeEntries = Object.entries(Locale);
for (const preferredLocale of languages) {
for (const localeEntry of localeEntries) {
if (localeEntry[1].toLowerCase() === preferredLocale.toLowerCase()) {
return Locale[localeEntry[0]];
}
}
}
return undefined;
}
const defaultLocale = Locale.EN;
export interface LocaleContextType {
@ -139,10 +125,7 @@ export const LocaleContext = React.createContext<LocaleContextType>({
const { Consumer: LocaleConsumer, Provider: RawLocaleProvider } = LocaleContext;
const LocaleProvider: React.FC = ({ children }) => {
const [locale, setLocale] = useLocalStorage(
"locale",
getMatchingLocale(navigator.languages) || defaultLocale,
);
const [locale, setLocale] = useLocalStorage("locale", defaultLocale);
const [messages, setMessages] = React.useState(undefined);
React.useEffect(() => {