cache translations in client

This commit is contained in:
Tom Moor
2020-11-23 21:54:14 -08:00
parent 57c2fd58dc
commit 08fb61ce36
3 changed files with 36 additions and 6 deletions

View File

@@ -94,7 +94,9 @@
"google-auth-library": "^5.5.1",
"http-errors": "1.4.0",
"i18next": "^19.8.3",
"i18next-chained-backend": "^2.0.1",
"i18next-http-backend": "^1.0.21",
"i18next-localstorage-backend": "^3.1.2",
"immutable": "^3.8.2",
"imports-loader": "0.6.5",
"invariant": "^2.2.2",

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,
},

View File

@@ -955,7 +955,7 @@
core-js-pure "^3.0.0"
regenerator-runtime "^0.13.4"
"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.0", "@babel/runtime@^7.12.1", "@babel/runtime@^7.3.1", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.0", "@babel/runtime@^7.12.1", "@babel/runtime@^7.3.1", "@babel/runtime@^7.4.5", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
version "7.12.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e"
integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==
@@ -5926,6 +5926,13 @@ humanize-number@0.0.2:
resolved "https://registry.yarnpkg.com/humanize-number/-/humanize-number-0.0.2.tgz#11c0af6a471643633588588048f1799541489c18"
integrity sha1-EcCvakcWQ2M1iFiASPF5lUFInBg=
i18next-chained-backend@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/i18next-chained-backend/-/i18next-chained-backend-2.0.1.tgz#762f78b30aafc5cab9f85f520f8281172380d1a1"
integrity sha512-IKLRCJ767tPWd3nKQMbcqbjd/tHcv+DjFIkaNd1yJSdnS6PME4lvCRYx+gl3gMMMbCL0r+l1bvRVBkTkRRXGVQ==
dependencies:
"@babel/runtime" "^7.4.5"
i18next-http-backend@^1.0.21:
version "1.0.21"
resolved "https://registry.yarnpkg.com/i18next-http-backend/-/i18next-http-backend-1.0.21.tgz#cee901b3527dad5165fa91de973b6aa6404c1c37"
@@ -5933,6 +5940,13 @@ i18next-http-backend@^1.0.21:
dependencies:
node-fetch "2.6.1"
i18next-localstorage-backend@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/i18next-localstorage-backend/-/i18next-localstorage-backend-3.1.2.tgz#415fcac42d6d66ff8bc878d269c5b5719fdedc2c"
integrity sha512-J81qf9atTAc9iMdHUNKJeAWgUsFvqbxfHIIztmF62tOaINA2AJk0kewJjm8LQDuArkiuW9RhQPbhqbyeZut35g==
dependencies:
"@babel/runtime" "^7.4.5"
i18next-parser@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/i18next-parser/-/i18next-parser-3.3.0.tgz#5cd907aff5e791c043137a4902ab42631cde9656"