question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

missingKeyHandler is called even when translations exist if I use a custom backend.ajax

See original GitHub issue

Hello,

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:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jamuhlcommented, Apr 24, 2019

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 😁

0reactions
tonix-tuftcommented, Apr 23, 2019

Yes, but I needed to override it with a dummy hook which just return the value because as I understood parse is called by the callback with the translation data passed to it.

Otherwise I am experiencing the misleading behaviour above, at least it works now.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found