cache translations in client

This commit is contained in:
Tom Moor committed 2020-11-23 21:54:14 -08:00
1 parent 57c2fd58dc
commit 08fb61ce36
3 files changed
+36 -6

No files matched your search

+19 -5
View File
@@ -1,6 +1,8 @@
// @flow
import i18n from "i18next";
import backend from "i18next-http-backend";
import Backend from "i18next-chained-backend";
import HttpApi from "i18next-http-backend";
import LocalStorageBackend from "i18next-localstorage-backend";
import { initReactI18next } from "react-i18next";
const initI18n = () => {
@@ -8,12 +10,24 @@ const initI18n = () => {
"DEFAULT_LANGUAGE" in process.env ? process.env.DEFAULT_LANGUAGE : "en_US";
i18n
.use(backend)
.use(Backend)
.use(initReactI18next)
.init({
backend: {
loadPath: "/locales/{{lng}}.json",
},
backend:
process.env.NODE_ENV === "test"
? {}
: {
backends: [LocalStorageBackend, HttpApi],
backendOptions: [
{
prefix: "translations-",
expirationTime: 7 * 24 * 60 * 60 * 1000,
},
{
loadPath: "/locales/{{lng}}.json",
},
],
},
interpolation: {
escapeValue: false,
},