-
Notifications
You must be signed in to change notification settings - Fork 17
I would like to expose other user settings. Can this proposal accomodate me? #3
Comments
There are two extension keys that can contain this data.
I would like to see us adding both of them in ECMA402 APIs. |
I'm not sure how overlapping it will end up being, but I do have a proposal for DateTimeFormat and NumberFormat to allow for looking into OS regional settings to retrieve custom formatting information. That would address your use case where you specify a custom date or time format (or number format). This information cannot be easily conveyed by extension keys and options, but I believe we can work toward extending ECMA402 APIs to allow systems to do that. But for Intl.Locale API I believe that respecting |
Could you give me at least a vague sketch of how you eventually see people accessing e.g. the user's DateTimeFormat? Would it be |
When @jungshik and I discussed Into user settings, it seemed like it would be better to separate out an API for reading default settings from the core Intl APIs. This would be a disadvantage the second proposal that you list. I wonder how much more we can support the first way. It doesn't sound like it could explain everything, though. Another option could be to allow Locale objects to have further internal slots which describe further OS settings. These would be lost by toString, and not directly readable, but interpreted by Intl constructors. |
Sure, let dtf = new Intl.DateTimeFormat(navigator.locales, {
dateStyle: "short",
useOSRegionalPrefs: true
});
dtf.format(now); |
Is there even an agreed-on format for the DateTimeFormat pattern? LDML/CLDR has a format, but we have been avoiding exposing it so far because Windows uses a different format. |
During the conversation about it the majority of opinions were that we should not expose patterns, but either styles (like I did in the example) or at most skeletons. See tc39/ecma402#109 and tc39/ecma402#108 for details. |
If we logically represent OS preferences in an internal slot of the locale, and then have an option in the bag to use that, then this example would work too. We would throw an exception if used on another locale without that internal slot. |
Well, yes, but we'd need to store pattern for dateShort, dateMedium, dateLong, dateFull, timeShort, timeMedium, timeLong, timeFull, dateTimeShort, dateTimeMedium, dateTimeLong, dateTimeFull... and I didn't even get to custom patterns for numbers. Trying to squeeze custom patterns into locale string via extension keys is imho not going to fly. |
In #3 (comment), what effect does passing |
No, useOSRegionalPrefs only allows us to look into OS prefs for custom date/time patterns and is a separate proposal. navigator.locales provides information about region, hourCycle, firstDayOfWeek, measuring system etc. preferred by the user. Those bits are not only useful across all Intl APIs but also will be used by higher level APIs. |
So what would be the difference between the results in your code if navigator.locales was en-US vs. zh-CN or similar? Assume both people have configured their computer to use Gregorian calendar, YYYY-MM-DD HH:mm:ss format, first day of week as Monday. I don't see how the locale matters in this scenario. |
The differences may not be observable. But if they would define a format with name of the week, or month, we'd have to use the right translation, among other things. Locale comes with a lot of defaults. You can override some of them with extension keys. Developer can ovcerride some of them with options. |
Also, if you'll work between ar and en-US, we'll transliterate numbers to the right calendar, which we'll pick according to the locale, unless you specify a different one in extension keys :) |
I'm not talking about actually exposing properties on the object, or even necessarily having implementations look up information ahead of time. What would be important is just that you'd need to use something from navigator.locales to be allowed to use the options to get the OS defaults. |
Now that using the Intl constructor is based on using internal slots, rather than |
As someone who uses the en-US locale, but sets their date format to YYYY-MM-DD, time format to HH:mm:ss, temperature unit to Celsius, distance unit to km, and thousands separator to a thin space, I am often poorly served when apps use the defaults for my locale, instead of reading from my OS settings.
One other environment I am familiar with, .NET, encompasses at least some of these settings in a CultureInfo, which they say is "called a locale for unmanaged code development". It seems to largely overlap with this proposal, but also have DateTimeFormat and NumberFormat to address my use cases. (It does not have units of measure; I guess that is separate.)
There isn't any description of the list of things exposed, except in the spec, which only lists their names. So it's hard to tell if e.g. numeric formatting info is exposed. But at least according to whatwg/html#3046 , date formats are not supported.
I realize this proposal may be working off some predefined set of things to expose, apparently going under the name "Unicode extension tags". I'm not clear if that means it will never support my use cases, or if there are Unicode extension tags for my use cases that aren't exposed yet, or if you eventually plan on going beyond Unicode extension tags...
If we don't plan to support at least retrieving the user's configured date and number formatting, through a combination of this and the navigator.locales proposal, then I am worried this proposal might not be a good idea, since we'll just need to work on another, very similar proposal for addressing those use cases later, and things would get confusing.
The text was updated successfully, but these errors were encountered: