feat: Server side translation setup (#4657)

* Server side translation setup

* docs
This commit is contained in:
Tom Moor
2023-01-07 11:52:09 -08:00
committed by GitHub
parent a333f48102
commit 53414ec3ba
13 changed files with 185 additions and 78 deletions

View File

@@ -1,8 +1,3 @@
import i18n from "i18next";
import backend from "i18next-http-backend";
import { initReactI18next } from "react-i18next";
import { unicodeBCP47toCLDR, unicodeCLDRtoBCP47 } from "../utils/date";
// Note: Updating the available languages? Make sure to also update the
// locales array in app/utils/i18n.js to enable translation for timestamps.
export const languageOptions = [
@@ -77,32 +72,3 @@ export const languageOptions = [
];
export const languages: string[] = languageOptions.map((i) => i.value);
export const initI18n = (defaultLanguage = "en_US") => {
const lng = unicodeCLDRtoBCP47(defaultLanguage);
i18n
.use(backend)
.use(initReactI18next)
.init({
compatibilityJSON: "v3",
backend: {
// this must match the path defined in routes. It's the path that the
// frontend UI code will hit to load missing translations.
loadPath: (languages: string[]) =>
`/locales/${unicodeBCP47toCLDR(languages[0])}.json`,
},
interpolation: {
escapeValue: false,
},
react: {
useSuspense: false,
},
lng,
fallbackLng: lng,
supportedLngs: languages.map(unicodeCLDRtoBCP47),
// Uncomment when debugging translation framework, otherwise it's noisy
keySeparator: false,
returnNull: false,
});
return i18n;
};