Intl.Locale.prototype.toString()

The Intl.Locale.prototype.toString() returns the Locale's full locale identifier string.

Syntax

locale.toString()

Return value

The locale's Unicode locale identifier string.

Description

The Locale object is a JavaScript representation of a concept Unicode locale identifier. Information about a particular locale (language, script, calendar type, etc.) can be encoded in a locale identifier string. To make it easier to work with these locale identifiers, the Locale object was introduced to JavaScript. Calling the toString method on a Locale object will return the identifier string for that particular Locale. The toString method allows Locale instances to be provided as an argument to existing Intl constructors, serialized in JSON, or any other context where an exact string representation is useful.

Examples

Using toString

let myLocale = new Intl.Locale("fr-Latn-FR", {hourCycle: "h24", calendar: "gregory"});
console.log(myLocale.baseName); // Prints "fr-Latn-FR"
console.log(myLocale.toString()); // Prints "fr-Latn-FR-u-ca-gregory-hc-h24"

Specifications

Specification
ECMAScript Internationalization API (ECMA-402)

Browser compatibility

DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
toStringChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.

Legend

Full support
Full support
No support
No support
See implementation notes.
See implementation notes.

See also