i18next / i18next-chained-backend

An i18next backend to chain multiple backends (add fallbacks, caches, ...)
MIT License
69 stars 10 forks source link

Using locize backend as the backup for a resourcesToBackend primary #33

Open davidemerritt opened 1 year ago

davidemerritt commented 1 year ago

🚀 Feature Proposal

I would like to use the LocizeBackend CDN backend as the cache backup for the local resource backend (resourcesToBackend). We are deploying these on a mobile app - and it isn't appropriate to use a suspense loading fallback for the >100ms of time waiting for the locize CDN on initial app load.

Motivation

We need immediate load of translation files (our mobile app is used in a lot of low service areas so a network request blocking translations is a non-starter), but we love the flexibility that your hosted CDN provides, so ideally we load from disk (bundled files) and then at some frequency ping for new translation values from the CDN.

Maybe this is already possible to use with the ChainedBackend, ResourcesToBackend and LocizeBackend but I could not get it to run. Because there are local files for the ResourcesToBackend, it never tries to read from the LocizeBackend, with the `cacheHitMode: 'refreshAndUpdateStore' attribute set.

Example

adrai commented 1 year ago

resourcesToBackend is not a valid caching backend (it has no save function). i18next-fs-backend for example can be used as caching backend, like here: https://github.com/locize/i18next-locize-backend/blob/master/example/updatable-cache/index.js

And on mobile (react-native etc...) you could use i18next-async-storage-backend it also has a save function.