On Github rxaviers / globalize-cldr-talk
by Rafael Xavier / @rxaviers / gh:rxaviers
jQuery
<!doctype html5> <html> <body> <script src="message-format.js"></script> <script src="number-format.js"></script> <script src="date-format.js"></script> </body> </html>
You have 2 messages.
You have 1 message.
You have 0 message.
github.com/jquery/globalize/issues/128
(The CLDR specs)
@ master
You have 0 message.
<!doctype html5> <html> <body> <script src="message-format__my-plural-fix.js"></script> <script src="number-format.js"></script> <script src="date-format__my-italian-fix.js"></script> </body> </html>
You have 0 messages.
<!doctype html5> <html> <body> <script src="message-format__new-release.js"></script> <script src="number-format__new-release.js"></script> <script src="date-format__new-releasejs"></script> </body> </html>
You have 0 message.
cldr.unicode.org/index/cldr-spec/json
Where to use it?
Does it support my module loader?
Simple layer to facilitate I18n software to access and use the official CLDR JSON data.
Where to use it?
Does it support my module loader?
Cldr.load( json );
Cldr.load({ main: { en: { ... } }, supplemental: { likelySubtags: { ... }, timeDate: { ... }, weekData: { ... } } });
$.get( "cldr/supplemental/likelySubtags.json", Cldr.load );
define([ "json!cldr/supplemental/likelySubtags.json" ], function( likelySubtags ) { Cldr.load( likelySubtags ); });
Cldr.load( require( "cldr/supplemental/likelySubtags" ) );
var enGb = new Cldr( "en-GB" );locale languageId maxLanguageId language script region en "en" "en-Latn-US" "en" "Latn" "US" en-US "en" "en-Latn-US" "en" "Latn" "US" en-GB "en" "en-Latn-GB" "en" "Latn" "GB" de "de" "de-Latn-DE" "de" "Latn" "DE" zh "zh" "zh-Hans-CN" "zh" "Hans" "CN" zh-TW "zh-TW" "zh-Hant-TW" "zh" "Hant" "TW" ar "ar" "ar-Arab-EG" "ar" "Arab" "EG" pt "pt" "pt-Latn-BR" "pt" "Latn" "BR" pt-BR "pt" "pt-Latn-BR" "pt" "Latn" "BR" pt-PT "pt-PT" "pt-Latn-PT" "pt" "Latn" "PT" es "es" "es-Latn-ES" "es" "Latn" "ES" es-AR "es-AR" "es-Latn-AR" "es" "Latn" "AR"
languageId = `en-GB`
enGb.get( "main/{languageId}/dates/timeZoneNames/gmtFormat" );
region = `GB`
language = `en`
enGb.get( "supplemental/territoryInfo/{region}/{language}" );
wget "http://www.unicode.org/public/cldr/latest/json.zip" unzip json.zip -d cldr
package.json
{ "peerDependencies": { "cldr-data": ">24" } }
bower.json
{ "dependencies": { "cldr-data": ">24" } }
bower install globalize
var formatter = Globalize( "en" ).numberFormatter(); [ 1, 2, 3.14159 ].map(function( x ) { return formatter( x ); }); // [ "1", "2", "3.142" ]
var formatter = Globalize( "en" ).numberFormatter(); app.get( "/", function(req, res){ res.send( formatter( input ) ); });
{ "supplemental": { "plurals-type-cardinal": { "en": { "pluralRule-count-one": "i = 1 and v = 0 @integer 1", "pluralRule-count-other": " @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …" } } } }
Over simplified for demonstration purposes
function( count ) { return count == 1 ? "one" : "other"; }
Norbert Lindenberg, the creator of ECMA-402