View
 

Globalize

Page history last edited by Jörn Zaefferer 7 months, 1 week ago

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)

documentationhttps://github.com/jquery/globalize#readme

demohttp://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 )
    • TODO 
  • Globalize.cultures
    • mapping of culture codes to culture objects 
  • Globalize.culture( selector )
    • TODO 
  • Globalize.findClosestCulture( selector )
    • TODO 
  • Globalize.format( value, format, culture )
    • TODO 
  • Globalize.localize( key, culture )
    • TODO 
  • Globalize.parseInt( value, radix, culture )
    • TODO 
  • Globalize.parseFloat( value, radix, culture )
    • TODO 
  • Globalize.parseDate( value, formats, culture )
    • TODO 

 

3.2 Specs for g11n API in jQuery UI core

 

  • TODO

 


 

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 (1)

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

You don't have permission to comment on this page.