snort/packages/app/src/IntlProvider.tsx

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-02-08 20:16:35 +00:00
import { type ReactNode } from "react";
import { IntlProvider as ReactIntlProvider } from "react-intl";
2023-02-27 11:31:46 +00:00
New Crowdin updates (#364) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Arabic) * feat: add it lang * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (German) * New translations en.json (Hungarian) * New translations en.json (Japanese) * New translations en.json (Chinese Simplified) * New translations en.json (Indonesian) * New translations en.json (Korean) * New translations en.json (Italian) * New translations en.json (Arabic) * New translations en.json (Japanese) * New translations en.json (Indonesian) * New translations en.json (Indonesian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (German) * New translations en.json (Hungarian) * New translations en.json (Japanese) * New translations en.json (Chinese Simplified) * New translations en.json (Indonesian) * New translations en.json (Korean) * New translations en.json (Italian) * New translations en.json (Arabic) * New translations en.json (Italian) * New translations en.json (Japanese) * New translations en.json (Indonesian) * New translations en.json (Italian) * Read preferences directly from localStorage * Add Indonesian to language picker * Update translators
2023-02-28 10:24:55 +00:00
import { ReadPreferences } from "State/Login";
import enMessages from "translations/en.json";
import esMessages from "translations/es.json";
import zhMessages from "translations/zh.json";
import jaMessages from "translations/ja.json";
import frMessages from "translations/fr.json";
import huMessages from "translations/hu.json";
import idMessages from "translations/id.json";
import arMessages from "translations/ar.json";
New Crowdin updates (#364) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Arabic) * feat: add it lang * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (German) * New translations en.json (Hungarian) * New translations en.json (Japanese) * New translations en.json (Chinese Simplified) * New translations en.json (Indonesian) * New translations en.json (Korean) * New translations en.json (Italian) * New translations en.json (Arabic) * New translations en.json (Japanese) * New translations en.json (Indonesian) * New translations en.json (Indonesian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (German) * New translations en.json (Hungarian) * New translations en.json (Japanese) * New translations en.json (Chinese Simplified) * New translations en.json (Indonesian) * New translations en.json (Korean) * New translations en.json (Italian) * New translations en.json (Arabic) * New translations en.json (Italian) * New translations en.json (Japanese) * New translations en.json (Indonesian) * New translations en.json (Italian) * Read preferences directly from localStorage * Add Indonesian to language picker * Update translators
2023-02-28 10:24:55 +00:00
import itMessages from "translations/it.json";
2023-02-08 04:54:33 +00:00
2023-02-08 20:16:35 +00:00
const DEFAULT_LOCALE = "en-US";
2023-02-08 04:54:33 +00:00
const getMessages = (locale: string) => {
2023-02-08 20:16:35 +00:00
const truncatedLocale = locale.toLowerCase().split(/[_-]+/)[0];
2023-02-08 04:54:33 +00:00
2023-02-08 20:16:35 +00:00
switch (truncatedLocale) {
case "es":
return esMessages;
case "zh":
return zhMessages;
case "ja":
return jaMessages;
2023-02-09 13:10:13 +00:00
case "fr":
return frMessages;
case "hu":
return huMessages;
case "id":
return idMessages;
case "ar":
return arMessages;
New Crowdin updates (#364) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Arabic) * feat: add it lang * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (German) * New translations en.json (Hungarian) * New translations en.json (Japanese) * New translations en.json (Chinese Simplified) * New translations en.json (Indonesian) * New translations en.json (Korean) * New translations en.json (Italian) * New translations en.json (Arabic) * New translations en.json (Japanese) * New translations en.json (Indonesian) * New translations en.json (Indonesian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (German) * New translations en.json (Hungarian) * New translations en.json (Japanese) * New translations en.json (Chinese Simplified) * New translations en.json (Indonesian) * New translations en.json (Korean) * New translations en.json (Italian) * New translations en.json (Arabic) * New translations en.json (Italian) * New translations en.json (Japanese) * New translations en.json (Indonesian) * New translations en.json (Italian) * Read preferences directly from localStorage * Add Indonesian to language picker * Update translators
2023-02-28 10:24:55 +00:00
case "it":
return itMessages;
2023-02-08 20:16:35 +00:00
default:
return enMessages;
}
};
2023-02-08 04:54:33 +00:00
export const IntlProvider = ({ children }: { children: ReactNode }) => {
New Crowdin updates (#364) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Arabic) * feat: add it lang * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (German) * New translations en.json (Hungarian) * New translations en.json (Japanese) * New translations en.json (Chinese Simplified) * New translations en.json (Indonesian) * New translations en.json (Korean) * New translations en.json (Italian) * New translations en.json (Arabic) * New translations en.json (Japanese) * New translations en.json (Indonesian) * New translations en.json (Indonesian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (Italian) * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (German) * New translations en.json (Hungarian) * New translations en.json (Japanese) * New translations en.json (Chinese Simplified) * New translations en.json (Indonesian) * New translations en.json (Korean) * New translations en.json (Italian) * New translations en.json (Arabic) * New translations en.json (Italian) * New translations en.json (Japanese) * New translations en.json (Indonesian) * New translations en.json (Italian) * Read preferences directly from localStorage * Add Indonesian to language picker * Update translators
2023-02-28 10:24:55 +00:00
const { language } = ReadPreferences();
const locale = language ?? getLocale();
2023-02-08 20:16:35 +00:00
return (
<ReactIntlProvider locale={locale} messages={getMessages(locale)}>
{children}
</ReactIntlProvider>
);
};
2023-02-27 11:31:46 +00:00
export const getLocale = () => {
return (navigator.languages && navigator.languages[0]) || navigator.language || DEFAULT_LOCALE;
};