2020-11-30 04:04:58 +00:00
|
|
|
|
// @flow
|
|
|
|
|
import i18n from "i18next";
|
|
|
|
|
import backend from "i18next-http-backend";
|
|
|
|
|
import { initReactI18next } from "react-i18next";
|
|
|
|
|
|
2021-01-31 22:40:50 +00:00
|
|
|
|
// Note: Updating the available languages? Make sure to also update the
|
2021-09-19 16:45:26 +00:00
|
|
|
|
// locales array in app/utils/i18n.js to enable translation for timestamps.
|
2021-01-31 22:40:50 +00:00
|
|
|
|
export const languageOptions = [
|
|
|
|
|
{ label: "English (US)", value: "en_US" },
|
|
|
|
|
{ label: "简体中文 (Chinese, Simplified)", value: "zh_CN" },
|
2021-07-02 19:08:08 +00:00
|
|
|
|
{ label: "繁體中文 (Chinese, Traditional)", value: "zh_TW" },
|
2021-01-31 22:40:50 +00:00
|
|
|
|
{ label: "Deutsch (Deutschland)", value: "de_DE" },
|
|
|
|
|
{ label: "Español (España)", value: "es_ES" },
|
2021-07-21 17:41:45 +00:00
|
|
|
|
{ label: "فارسی (Persian)", value: "fa_IR" },
|
2021-01-31 22:40:50 +00:00
|
|
|
|
{ label: "Français (France)", value: "fr_FR" },
|
|
|
|
|
{ label: "Italiano (Italia)", value: "it_IT" },
|
2021-07-09 01:32:05 +00:00
|
|
|
|
{ label: "日本語 (Japanese)", value: "ja_JP" },
|
2021-01-31 22:40:50 +00:00
|
|
|
|
{ label: "한국어 (Korean)", value: "ko_KR" },
|
2021-06-10 00:42:14 +00:00
|
|
|
|
{ label: "Português (Brazil)", value: "pt_BR" },
|
2021-01-31 22:40:50 +00:00
|
|
|
|
{ label: "Português (Portugal)", value: "pt_PT" },
|
2021-02-23 18:35:50 +00:00
|
|
|
|
{ label: "Pусский (Россия)", value: "ru_RU" },
|
2021-09-19 16:45:26 +00:00
|
|
|
|
{ label: "Polskie (Polska)", value: "pl_PL" },
|
2021-01-31 22:40:50 +00:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export const languages: string[] = languageOptions.map((i) => i.value);
|
|
|
|
|
|
|
|
|
|
// Languages are stored in en_US format in the database, however the
|
|
|
|
|
// frontend translation framework (i18next) expects en-US
|
|
|
|
|
const underscoreToDash = (text: string) => text.replace("_", "-");
|
|
|
|
|
const dashToUnderscore = (text: string) => text.replace("-", "_");
|
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
|
export const initI18n = () => {
|
2021-01-31 22:40:50 +00:00
|
|
|
|
const lng = underscoreToDash(
|
|
|
|
|
"DEFAULT_LANGUAGE" in process.env ? process.env.DEFAULT_LANGUAGE : "en_US"
|
|
|
|
|
);
|
2020-11-30 04:04:58 +00:00
|
|
|
|
|
|
|
|
|
i18n
|
|
|
|
|
.use(backend)
|
|
|
|
|
.use(initReactI18next)
|
|
|
|
|
.init({
|
|
|
|
|
backend: {
|
|
|
|
|
// this must match the path defined in routes. It's the path that the
|
|
|
|
|
// frontend UI code will hit to load missing translations.
|
2021-01-31 22:40:50 +00:00
|
|
|
|
loadPath: (languages: string[], namespaces: string[]) =>
|
|
|
|
|
`/locales/${dashToUnderscore(languages[0])}.json`,
|
2020-11-30 04:04:58 +00:00
|
|
|
|
},
|
|
|
|
|
interpolation: {
|
|
|
|
|
escapeValue: false,
|
|
|
|
|
},
|
|
|
|
|
react: {
|
|
|
|
|
useSuspense: false,
|
|
|
|
|
},
|
|
|
|
|
lng,
|
|
|
|
|
fallbackLng: lng,
|
2021-01-31 22:40:50 +00:00
|
|
|
|
supportedLngs: languages.map(underscoreToDash),
|
|
|
|
|
// Uncomment when debugging translation framework, otherwise it's noisy
|
|
|
|
|
// debug: process.env.NODE_ENV === "development",
|
2020-11-30 04:04:58 +00:00
|
|
|
|
keySeparator: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return i18n;
|
|
|
|
|
};
|