User requests some page and I want to know (on server side) what is the language in his/her browser. So I could render template with the right messages.
On client side it's easy:
var language = window.navigator.userLanguage || window.navigator.language
Express is a popular unopinionated web framework, written in JavaScript and hosted within the Node. js runtime environment. This module explains some of the key benefits of the framework, how to set up your development environment and how to perform common web development and deployment tasks.
js is a server-side JavaScript run-time environment. It's open-source, including Google's V8 engine, libuv for cross-platform compatibility, and a core library. Notably, Node. js does not expose a global "window" object, since it does not run within a browser.
We already discussed the first line of this definition: “Node. js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.” Now let's understand the other two lines so we can find out why Node. js is so popular.
You can use req.headers["accept-language"] to get the language/locale the user has set in his browser.
For easier support, you may want to look into a locale module.
request.acceptsLanguages
will contain a parsed version of request.headers['accept-language']
.
See: http://expressjs.com/en/api.html#req.acceptsLanguages
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With