Globalization API - Sample Use Cases

Nicholas C. Zakas standards at nczconsulting.com
Fri Dec 2 13:28:10 PST 2011


Instead of continuing with the previous thread, I figured it would be 
easier to start a new one.

One of my main points about the current Globalization API is that the 
API seems to be designed around complex use cases vs. simple use cases. 
Whether intentional or unintentional the Globalization API fills two 
gaps in ECMAScript: number formatting and date formatting. Setting aside 
the ability to internationalize currencies and dates, this is a 
capability that has long been missing from ECMAScript and developers 
will rejoice if/when it arrives.

That being said, I think there's a strong possibility that simple 
date/number formatting will end up being a popular use case of the API 
as opposed to those who are actively looking for locale-specific changes 
due to an internationalized product. I'd venture a guess to say that the 
common uses would end up being:

1. Date formatting
2. Number formatting
3. Comparing/sorting (with the current Collator)

I would love it if the ability to format numbers and dates were simpler 
than currently spec'ed, more specifically, if the object literals could 
be done away with in favor of formatting strings. Yes, I know formatting 
strings have some limitations, however the way I have created 
internationalized applications in the past has been by abstracting out 
the internationalized parts into configuration files (such as a Java 
properties file). The data from that could then be passed into a JS API 
that Did The Right Thing. Formatting strings make this trivial, needing 
to code up an object literal makes this trickier (JSON is not a great 
format for config files).

Just a few extra cents.

-N

___________________________
Nicholas C. Zakas
http://www.nczonline.net


More information about the es-discuss mailing list