i18next / i18next-http-backend

i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
MIT License
443 stars 67 forks source link

Version 2.0.0 breaks reloadResources #101

Closed medihack closed 1 year ago

medihack commented 1 year ago

🐛 Bug Report

After upgrading to Version 2.0.0 (also just tried 2.0.1) the i18next instance still contains the old data after calling reloadResources and the promise is resolved. The data is correctly fetched from the server (my API route is hit), but the store isn't updated anymore. Works without a problem with v1.4.5.

To Reproduce

// also doesn't work when using the callback
i18next.reloadResources(lng, ns).then(() => {
  console.log(i18next.store) // still contains the old data
})

Expected behavior

The store should be correctly updated.

Your Environment

adrai commented 1 year ago

v2.0.0 was just a typescript change... Can you please provide a minimal reproducible example?

adrai commented 1 year ago

btw: just tested it based on this example: https://github.com/i18next/i18next-http-backend/tree/master/example/node and seems to work as expected

medihack commented 1 year ago

Ok, that's strange then. The only other thing I did is to get rid of the i18next-multiload-backend-adapter as I thought it isn't necessary anymore.

This is the old way I set it up (v1.4.5):

import i18next, { InitOptions } from "i18next"
import HttpBackend from "i18next-http-backend"
import BackendAdapter from "i18next-multiload-backend-adapter"
import { defaultConfig } from "./i18nDefaultConfig"

export const createClient = (config: InitOptions) => {
  const instance = i18next.createInstance()

  // TODO: fix types, see https://github.com/i18next/i18next-fs-backend/issues/20
  const backend = {
    backend: HttpBackend,
    backendOption: {
      loadPath: "/api/locales?lng={{lng}}&ns={{ns}}",
    },
  } as any

  const initPromise = instance.use(BackendAdapter).init({
    ...defaultConfig,
    backend,
    ...config,
  })

  return { i18n: instance, initPromise }
}

And this the new way (v2.0.1):

import i18next, { InitOptions } from "i18next"
import HttpApi from "i18next-http-backend"
import { defaultConfig } from "./i18nDefaultConfig"

export const createClient = (config: InitOptions) => {
  const instance = i18next.createInstance()

  const initPromise = instance.use(HttpApi).init({
    ...defaultConfig,
    backend: {
      allowMultiLoading: true,
      loadPath: "/api/locales?lng={{lng}}&ns={{ns}}",
    },
    ...config,
  })

  return { i18n: instance, initPromise }
}

Can it be that multiloading is the problem? If things are still unclear I can try to setup a minimal example.

adrai commented 1 year ago

Adapter is still needed to enable MultiLoading https://github.com/i18next/i18next-multiload-backend-adapter

https://github.com/i18next/i18next-http-backend#backend-options

image
medihack commented 1 year ago

Ok, I see. Sorry for wasting your time :-( Never thought of that as refreshing the page showed everything correctly because of SSR. I wait for the 2.0.0 npm release of i18next-multiload-backend-adapter and bring it back in. Thanks a lot for your help and all the work you put into i18next! Closing this issue for now.