My React app loads from a relative path by setting the homepage
variable in package.json. However i18next-http-backend still tries to load the translations from http://localhost:3000/locales/en/translation.json
instead of http://localhost:3000/myapp/locales/en/translation.json
. I even tried setting the loadPath option (not sure of the syntax though), but that didn't work. Please see below:
i18n
.use(Backend)
.use(initReactI18next)
.init({
fallbackLng: 'en',
debug: true,
loadPath: `${process.env.PUBLIC_URL}/locales/{{lng}}/{{ns}}.json`,
interpolation: {
escapeValue: false // not needed for react as it escapes by default
}
})
How can I make this work?
The
loadPath
needs to be set as part of the initialisation of theBackend
, so you need to do the following...