i18next / i18next-localstorage-backend

This is a i18next cache layer to be used in the browser. It will load and cache resources from localStorage and can be used in combination with the chained backend.
MIT License
88 stars 43 forks source link

Cache fallback values in the users language #40

Closed rschluesselbauer closed 2 years ago

rschluesselbauer commented 2 years ago

🚀 Feature Proposal

Add option to cache translations of the fallback language for the originally requested language.

Motivation

If translations for a language do not exist and the fallback language is used, it would make sense to cache that result for the requested language to avoid multiple requests that always result in a 404.

If translations in the requested language do not exist, we make a bunch of 404 requests with the HTTP backend. Then the fallback language is used and the translations are cached for the fallback language. If the user reloads the page, they have to go through the 404 requests again before falling back to the cache. This could be avoided

Example

Imagine a setup with a localstorage-backend before a http-backend:

Whenever the page is reloaded the 404ing requests would be repeated.

adrai commented 2 years ago

why not simply define supportedLngs and prevent all 404?

rschluesselbauer commented 2 years ago

That is a good point. However, in my case an admin can upload translation files in any language, therefore I do not know

If I want to allow partial translation (translating only some namespaces), then this does not work.

adrai commented 2 years ago

Then you may need to create your own chained-backend logic.

rschluesselbauer commented 2 years ago

Ok if this doesn't make any sense in the context of this cache, I'll close the issue. Thank you for your feedback!