[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure data returned from Intl Enumeration is consistent with data supported by Intl objects #814

Open
sffc opened this issue Jul 13, 2021 · 8 comments

Comments

@sffc
Copy link
Contributor
sffc commented Jul 13, 2021

(I remember discussing this before, but I can't find an issue for it)

We should make sure that the lists returned from Intl Enumeration is required by the spec to be the same as the lists of what Intl objects support. For example, Intl.DateTimeFormat should support the calendar systems returned by Intl.supportedValuesOf("calendar"), no more, no less.

@anba
Copy link
Contributor
anba commented Jul 22, 2021

We just have to make sure we don't require to have data which isn't present. For example Intl.NumberFormat accepts any currency and if the currency isn't known, it simply defaults to outputting the currency code:

js> print(new Intl.NumberFormat("en", {style: "currency", currency: "ZZZ"}).format(1))
ZZZ 1.00

whereas Intl.DisplayNames is required to detect and handle unknown currencies. (This example only works with JSC and SM, because V8 doesn't yet support the fallback option for the "currency" type.)

js> print(new Intl.DisplayNames("en", {type: "currency", fallback: "none"}).of("ZZZ")) 
undefined

And some currencies are even only supported for certain locales:

js> print(new Intl.DisplayNames("en", {type: "currency", fallback: "none"}).of("UYW")) 
Uruguayan Nominal Wage Index Unit
js> print(new Intl.DisplayNames("de", {type: "currency", fallback: "none"}).of("UYW")) 
undefined

@FrankYFTang
Copy link
Contributor

any suggestion of how to phrase that in the spec text?

@ljharb
Copy link
Member
ljharb commented Aug 13, 2021

Maybe using a host hook as the source of truth for viable values for both enumeration and also other relevant APIs, and requiring the host hook always return the same values across calls?

@FrankYFTang
Copy link
Contributor

Any suggestion of how to add such mandate into the spec text?

@ljharb
Copy link
Member
ljharb commented Dec 2, 2021

A normative note that says so, like https://tc39.es/ecma262/#sec-hostimportmoduledynamically has ("it must always do so for subsequent calls.").

@sffc
Copy link
Contributor Author
sffc commented Oct 6, 2022

We can work on the editorial language here after it is merged into ECMA-402.

@FrankYFTang FrankYFTang transferred this issue from tc39/proposal-intl-enumeration Jul 31, 2023
@justingrant
Copy link
Contributor

For example, Intl.DateTimeFormat should support the calendar systems returned by Intl.supportedValuesOf("calendar"), no more, no less.

For time zones, what you describe is not the current behavior. Intl.supportedValuesOf("timeZone") returns only canonical time zone IDs (aka "primary time zone identifiers" in current ECMA-262 terminology), while Intl.DateTimeFormat accepts both primary and non-primary IDs.

FWIW, I think that this is the right default behavior, because AFAICT the main use case for Intl.supportedValuesOf("timeZone") is to power a UI dropdown of available time zones, and it would be bad UI to have multiple entries of the same time zone in the dropdown.

For calendars, a similar argument could be made for the deprecated islamicc calendar, where it's probably not good to have a UI dropdown of calendars with two essentially duplicate calendars.

We could extend Intl.supportedValuesOf to an options parameter e.g. Intl.supportedValuesOf('timeZone', { includeDeprecated: true }) if the caller really wanted to get the full list. FWIW, I'd heartily support doing this because it would let apps cache the full list of valid IDs to avoid having to create an (expensive) Intl.DateTimeFormat instance in order to determine whether an ID is valid or not.

@justingrant
Copy link
Contributor

requiring the host hook always return the same values across calls?

FWIW, similar language is already part of https://tc39.es/proposal-temporal/#sup-availablenamedtimezoneidentifiers and https://tc39.es/proposal-temporal/#sup-availablenamedtimezoneidentifiers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants