Extra HTTP requests
See original GitHub issue🐛 Bug Report
After loading the web application, an http request goes out to get localization data from *loadPath
.
If you change the current language, then the corresponding files will come from the backend - this behavior is quite logical,because I only get files that will use.
Folders structure
- public/
--- locales/
----- ru
------- translation.json
------- filters.json
----- ua
------- translation.json
------- filters.json
In i18n options I also use LanguageDetector
, which helps me to save the current state of the language in local storage (init file below)
i18n
.use(Backend)
.use(LanguageDetector)
.use(initReactI18next)
.init({
initImmediate: false,
fallbackLng: 'ru',
debug: isDebugMode,
ns: ['filters'],
defaultNS: 'translation',
interpolation: {
escapeValue: false,
formatSeparator: ','
},
react: {
wait: true,
useSuspense: true
},
backend: {
loadPath: './locales/{{lng}}/{{ns}}.json' // * where i store my locales
},
detection: {
order: ['localStorage'],
caches: ['localStorage', 'cookie'],
cookieMinutes: 80
}
})
Further, after switching the language and reloading the page, I will receive a json
that corresponds to the current language. But there will also be extra requests to get localization files that should not be used
*red dots mark unnecessary requests
To Reproduce
In other words.
I ran the page for the first time and got the files corresponding to ‘fallbackLng’ - from locales/ru/*
Then I changed the language to ua, the changes were saved in localStorage, and after reboot, I hope to only get the files from locales/ua/*
.
But in the end I get files from both directories
Expected behavior
After changing the language and reloading the page, I want to receive those files that correspond to the current language, avoiding unnecessary requests
Your Environment
- runtime version: browser -> react-i18next v11.3.4
- i18next version: 19.3.4
- os: Windows / Mac
Issue Analytics
- State:
- Created 3 years ago
- Comments:22 (12 by maintainers)
I think yes
Well. I will reinstall all my libraries, re-read the documentation again and try to figure out the cause of this problem. Perhaps this problem is from my side. Probably should close this issue?
Thank you very much for your help and for 3 hours of your time!