I'm trying to check user language in pure node js, without any extensions from npm. I used process and global command, there is a lot of specifications but i couldn't find system language
You can use req. headers["accept-language"] to get the language/locale the user has set in his browser.
The Node. js runtime is built on top of a programming language—in this case, JavaScript—and helps in running frameworks itself.
No, it is not visible to the browser. The language is JavaScript but Node totally server-side. it's as secure as any other server environment "Node".
By using JavaScript, this task can be easily done by using: Languages property is available for the navigator interface, which returns the most preferred / user preferred language set in the web browser. This property is read-only.
Here is an OS/node/browser independent way of obtaining the default locale
let locale = Intl.DateTimeFormat().resolvedOptions().locale;
console.log(locale);
Answer is in your question. You don't want to use a plugin, but you can take a look on how they do it :)
The answer is the environment
Spoiler
function getEnvLocale(env) {
env = env || process.env;
return env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE;
}
Don't forget to adapt to the different platform (mac, linux, windows...)
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