Intl
developer.mozilla.org
developer.mozilla.org
I've been working on ECMA-402 for the last 6 years on behalf of Mozilla. I'm excited to see it showcased on HN! We have an amazing, inclusive and open community of engineers, linguists and standardization exports from all of the World from largest corporations to smallest non profits and maintainers of open source little libraries.
If you'd like to see what we're working on, see https://github.com/tc39/proposals/blob/master/ecma402/README...
If you'd like to join us, please check out https://github.com/tc39/ecma402/blob/master/CONTRIBUTING.md
Our biggest challenge now is to make sure that anyone can use ECMA-402 - either with a well supported JS engine (V8, SpiderMonkey, JSShell etc.) or via library. To achieve that we're working on Rust project called ICU4X which aims to be able to back ECMA-402 in web browsers, on servers, in client solutions and offer FFI to many programming languages including to JS over WASM.
If you'd like to help us with that, there's tons of work and we're very eager to grow our community! Check out https://github.com/unicode-org/icu4x/blob/main/CONTRIBUTING.... and https://github.com/unicode-org/icu4x/tree/main/docs
If you have any questions, AMA!
Specifically, the table lists Node 12 as supporting Intl, but critically, Node 12 defaults to being built with the `small-icu` dataset. This is not actually sufficient if, for example, you want to correctly format brazilian currency (among many other use cases). For that you want the `full-icu` data set, which can be configured via a env var. Node 14+, however, does thankfully come w/ full-icu by default.
This is also something to be aware also if you're looking at custom size-optimized docker images, since skimping on ICU is a "low-hanging" size optimization.
I think the major thing that will take time behind getting Temporal to Stage 4 is aligning with IETF on [a draft update RFC 3339](https://github.com/ryzokuken/draft-ryzokuken-datetime-extend...)
If you have some experience with Luxon or similar immutable date/time data types then you’ll get to use Temporal in no time. The API is incredibly ergonomic and apparently useless things (such as YearMonth) become so useful for even simpler cases.
That piqued my interest. In my opinion partial date components are only useful for alternative calendar systems or localizations (previously: [1]), so if your use cases are not one of them I'd like to hear more about that.
- data processing and graphing: a lot of data is collected on a monthly basis and represents the aggregate for that month (like monthly energy use). Naively storing it as a full date and ignoring the day means that you now have a compatibility issue with other data, collected monthly, that isn't aggregate (like the height of a tree) - "[THING] of the month": something is chosen by a community poll or admin or however else to be highlighted for/of that month You need something to use as a key for it and a YearMonth captures the requirements perfectly. Especially when you then have to display a localised title above it, having it be a distinct class and not just a full date will save you a lot of trouble. - same as above, but a more business-y use case: various monthly reports. Usually created in the next month, you need a way to represent which month it's "for"
[1] I firmly believe that the localization support is too large for standard libraries. In particular, that "localization support" usually means that you have a ripoff version of CLDR & ICU interface and no equivalent to something like gettext, essential to any actual localization task.
One helping hand is that libraries like date-fns (http://date-fns.org) use it liberally under the hood.
https://caniuse.com/?search=Intl
Hopefully, more people will follow suit and ban IE11 when O365 no longer supports it: https://docs.microsoft.com/en-us/lifecycle/announcements/int...
If I'd use it for all polyfills (which we should maybe consider!), we'd likely self-host the service.
We hope to eventually back SpiderMonkey (Firefox JS engine) implementation with it, but we also want to target WASM and in result expose it as a polyfill for any browser to use.
I don't know if by the time ICU4X is 1.0 IE11 will still matter, but it may be possible to compile it to asm.js and run in IE11 maybe?
Once I realized this I switched to Luxon, which is entirely Intl based: https://moment.github.io/luxon/docs/manual/intl.html
Project Fluent is a great recommendation though, haven't seen before but looks really useful.
Unless the specification has been rewritten under another name, I'm not sure why the date matters? The specification was mostly written by non-mozillians and I still don't quite get the point from m0llusk. Firefox OS and MozIntl APIs is not mentioned nor linked in the submission either. Maybe I'm just missing both of your points entirely, if so, I'm sorry.
There have been 9 revisions of ECMA-402 since 2012. We are, in fact, following TC-39 on a yearly cadence of releases.
You can see the history of editions here: https://www.ecma-international.org/publications-and-standard...
The first edition (finished in 2012), had just NumberFormat, Collator and basic DateTimeFormat.
Since then, we added Locale, PluralRules, ListFormat, RelativeTimeFormat, DisplayNames, two new revisions of NumberFormat, two major additions to DateTimeFormat, and we're now adding Segmenter, LocaleInfo, CalendarInfo and working on MessageFormat 2.0.
Here's a very incomplete list of finished proposals that have been merged into the standard and implemented in browsers - https://github.com/tc39/proposals/blob/master/ecma402/finish...
I may or may not be involved in majority of them! :)
Besides currency, date/time, numeric separators, and unit selection/conversion, that's all that's usually necessary (assuming the app's strings are translated).
It would be ideal to be able to use localized short and long month names, but be able to format the date and time as required.
Or there should be some other standard library/tool to format dates and times, because the JS ecosystem is a mess. Python is great in that way, that it includes everything needed, and you don't have to reinvent the wheel constantly, or try to find which random library does reinventing the best.
const a = new Date("2021/01/02"); // Sat Jan 02 2021 00:00:00 GMT-0800 (Pacific Standard Time)
const b = new Date("2021-01-02"); // Fri Jan 01 2021 16:00:00 GMT-0800 (Pacific Standard Time)
Date library authors have been bit hard because date parsing is hard, and they thought it would be easier to let the Date constructor do the job... only to find out via bug reports about the nasty obscurities of the date parsing rabbit hole.Proper date input usually requires a widget.
The date means different things between the various English locales. In most of them, it means 1st February. In the USA, January 2nd.
Unfortunately, the very unusual US format is the default locale in many systems.
So they want "do the right thing" for 103 out of 104 locales, but "do what I told you" for "MY" locale.
This is a bit of a conundrum because we don't want to treat any locale as "special". To translate it to code you'd write something like:
if (currentLocale == "THE_ONE_UX_CREATED_MOCKS_FOR") {
let value = formatToUXProvidedPattern(data);
} else {
let value = data.toLocaleString(currentLocale);
}
I don't have a great answer how to approach it since there are severe drawbacks and risks to all known potential approaches to "squeeze just one particular format that UX provided into i18n database", but I just wanted to say that we're aware that Intl API has the clash with the UX-driven-development.We could definitely use some help :)
Thank you for writing a user land library for it. It's a thankless task and a very important one and I think such a complex problem deserves a userland solution!
Especially given that everyone and their dog was using moment.js for the longest time, it's always a bit surprised me that spec improvements didn't try to get more coverage for the "generalzied formatting" stuff. Maybe this stuff is all just calling OS internals
I can see an appeal for it, and I wouldn't mind `Date` or `Temporal` to have such pattern-driven formatting, but it is critical to recognize that it is not internationalization and thus doesn't belong there.
In particular, if you use `strftime` like formatting you're doing the opposite - you're hardcoding the formatting into a single pattern. It may be the right thing for your project, but it definitely is not i18n :)
You might say "I want to supply my own pattern, you just do step two for me" and technically we can provide that functionality by exposing it.
The issue is that from the API design perspective it would lead to people misusing the API misunderstanding what is going on and believing that they "internationalized their UI" which is not the case. In fact, they'd make things worse for their users than if they just displayed a date in a single locale with consistent pattern+localization because in some cases "MM/DD" and "DD/MM" are indistinguishable when expanded and that may lead to data loss, security loss, or just confusion.
I'd argue that every case where you want to supply your own pattern is a case where you should not attempt to internationalize that pattern. I also recognize that it's just my opinion.
https://unicode-org.github.io/icu/userguide/transforms/norma...
The place where I live shouldn't define the way numbers or dates are presented to me, or the measurement units I use. That's what international standards are for.
You are welcome to try to convince everyone to use the same language and conventions, go ahead.
In the meantime, the rest of us need tools to deal with the world as it is.