Closed tavurth closed 6 years ago
the xhr-backend is not "universal" you will need to use node-fs-backend on serverside to load translations from filesystem, see example:
nextjs: https://github.com/zeit/next.js/blob/canary/examples/with-react-i18next/server.js#L10 razzle: https://github.com/i18next/react-i18next/blob/master/example/razzle-ssr/src/server.js#L12
xhr-backend is not "universal"
@tavurth
All you have to do is to define another "ajax" (https://github.com/i18next/i18next-xhr-backend/blob/0ec7d848236c379a90017fff53640380a4d0d46c/src/index.js#L11)
I suggest axios.
Eg
import i18next from 'i18next';
import XHR from 'i18next-xhr-backend';
import axios from 'axios';
i18next
.use(XHR)
.init({
backend: {
ajax: axios
...
}
});
Now you have a universal backend plugin.
The main goal of the backend is to be small - no need to pull in an axios module. There is already plenty backends: https://www.i18next.com/overview/plugins-and-utils#backends
On node.js server you will use fs-backend anyway.
Creating a own backend is very simple by the way: https://www.i18next.com/misc/creating-own-plugins#backend
You might create one based on axios for your case and share it with the community?
I don't really see the point to pollute NPM more. This already do the trick perfectly for the ones who need a universal plugin.
https://github.com/i18next/i18next-xhr-backend/issues/281#issuecomment-416757169
can life with that...;) the only thing for sure is - i won't do it...
¯_(ツ)_/¯
It's actually worth recommending it for those already using Axios who don't want another dependency.
And, by the way, having a module named "backend" that cannot be used from the backend is somewhat a silly dev joke 😆
@Vadorequest hm...might rename it to i18next-xhr-access-module-that-uses-xhr-to-load-data-from-backend...but might live with the silly joke...
And what dependecy...this uses browser native XMLHttpRequest
no axios or other big dependency for doing simple xhr
I meant, I prefer to use Axios that is already a dependency in my case, rather than using a custom backend or another backend that is universal, to avoid an extra dependency.
So, the point of all this is, it was a good thing @arsnl mentioned it, despite the fact you weren't too fond of it. 😉
I'm facing the same issue. Must I create a node backend? Is there any plug-in npm for gatsby.js?
@roooby There are several backends for node, like: https://github.com/i18next/i18next-node-fs-backend or https://github.com/i18next/i18next-node-remote-backend... it depends... https://www.i18next.com/overview/plugins-and-utils#backends