I volontari di MDN non hanno ancora tradotto questo articolo in Italiano. Unisciti a noi e traducilo tu stesso.
Puoi anche consultare l’articolo in English (US).

The NavigatorLanguage.language read-only property returns a string representing the preferred language of the user, usually the language of the browser UI.

Syntax

var lang = navigator.language 

Value

A DOMStringlang stores a string representing the language version as defined in BCP 47. Examples of valid language codes include "en", "en-US", "fr", "fr-FR", "es-ES", etc.

Note that in Safari on macOS and iOS prior to 10.2, the country code returned is lowercase: "en-us", "fr-fr" etc.

Example

if (window.navigator.language != 'en') {       
  doLangSelect(window.navigator.language); 
}

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'NavigatorLanguage: language' in that specification.
Living Standard Initial definition

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support Yes1 Yes

12

53

114 Yes Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes1 Yes1 Yes4 Yes Yes ?

1. Returns the browser UI language, not the value of the Accept-Language HTTP header.

2. Prior to Firefox 4 this property's value was also part of the user agent string, as reported by navigator.userAgent.

3. Starting in Firefox 5.0 this property's value is based on the value of the Accept-Language HTTP header.

4. Closest available (non-standard) properties are userLanguage and browserLanguage.

See also

Tag del documento e collaboratori

Ultima modifica di: sideshowbarker,