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

[Feature] Fallback if missing keys #14

Open mwskwong opened 4 years ago

mwskwong commented 4 years ago

So let say i18next-localstorage-backend cached the following resource:

{
     "keyA": "valueA
}

Current Behavior

If the code request for t("keyB"), it will return the default value and will not fallback to other backends.

Feature Request

If the code request for t("keyB"), is it possible to fallback to the next backend (e.g. i18next-xhr-backend)?

jamuhl commented 4 years ago

Won't work. On a per key level but per namespace: https://github.com/i18next/i18next-multiload-backend-adapter

There are two ways to achieve what you like:

a) before going to missed path doing a request to via xhr to find keyB -> bad idea, async, slow -> accessing t is sync b) access xhr backend after taking from cache and merge that into the content of the localStorage cached loaded translations -> removes the value of the cache (only acts now as a first fast preload)

What is your use case? Is changing the version in localStorage cache or setting cache duration not sufficient?

wong2 commented 1 year ago

+1 on this feature