i18next / i18next-xhr-backend

[deprecated] can be replaced with i18next-http-backend
https://github.com/i18next/i18next-http-backend
MIT License
253 stars 75 forks source link

backend hitting additional endpoint and adding a -US to {{lng}} #324

Closed orpheus closed 5 years ago

orpheus commented 5 years ago

Hey, this may be more of a question than a bug.

The backend is correctly fetching the translation json from

http://localhost:8080/public/locales/en/translation.json

but then also hits

http://localhost:8080/public/locales/en-US/translation.json

and get's a 404. Additional failed request on every refresh. I can't seem to find out why it's adding -US and hitting it after it already found a translation json.

Can someone point me in the right direction please?

import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import XHR from 'i18next-xhr-backend'
import LanguageDetector from 'i18next-browser-languagedetector'

 i18n
    .use(XHR)
    .use(LanguageDetector)
    .use(initReactI18next)
    .init( {
  debug: true, // TODO: enable-disable correctly
  fallbackLng: 'en',
  backend: {
    loadPath: `/public/locales/{{lng}}/{{ns}}.json`
  }
})

my translation is in this path

public/locales/en/translation.json

jamuhl commented 5 years ago

the detected language is en-US it will load -> en-US, en, fallbackLng

you can set load option https://www.i18next.com/overview/configuration-options#languages-namespaces-resources or whitelist to avoid loading languages you won't provide...

anyway that 404 is a network error - not to confuse with javascript runtime error!