I’m trying to use i18next caching solution but it is not clear to me what is wrong because I don’t see the storage in browser’s Application tab.
This project does not contain a backend. It’s a self-contained web component with plain Javascript.
Here’s the code.
<code>import i18next from 'i18next';
import resourcesToBackend from 'i18next-resources-to-backend';
import LocalStorageBackend from 'i18next-localstorage-backend';
import ChainedBackend from "i18next-chained-backend";
let initialized = false;
const userLocale = navigator.language.split('-')[0];
export function initTranslation() {
if (!initialized) {
i18next
.use(resourcesToBackend((lng, ns) => import(`./my/path/common-${lng}.json`), 'commonResource'))
.use(ChainedBackend)
.init({
debug: true,
fallbackLng: 'en',
lng: userLocale,
backend: {
backends: [LocalStorageBackend],
backendOptions: [{
projectId: 'mytranslation',
expirationTime: 7 * 24 * 60 * 60 * 1000 // 7 days
}]
}
});
initialized = true;
}
</code>
<code>import i18next from 'i18next';
import resourcesToBackend from 'i18next-resources-to-backend';
import LocalStorageBackend from 'i18next-localstorage-backend';
import ChainedBackend from "i18next-chained-backend";
let initialized = false;
const userLocale = navigator.language.split('-')[0];
export function initTranslation() {
if (!initialized) {
i18next
.use(resourcesToBackend((lng, ns) => import(`./my/path/common-${lng}.json`), 'commonResource'))
.use(ChainedBackend)
.init({
debug: true,
fallbackLng: 'en',
lng: userLocale,
backend: {
backends: [LocalStorageBackend],
backendOptions: [{
projectId: 'mytranslation',
expirationTime: 7 * 24 * 60 * 60 * 1000 // 7 days
}]
}
});
initialized = true;
}
</code>
import i18next from 'i18next';
import resourcesToBackend from 'i18next-resources-to-backend';
import LocalStorageBackend from 'i18next-localstorage-backend';
import ChainedBackend from "i18next-chained-backend";
let initialized = false;
const userLocale = navigator.language.split('-')[0];
export function initTranslation() {
if (!initialized) {
i18next
.use(resourcesToBackend((lng, ns) => import(`./my/path/common-${lng}.json`), 'commonResource'))
.use(ChainedBackend)
.init({
debug: true,
fallbackLng: 'en',
lng: userLocale,
backend: {
backends: [LocalStorageBackend],
backendOptions: [{
projectId: 'mytranslation',
expirationTime: 7 * 24 * 60 * 60 * 1000 // 7 days
}]
}
});
initialized = true;
}