Hi Everyone,
I am a developer from the Microsoft ASP.NET team. We’ve put together an open source prototype of a jQuery Globalization/Localization plugin, and would love your feedback.
The complete prototype, extensive details of the API and its motivation, and demos are available on GitHub:
And here is another post from Scott Guthrie introducing some of its features with some more examples:
Features
- Supports over 350 different cultures, including country-specific cultures and language, country-neutral cultures.
- Culture information for each culture is available through a simple data structure, accessible to plugins for their own purposes.
- Supports formatting dates to any of these cultures, including those that have non-Gregorian calendars, Gregorian calendars with a year offset, and calendars with multiple Eras.
- Supports formatting numbers to strings as numbers, currency, or percentages, to any of these cultures, including those with very special formatting rules, such as number group sizes that differ between currency and percentages, or have a different number of digits.
- Supports parsing dates and numbers from the culture specific string representation of them back into JavaScript dates and numbers.
- Supports localization through a localize() API that handles selecting the best known match automatically.
- Supports the Accept-Language header value as-is, to select the culture best suited to the user per their browser settings.
- Extensibility allows for plugins to access and add to the culture information, including cultures it does not already support.
- Retrofitted the jQueryUI DatePicker plugin to use this plugin, rather than its existing globalization support. This was fairly simple to do and immediately opens up the range of cultures supported by the plugin to the full set of cultures supported by jQuery.glob.js.
Example
Formatting a date:
- jQuery.format(new Date(1955,10,5), “D”)
This uses the standard date format (represented with the ‘D’ token) for the currently selected culture. The current culture is set via the jQuery.culture field. You can also specify the culture explicitly to format, if desired. Assuming the current culture is ‘ja-JP’ (Japanese in Japan), the result would be:
1955年11月5日
The plugin also adds parseDate, parseInt, and parseFloat methods which allow the reverse of formatting. Assuming the current culture is still ‘ja-JP’, this would return the original JavaScript date:
- jQuery.parseDate(“1955年11月5日”);
There are many supported ‘standard’ date formats, as well as a rich set of custom format tokens to customize the result. I am glossing over the details for brevity here – if you are interested, please do see the extensive readme on GitHub.
You can also view a live demo of the plugin in action, which demonstrates all cultures formatting various sample dates and numbers, here:
Or view a live demo of the retrofitted DatePicker plugin, here:
Thanks!
-Dave Reed