Closed dcworldwide closed 5 years ago
change the value of version - that will invalidate the cache
it will only return cached value if version is same: https://github.com/i18next/i18next-localstorage-backend/blob/master/src/index.js#L62
Ok i think I get it. Better docs wouldn't hurt.
@dcworldwide would you like to share your feedback/addition for the documentation with us? Or even better, submit a PR? Would be very nice.
Once I get it working ok. What is missing is an example invalidation scenario.
Hello there,
I've the same problem as described by @dcworldwide, I'm not able to invalidate the cache, both using versions
alone and in conjunction with the expirationTime
set to 0
.
How can one correctly invalidate the cache after changing the translation files?
Thanks in advance
@CloudPower97 it's just change the versions
in code it was: versions: { en: 'v1.2', fr: 'v1.1' }
change eg: versions: { en: 'v1.3', fr: 'v1.1' }
--> english will be not loaded from cache
@jamuhl Already tried, it doesn't work...
This is my i18n.js
file:
import i18n from 'i18next'
import detector from 'i18next-browser-languagedetector'
import backend from 'i18next-chained-backend'
import LocalStorageBackend from 'i18next-localstorage-backend' // primary use cache
import XHR from 'i18next-xhr-backend' // fallback xhr load
import { reactI18nextModule } from 'react-i18next'
i18n
.use(detector)
.use(backend)
.use(reactI18nextModule) // passes i18n down to react-i18next
.init({
backend: {
backends: [LocalStorageBackend, XHR],
backendOptions: {
prefix: 'i18next_res_',
versions: {
en: 'v1.0',
it: 'v1.0',
},
},
},
fallbackLng: 'en',
interpolation: {
escapeValue: false, // react already safes from xss
},
whitelist: ['en', 'it'],
ns: ['common', 'homepage'],
defaultNS: 'common',
})
export default i18n
Here's what I've done:
it
translation file in public/locales/it/
it
version in i18n.js
file above from v1.0
to v1.1
Expected behavior : I can see the new updated translation because the cache is now invalidated Current behavior: I can't see the new updated translation because the cache is NOT invalidated.
Am I doing something wrong?
As stated before I also tried adding expirationTime: 0
to force somehow the invalidation, but this didn't the trick.
Thank you for your time
https://github.com/i18next/i18next-chained-backend#backend-options backend options is an array per backend in chained backend...
@jamuhl Whoops, completely missed it! Thank you, everything is working fine now!
If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project -> there are many ways to help this project :pray:
Could you please expand on your explanation of the versions option? I don't really understand how it's supposed to be used.
I want to know how to invalidate the local storage cache of my user when releasing a new version of my translations. How can I do that?
Thanks