From 7088ac71e1397c972d3e10d1d38882f054c85ac2 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Thu, 14 Sep 2017 22:54:01 +0200 Subject: [PATCH] Add navigator.locales to expose additional locale details In existing browser implementations, navigator.languages seems to expose the basics of a locale--language, possibly region and script. However, there are additional locale-related settings which are taken as parameters by ECMA 402 and which fit into BCP 47 language tags. It is possible that just changing the value of navigator.languages could break existing sites. For example, localizations which are selected based on the exact value of navigator.language would find an unknwon language if a Unicode extension tag is appended. For this reason, rather than attempting to expose those options via BCP 47 Unicode extension tags, this patch adds a navigator.locales property. navigator.locales is a FrozenArray of Intl.Locale objects. Intl.Locale is a new proposal in TC39 which makes it easier to parse and manipulate language tags. --- source | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/source b/source index 812224dd049..101aa41faf0 100644 --- a/source +++ b/source @@ -2942,6 +2942,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The RangeError class
  • The typeof operator
  • The TypedArray Constructors table
  • +
  • The Intl.Locale class
  • @@ -91375,12 +91376,14 @@ interface NavigatorID { -
    Language preferences
    +
    Language and locale preferences
    [NoInterfaceObject, Exposed=(Window,Worker)]
     interface NavigatorLanguage {
       readonly attribute DOMString language;
       readonly attribute FrozenArray<DOMString> languages;
    +
    +  readonly attribute FrozenArray<Intl.Locale> locales;
     };
    @@ -91397,6 +91400,14 @@ interface NavigatorLanguage {

    The most preferred language is the one returned by navigator.language.

    + +
    self . navigator . locales
    +
    +

    Returns an array of Intl.Locale objects representing the user's preferred locales, + with the most preferred locale first. These locales may include additional Unicode extension tags + such as the user's preferred calendar, numbering system, etc.

    +

    A languagechange event is fired at the @@ -91429,6 +91440,9 @@ interface NavigatorLanguage { returned until the user agent needs to return different values, or values in a different order.

    +

    The language tags contained returned must include only language, region and script, excluding + extensions.

    +

    Whenever the user agent needs to make the navigator.languages attribute of a Window or WorkerGlobalScope object return a new set of language tags, the user agent must @@ -91442,6 +91456,20 @@ interface NavigatorLanguage { +

    locales
    +
    + +

    Must return a frozen array of Intl.Locale objects representing either one + or more plausible languages, or the user's preferred + locales, ordered by preference with the most preferred language first. The same object must be + returned until the user agent needs to return different values, or values in a different order.

    + +

    The Intl.Locale objects provided may include additional Unicode extension tags such + as the user's preferred calendar, numbering system, etc. These may be set by operating system settings, + for example.

    + +
    +

    To determine a plausible language, the user agent should bear in mind the following: