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 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.
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:
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:
This is an impressive, very well thought out hunk of code. I especially like the way you've described Cultures as opposed to languages or countries.
One thing that strikes me is how little actual jQuery is being used in the codebase. Apart from a use (or two) of $.map, $.each and $.inArray, this is just vanilla js wrapped in the jQuery namespace--there's nothing wrong with that, of course.
Seems if you wrote your own map, each, and inArray methods other libs could take advantage of the great stuff here without the jQuery dependency.
Is there some obvious reason that I'm overlooking that this needs to have a jQuery dependency?
So, I definitely like where this is going, but to be perfectly honest, my biggest critique is that you've added many methods to jQuery, where the general rule is to add one to the namespace and anything else should be sub defined. Basically, if you took this:
And did this...
// The Plugin, respecting the jQuery namespace rules for all plugins
// The Plugin's sub methods/properties/settings
(I just picked l10n because its buzzy and stuff :D )
Agreed. Please try to limit your pollution of the namespace, especially since in this case it really isn't needed. Also, I think the ability to localize phone numbers is something that is really lacking right now, since most of the other basic number/date conversions are present.