1 of 8

Intl.Locale:

For Stage 2

Daniel Ehrenberg

Igalia

In partnership with Mozilla

TC39 September 2017

2 of 8

Example

let localeName = “en-US-u-ca-chinese”

let locale = new Intl.Locale(localeName,

{numberingSystem: “arab”})

locale.language // “en”

locale.region // “US”

locale.script // undefined

locale.calendar // “chinese”

locale.numberingSystem // “arab”

locale.toString()

// “en-US-u-ca-chinese-nu-arab”

let dtf = new Intl.DateTimeFormat(locale);

dtf.resolvedOptions().calendar // “chinese”

dtf.resolvedOptions().locale // “en-US”

3 of 8

Motivation

  • Parsing and resetting
    • language, region and script of a locale
    • Unicode extension tags in a locale
  • Serializable locale preferences
  • Base for future additions...

4 of 8

Future additions

  • Likely subtags
  • First day of the week
  • Display names/strings
  • HTML navigator.locales
  • OS-default formats
  • (Should any of these be in v1?)

5 of 8

Invalid locales supported?

  • Question from last meeting; Stage 2 blocker
  • Why check supported?
    • What do you do with an unsupported locale? Earlier errors better
  • Why not check? (current spec)
    • Sometimes you want to parse a locale without looking up resources for it

6 of 8

Invalid locales supported?

  • What do other languages do?
    • Java: Silently allow unsupported languages
    • ICU4C: Silently allow unsupported languages
    • Python: locale.setlocale checks; locale.normalize doesn’t check
    • Swift: Allows unknown locales

7 of 8

Invalid locales supported?

  • Recommendation
    • Allow constructing unsupported locales
      • Useful for things like normalization
    • When operations are added to get more things out of locales (e.g., display names, default calendar, etc.), throw on unsupported locales
    • As an argument to, e.g., Intl.DateTimeFormat, detect unsupported using resolvedOptions()

8 of 8

Status

  • Stage 2?