From 77b0595518d6c51d1662ed42c417a9f58dc9e154 Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Sat, 4 Nov 2023 19:07:42 +0100 Subject: [PATCH] lib: add navigator.language & navigator.languages PR-URL: https://github.com/nodejs/node/pull/50303 Reviewed-By: Yagiz Nizipli Reviewed-By: Geoffrey Booth --- doc/api/globals.md | 42 ++++++++++++++++++++++++++ lib/internal/navigator.js | 24 +++++++++++++++ test/parallel/test-navigator.js | 52 +++++++++++++++++++++++++++++++-- 3 files changed, 115 insertions(+), 3 deletions(-) diff --git a/doc/api/globals.md b/doc/api/globals.md index 187455eee772ff..15b5df3bc42159 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -637,6 +637,47 @@ 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 language will be determined by +the ICU library used by Node.js at runtime based on the +default language of the operating system. + +The value is representing the language version as defined in [RFC 5646][]. + +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 `navigator.languages` contains only the value of +`navigator.language`, which will be determined by the ICU library used by +Node.js at runtime based on the default language of the operating system. + +The fallback value on builds without ICU is `['en-US']`. + +```js +console.log(`The preferred languages are '${navigator.languages}'`); +``` + ### `navigator.platform`