Enable users to hit en locale
This commit is contained in:
parent
2287411d5a
commit
6bb2b80d11
1 changed files with 9 additions and 4 deletions
|
@ -52,7 +52,7 @@ export const LocaleContext = React.createContext<LocaleContextType>(
|
||||||
|
|
||||||
const { Consumer: LocaleConsumer, Provider: RawLocaleProvider } = LocaleContext;
|
const { Consumer: LocaleConsumer, Provider: RawLocaleProvider } = LocaleContext;
|
||||||
|
|
||||||
enum Locale {
|
export enum Locale {
|
||||||
AR = "ar",
|
AR = "ar",
|
||||||
AZ = "az",
|
AZ = "az",
|
||||||
BG = "bg",
|
BG = "bg",
|
||||||
|
@ -62,6 +62,7 @@ enum Locale {
|
||||||
DA = "da",
|
DA = "da",
|
||||||
DE = "de",
|
DE = "de",
|
||||||
EL = "el",
|
EL = "el",
|
||||||
|
EN = "en",
|
||||||
ES = "es",
|
ES = "es",
|
||||||
ES_CO = "es-co",
|
ES_CO = "es-co",
|
||||||
ET = "et",
|
ET = "et",
|
||||||
|
@ -107,6 +108,8 @@ const localeData: Record<Locale, LocaleMessages> = {
|
||||||
[Locale.DA]: locale_DA,
|
[Locale.DA]: locale_DA,
|
||||||
[Locale.DE]: locale_DE,
|
[Locale.DE]: locale_DE,
|
||||||
[Locale.EL]: locale_EL,
|
[Locale.EL]: locale_EL,
|
||||||
|
// Default language
|
||||||
|
[Locale.EN]: undefined,
|
||||||
[Locale.ES]: locale_ES,
|
[Locale.ES]: locale_ES,
|
||||||
[Locale.ES_CO]: locale_ES_CO,
|
[Locale.ES_CO]: locale_ES_CO,
|
||||||
[Locale.ET]: locale_ET,
|
[Locale.ET]: locale_ET,
|
||||||
|
@ -141,10 +144,10 @@ const localeData: Record<Locale, LocaleMessages> = {
|
||||||
[Locale.ZH_HANT]: locale_ZH_HANT
|
[Locale.ZH_HANT]: locale_ZH_HANT
|
||||||
};
|
};
|
||||||
|
|
||||||
function getMatchingLocale(): Locale {
|
export function getMatchingLocale(languages: readonly string[]): Locale {
|
||||||
const localeEntries = Object.entries(Locale);
|
const localeEntries = Object.entries(Locale);
|
||||||
|
|
||||||
for (const preferredLocale of navigator.languages) {
|
for (const preferredLocale of languages) {
|
||||||
for (const localeEntry of localeEntries) {
|
for (const localeEntry of localeEntries) {
|
||||||
if (localeEntry[1].toLowerCase() === preferredLocale.toLowerCase()) {
|
if (localeEntry[1].toLowerCase() === preferredLocale.toLowerCase()) {
|
||||||
return Locale[localeEntry[0]];
|
return Locale[localeEntry[0]];
|
||||||
|
@ -156,7 +159,9 @@ function getMatchingLocale(): Locale {
|
||||||
}
|
}
|
||||||
|
|
||||||
const LocaleProvider: React.FC = ({ children }) => {
|
const LocaleProvider: React.FC = ({ children }) => {
|
||||||
const [locale] = React.useState(getMatchingLocale() || defaultLocale);
|
const [locale] = React.useState(
|
||||||
|
getMatchingLocale(navigator.languages) || defaultLocale
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IntlProvider
|
<IntlProvider
|
||||||
|
|
Loading…
Reference in a new issue