Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Fallback if missing keys #14

Open
mwskwong opened this issue Dec 17, 2019 · 2 comments
Open

[Feature] Fallback if missing keys #14

mwskwong opened this issue Dec 17, 2019 · 2 comments

Comments

@mwskwong
Copy link

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
Copy link
Member

jamuhl commented Dec 17, 2019

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

  • A request to load from backend comes before accessing t
  • A key is handled missed if not found

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
Copy link

wong2 commented Nov 10, 2022

+1 on this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants