type: utility
version: 0.1.0a1 (not a jQuery UI version number, as this is a standalone utility)
status: in development (part of Grid project)
documentation: https://github.com/jquery/globalize#readme
demo: http://jquery.github.com/globalize/examples/browser/
npm: globalize
keywords: utility, globalization (g11n), internationalization (i18n), multilingualization (m17n), localization (L10n), localize, format, parse, translate, strings, numbers, dates, times, calendars, cultures, languages, locales
TODOs:
https://github.com/jquery/globalize/issues
1 - Description:
This used to be a jQuery plugin called jquery-global. It is now a JavaScript library called Globalize.
It enables complex culture-aware number and date parsing and formatting, including the raw culture information for hundreds of different languages and countries, as well as an extensible system for localization. We want to thank Microsoft for donating a considerable effort in the creation of this first version of a globalization plugin for jQuery, including jquery-global.js (now globalize.js) as well as the generator program used to generate JavaScript culture files.
Some goals:
- Should do one of:
- export itself as a CommonJS module called "globalize" (if it detects require, exports and module)
- export itself as a single global variable 'Globalize'
- Should contains the entire API and all loaded culture info on the exported module or global variable
- Should allow for loading of culture files after globalize.js is loaded
- Should NOT allow for loading of culture files before globalize.js is loaded
- Should NOT have a dependence on jQuery or any $ variable
- Should NOT have jQuery in the name
- Should have a full test suite that does not use jQuery (to ensure independence)
- Should have a valid npm package.json
- Should be listed in npm
- Should work without modification in a web browser by simple script includes (with or without CommonJS require, exports and module)
- Should remember one current culture, used for all API calls on the global variable Globalize that don't specify a culture
- Should have a way to create a new local globalize object by
- var g = Globalize( "fr" );
- // All subsequent API calls on g have the culture set to "fr", unaffected by setting the culture on global variable Globalize
- // Culture on g can be set to something else, just like on global variable Globalize
The jQuery team no longer maintains a jQuery plugin for globalization, only globalize.js and its accompanying globalize culture files.
In the future, jQuery UI core will expose an API interface that can be met by Globalize. At that point the jQuery UI team will encourage widget authors to utilize this $. utility API to ensure any widget can be globalized in the same way, with or without globalize.js as a dependency.
Draft example code:
/*
* jquery.ui.core.js
*/
(function( $ ) {
// ...
$.localize = Globalize.localize || function( key, defaultValue, culture ) {
return defaultValue;
};
$.format = Globalize.format || function( value, format, culture ) {
return value;
};
$.parseInt = Globalize.parseInt || function( value, radix, culture ) {
return parseInt( value, radix );
};
$.parseFloat = Globalize.parseFloat || function( value, culture ) {
return parseFloat( value );
};
// ...
}( jQuery ));
/*
* jquery.ui.dialog.js
*/
// ...
closeText: $.localize( "closeText.dialog", "Close" );
// ...
Related blog posts:
Related forum threads:
2 - Visual Design:
N/A
3 - Functional Specifications/Requirements:
3.1 Specs for Globalize ( globalize.js )
- Globalize.addCultureInfo( cultureName, extendCultureName, info )
- Globalize.cultures
- mapping of culture codes to culture objects
- Globalize.culture( selector )
- Globalize.findClosestCulture( selector )
- Globalize.format( value, format, culture )
- Globalize.localize( key, culture )
- Globalize.parseInt( value, radix, culture )
- Globalize.parseFloat( value, radix, culture )
- Globalize.parseDate( value, formats, culture )
3.2 Specs for g11n API in jQuery UI core
4 - Markup & Style:
N/A
5 - Latest version of plugin:
http://jquery.github.com/globalize/examples/browser/
6 - Open issues being discussed
- The localize method currently has no support for interpolating values, e.g. "Found {suggestion_count} results", localized to deDE to "{suggestions_count} Ergebnisse gefunden". This can be implemented on the client, but could be an interesting feature for the plugin, making the localize method do a bit more then just object/property lookups. There's also potential for localized formatting of these interpolated values. Once we figure that out, we should figure out the ui.core wrapper.
Comments (5)
aurelien gerits said
at 4:01 am on Jan 4, 2012
Hello I try to simplify the call to globalize, following the example above but an error is returned:
$.localize = Globalize.localize || function( key, defaultValue, culture ) {
return defaultValue;
};
But I just try to simplify: $.localize( "translate", "fr")
This return an error :
this.findClosestCulture is not a function
johnny_reilly said
at 2:40 am on May 7, 2012
Hi Guys,
We've been making use of Globalize.js for some time and we've found it really works well. Date / number localisation on the client has never been easier from our perspective. Thanks for all your efforts!!!
I have to say that we were put off using Globalize.js for quite some time by the "in development" status. One of your team (it may have been Scott but I'm not sure) advised us this was now actually pretty stable. We've definitely found this to be the case and it's really helped us in our projects. We've had no issues with it at all - it does exactly what we need it to do.
I was wondering if it might make sense for Globalize.js to have it's status somehow changed to indicate that it is basically stable and ready for use. Perhaps it might actually be possible to "officially" release this? Based on our own usage I think it's ready to go. I'm not aware of any "killer" problems with it. (Only these: https://github.com/jquery/globalize/issues?labels=bug&page=1&sort=comments&state=open - none of which seems too serious )
I suspect that many other people will be holding back from using it because either they imagine it's likely to change radically again, or simply they wont be allowed to by project managers concerned by using a utility that hasn't even made it to "beta" officially. It would be a shame, and I think a mistake, if Globalize.js wasn't officially released until the grid was as well because this is a *massively* useful utility which stands alone.
Thanks again for your hard work on this - I really appreciate it!
Cheers,
John
Scott González said
at 8:16 am on May 7, 2012
Regardless of how well the current code works, I'm not comfortable publicly marking it as stable. It doesn't fully solve our own problems and we may even change out all of the underlying data for CLDR.
Jörn Zaefferer said
at 6:16 am on May 7, 2012
Hey John,
thanks for your comment. You make a good point. Looks like we should at least land the open Pull Requests before tagging a 1.0.0 release. The 0.1.0 version is not really justified - as you say, its pretty stable already.
I'll ping Richard to make a pass together through the PR queue. Though your feedback on those open ones is very welcome, too.
johnny_reilly said
at 1:10 am on May 8, 2012
Hi Scott / Jörn,
Thanks for both responding!
From my perspective if the underlying data changes (even if all of it changes!) this is not a problem. As long as the API is stable and reliable (which it seems to be) then that is what matters; our code depends only indirectly on the data but directly on the API.
I totally understand that you might have reservations releasing it officially if you still have major changes in mind for the API. But given how useful it's been to us in our projects I think it would be great if the status could even be moved on to indicate that.
Even if the status was marked as "beta" I think that would be good. More people would consider using it and you might even get more activity around the library to solve the few existing issues.
Whatever you decide I just wanted to say that I think this is *great* and thank you again so much for your efforts - you have contributed to my "developer joy"!
You don't have permission to comment on this page.