From fed416279e01b8d2bbc53b48727d0ab183fef2df Mon Sep 17 00:00:00 2001 From: uzlopak Date: Mon, 30 Oct 2023 01:28:53 +0100 Subject: [PATCH] lib: add navigator.language & navigator.languages --- doc/api/globals.md | 44 +++++++++++++++++++++++++++++++++ lib/internal/navigator.js | 24 ++++++++++++++++++ test/parallel/test-navigator.js | 44 ++++++++++++++++++++++++++++++++- 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/doc/api/globals.md b/doc/api/globals.md index ebaaf2a6e0012e..8a2c481a7e5fb4 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -637,6 +637,50 @@ logical processors available to the current Node.js instance. console.log(`This process is running on ${navigator.hardwareConcurrency} logical processors`); ``` +### `navigator.language` + + + +* {string} + +The `navigator.language` read-only property returns a string representing the +preferred language of the Node.js instance. + +The value is representing the language version as defined in RFC <5646>. + +You can override the value of `navigator.language` by setting the +`LC_ALL` environment variable. + +For example: +```sh +LC_ALL=fr-FR node -p "console.log(navigator.language)" +``` + +The fallback value on builds without ICU is `'en-US'`. + +```js +console.log(`The preferred language of the Node.js instance has the tag '${navigator.language}'`); +``` + +### `navigator.languages` + + + +* {Array} + +The `navigator.languages` read-only property returns an array of strings +representing the preferred languages of the Node.js instance. +By default it contains only the value of `navigator.language`. +The fallback value on builds without ICU is `['en-US']`. + +```js +console.log(`The preferred languages are '${navigator.language}'`); +``` + ### `navigator.userAgent`