Fix default locale to en-US locale (#3356)
This commit is contained in:
parent
d7aa0200c2
commit
5c07ac0916
2 changed files with 1 additions and 43 deletions
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -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(() => {
|
||||
|
|
Loading…
Reference in a new issue