Closed dovagueh closed 1 year ago
Your loadPath is wrong.
- loadPath: '/data/{lng}.json',
+ loadPath: '/data/{{lng}}.json',
btw: resGetPath is not an option for i18next-http-backend
Why my path is wrong ?
Why you put a loadpath parameter if it doesn't serve to provide the actual loadpath ?
because the interpolation needs double curly brackets
instead of loadPath: '/data/{lng}.json',
write: loadPath: '/data/{{lng}}.json',
btw: if that still does not solve your issue, please provide a minimal reproducible example repository or codesandbox I can execute...
I have just tried same result
please provide a minimal reproducible example repository or codesandbox I can execute...
import i18n from "i18next"; import Backend from "i18next-http-backend"; import { initReactI18next } from "react-i18next";
//i18n.sync.resStore = {};
i18n
.use(Backend)
.use(initReactI18next)
.init({
fallbackLng: false,
lng: "fr",
resGetPath: '/data/{{lng}}.json',
attributes: ['t', 'i18n'],
ns: ['Translator'],
defaultNS: 'Translator',
interpolation: {
escapeValue: false,
},
Backend:{
loadPath: '/data/{{lng}}.json',
//loadPath: ${window.location.origin}/Data/{{lng}}.json
,
},
debug: true,
react: {
wait: true
}
}, (error, t) => {
if(error)
console.error(error);
});
export default i18n;
This is just a code snipped, and not a reproducible example...
that's the code that is refusing to load the file when I import it my browser just tell me that the translation files is not found. the same code using the hardcoded link work. Meaning i just need to create the folders and the file. For me there is an issue somewhere as i didn't provide this link. maybe my init is wrong somewhere but looking at the documentation it doesn't look so. Looking at the code I have provided it seem to me that the URL value is hardcoded, but i may be wrong as well.
btw:
import i18n from "i18next";
import Backend from "i18next-http-backend";
import { initReactI18next } from "react-i18next";
//i18n.sync.resStore = {};
i18n
.use(Backend)
.use(initReactI18next)
.init({
fallbackLng: false,
lng: "fr",
// resGetPath: '/data/{{lng}}.json', // this is probably an option for jquery-i18next
// attributes: ['t', 'i18n'], // this is probably an option for jquery-i18next
ns: ['Translator'],
defaultNS: 'Translator',
interpolation: {
escapeValue: false,
},
- Backend: {
+ backend: {
loadPath: '/data/{{lng}}.json',
//loadPath: ${window.location.origin}/Data/{{lng}}.json,
},
debug: true,
react: {
- wait: true
+ useSuspence: true
}
}, (error, t) => {
if(error) console.error(error);
});
export default i18n;
Ok backend declaration was wrong. Thanks for the clarification.
🐛 Bug Report
Basically I try to use a specific path folder to store my translation file using I18next-http-backend to load them. But I endup having a loading issue and file not found issue. it was like the path was already hardcoded in the backend because the url reported wasn't my own. I tried to use these parameters
but it doesn't change anything the url the backend was trying is this one
This url haven't been configured by me
To Reproduce
A minimal reproducible example. A codesandbox example or similar or at least steps to reproduce the behavior: In version 2.2.1 just try to load a Json translation file from another folder instead of this one. /locales/{{lng}}/{{namespace}}.json' For me the code that create this bug is located in the provided part below
Clearly the loadpath variable is hardcoded due to the fact that the check for the provided variable will be validated. then it will use this value which is above all and will override the provided path. I think it should be inside the IF statement which is not the case here.
Expected behavior
A clear and concise description of what you expected to happen.
Your Environment