question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example of i18next-express-middleware with i18next-node-remote-backend

See original GitHub issue

I tried this:

var i18next = require('i18next');
var middleware = require('i18next-express-middleware');
var backend = require('i18next-node-remote-backend');

i18next
    .use(middleware.LanguageDetector)
    .use(backend)
    .init({
        debug: false,
        detection: {
            order: ['querystring', 'cookie']
        },
        backend: {
            loadPath: 'http://example.com/translate?language={{lng}}',
            crossDomain: true
        }

    });

and it does not seem to fetch the resource when I access the http://localhosst:3000/?lng=en

If I pass the lng manually to the init options, it fetches the desired language passed to this variable, but I’d like to init the language bases on a variable like query param or cookie.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
adyzcommented, Aug 18, 2016

Thanks for all the help, you are right!

1reaction
jamuhlcommented, Aug 17, 2016

you don’t have to init with a specific language on a webserver. think of it - every request comes from a different user with possible different language. If you set language globally you can cause errors by using the wrong language as a user two changes language during user ones request (async nature of node).

You basically should preload all the languages you support on server using the preload option on init (array of languages you want to load).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Any example on using remote backend · Issue #288 · i18next/next ...
It seems it must use node-fs-backend no matter what. If my resources are on remote ... In this case we're talking about i18next-express-middleware...
Read more >
How do you configure i18next-express-middleware?
I am trying to get started using i18next with an Express server, but cannot get it working based on the examples in the...
Read more >
Plugins and Utils - i18next documentation
i18nFormat plugin to use airbnb/polyglot.js format with i18next ... backend layer for i18next used in Node.js & Deno to load translations from the...
Read more >
Node.js web frameworks like express or Fastify and also for ...
This is a middleware to be used with Node.js web frameworks like express or Fastify and also for Deno. It's based on the...
Read more >
i18next-http-middleware vs react-i18next - compare differences and ...
i18next -http-middleware is a middleware to be used with Node.js web frameworks like express or Fastify and also for Deno. (by i18next).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found