Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Async init on i18next reload resurce

I'm using the i18next library in version "i18next": "^21.8.0" ,to localize my React app.

When I tried to reload an await resource, I saw many examples, but no one was able to show me how to load a json file async.

When I try to add the resource through console.log(await langRequest), I get the correct input.

There is the function that returns the JSON file correctly for me:

const langRequest = async () => {
    const url = createUrl('Ajax/GetStrings', { lang: 'he' });
    const languageResponse = await get(url);
    return languageResponse;
}

And there is the init method:

i18n.use(initReactI18next).init({
    resources: {
        he: { translation: await langRequest }
    },
    fallbackLng: 'en',
    debug: true,
    react: {
        useSuspense: false
    }
})

I tried to write this code witout await before the langRequest but it still not working.

  • The init is outside of component brackets.

  • I tried using an empty resource and i18next.addResourceBundle(language, {languageResponse}); in useEffect, but got the following error:

bundle.js:149045 Uncaught (in promise) TypeError: key.indexOf is not a function at cleanKey (bundle.js:149045:23) at getLastOfPath (bundle.js:149069:8) at getPath (bundle.js:149092:25) at ResourceStore.addResourceBundle (bundle.js:149411:18) at I18n._this2. [as addResourceBundle] (bundle.js:151544:50) at bundle.js:868:53

Thanks a lot to all helpers!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Loading resources via http does not work like that... You need an i18next backend plugin.

A complete blog post based on react can be found here.

Also have a look at this documentation.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!