Closed toan2948 closed 2 years ago
i18next-http-backend has no ajax option, but a request option: https://github.com/i18next/i18next-http-backend#backend-options
Thank you @adrai, I have changed the ajax option to a request option as below. But it still does not work. Do I miss something else or what should I notice when changeing to a request option?
old: ajax: (fullUrl, options, callback, data, cache) => { new: request: function (options, fullUrl, data, callback, cache) {...}
A reproducible example would be nice... What is the console showing before the missing logs?
Before the missing logs, console shows this:
I also got this error:
it points to line 83 of i18n.js:
Did you check what is in there?
console.log(localiStorage.getItem(lng + '_cache'))
Running console.log( localStorage.getItem(lng + '_cache'))
I got this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /locales/add/en/footer</pre>
</body>
</html>
So that looks like to be the response from your webserver.
Clear your localstorage cache and check the arguments in your request function before:
console.log({ data, url, fullUrl, options })
x.open(data ? 'POST' : 'GET', url, 1);
Sorry, but I will not continue to debug for you. You have to debug your code yourself.
If you see an issue, provide a reproducible example.
When I refresh the page, I got no more error as above, and the console returns this:
But still warnings:
I will make a reproducible code. If you have any opinion with the above warnings, please let me know.
probably your callback signature is still wrong... instead of callback(translations) it should be callback(null, translations)
I have solved the issue with your suggest on the callback function.
Here is how I changed: -callback('', { status: 200 }) +callback(null, { status: 200, })
-callback(translation, { status: 200 }) +callback(null, { status: 200, data: translation })
-callback(JSON.parse(x.responseText)[ns], x) +callback(null, {data: JSON.parse(x.responseText)[ns]})
Thank you @adrai
🐛 Bug Report
I am converting from i18next-xhr-backend to i18next-http-backend, as i18next-xhr-backend is deprecated. With 'xhr' my project works well, but when changes to 'http' it does not work, the language is not switched. I have changed only two lines of code as follow:
import Backend from "i18next-http-backend"; import XHR from 'i18next-xhr-backend';
i18n .use(LanguageDetector) .use(initReactI18next) .use(XHR) .use(Backend)
With i18next-xhr-backend, I got this console when turning on the debug:
With i18next-http-backend, I got this console when turning on the debug:
What should I do more in converting to i18next-http-backend ?
To Reproduce
The code in i18n.js:
Code in i18nconfig.js:
Expected behavior
The translation should work as before with i18next-xhr-backend. All namespaces are loaded. The languages are switched.
Your Environment