Lazy loading local resource works, but it keeps calling the function even after the resource is loaded
kpturner opened this issue ยท 2 comments
๐ Bug Report
To Reproduce
I can successfully lazy load certain resources locally using the callback mechanism documented. However, the function seems to get called again (to load the resources again) even though I have already loaded them. I am using vite (not webpack) so the solution is a bit clunky (vite does not allow interpolated strings on a dynamic import).
ResourcesToBackend(async (lang, ns, cb) => {
if (lang === 'en' && [foo', 'bar'].includes(ns)) {
try {
const { default: resources } =
ns === 'foo'
? await import('@core/i18n/foo.json')
: await import('@core/i18n/bar.json')
cb(null, resources)
} catch (err) {
console.error('Failed to load bundled resources', err)
cb(err as Error, null)
}
} else {
cb(null, null)
}
}),
]
Expected behavior
Despite successfully loading the resources here with cb(null, resources)
the function still gets called again for the same language and namespace - as if it is not loaded. However the translations work fine.
Your Environment
- runtime version: node 18
- i18next version: i.e. 23.5.1
- os: Mac
Please provide a complete but minimal reproducible exampe. i18next-resources-to-backend does not trigger any loading, it's all controlled by i18next core
I found out why. The behaviour is correct. I will close this.