missingKeyHandler is called even when translations exist if I use a custom backend.ajax
See original GitHub issueHello,
I am experiencing an issue with the following configuration (using i18next-react
and this backend plugin):
i18n
.use(initReactI18next)
.use(i18nextXHRBackend)
.init({
lng,
fallbackLng: defaultLng,
debug,
ns: ['common'],
defaultNS: 'common',
interpolation: {
escapeValue: false
},
saveMissing: true,
missingKeyHandler,
backend: {
loadPath: loadPathBaseUrl + '/i18n/{{lng}}/{{ns}}.json',
ajax: loadLngAJAX,
crossDomain: true
}
});
export default i18n;
If I use a custom missingKeyHandler
and a custom backend.ajax
callback, missingKeyHandler
gets fired even when translations exist and are loaded (I see messages in the console if debug
is true
and my missingKeyHandler
is called).
If I comment this line out:
...
//ajax: loadLngAJAX,
...
Everything works and missingKeyHandler
is not fired (as it should be even when using a custom ajax
with this backend plugin).
Do you think this is a bug or is there a reason why I am experiencing this behaviour?
Thank you for your attention.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
i18next missing key whereas the key exists? - Stack Overflow
i18next::translator: missingKey fr common my key. whereas the key is in the translation file (which is correctly loaded and taken into account).
Read more >Javier Martín Alonso|3.2.0
emits missingKey always (like console.log) even if saveMissing is of -> use missingKeyHandler if you only want the trigger only on saveMissing: true ......
Read more >i18next | Yarn - Package Manager
Flexible connection to backend (loading translations via xhr, ...) Optional caching, user language detection, ... Proper pluralizations; Translation context ...
Read more >Source - GitHub
You can enable multiRead support in backends again by using ... (like console.log) even if saveMissing is of -> use missingKeyHandler if you...
Read more >i18next - SimpleLocalize
Configure http-backend feature to manage translations from web ... if you use namespaces }, saveMissing: true, missingKeyHandler: (lngs, ns, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes - not sure what happens - but in the end the code is dead simple…ajax and missingHandler have nothing todo with each other only if the ajax call somehow does not provide the data in correct format for parse (which is a JSON.parse) to succeed. That is what fails currently and your parse dummy “fixes” - the underlying problem still is in your ajax implementation.
But like you say - works with both - so: If it’s ok for you - it’s ok for me 😁
Yes, but I needed to override it with a dummy hook which just return the value because as I understood
parse
is called by thecallback
with the translation data passed to it.Otherwise I am experiencing the misleading behaviour above, at least it works now.