Announcing Globalize 1.0

Posted on by

The jQuery Foundation is excited to announce the 1.0 release of the Globalize project, our internationalization (i18n) library. This release has been a long time coming and as Globalize picks up steam and gains more and more adoption every day, we are proud to finally announce the first stable release of this project. We could go on about the features and benefits of this latest release but we felt it was important that you hear it from the source. Below, Rafael Xavier, the lead for the Globalize project, details everything you need to know about the 1.0 release of Globalize and what is yet to come.

An always up-to-date, modular and simple i18n library

Allow me to skip the details and jump to the fun part. Below is what you get with Globalize today, which provides number formatting and parsing, date and time formatting and parsing, currency formatting, message formatting (ICU message format pattern with gender and pluralization support).

Date formatting and parsing

The date module provides methods that convert dates and times from their internal representations to textual form (formatting) and back again (parsing) in a language-independent manner. Your code can conveniently control the length of the formatted date, time, datetime.

locale .dateFormatter({ datetime: "medium" })( new Date() );
en "Feb 20, 2015, 12:15:00 PM"
zh "2015年2月20日 下午12:15:00"
zh-u-nu-native "二〇一五年二月二〇日 下午一二:一五:〇〇"
es "20 de feb. de 2015 12:15:00"
ar "٢٠‏/٠٢‏/٢٠١٥ ١٢،١٥،٠٠ م"

Your code can even select the fields individually, completely independent of the locale conventions. The pattern “GyMMMd” selects era in its abbreviated form, year, month in its abbreviated form, and day.

locale .dateFormatter({ skeleton "GyMMMd" })( new Date() );
en "Feb 20, 2015 AD"
zh "公元2015年2月20日"
es "20 feb. de 2015 d. C."
ar "٢٠ فبراير، ٢٠١٥ م"

 

Relative time formatting

In addition to formatting dates and times, the relative time module provides internationalized messages for date and time fields, using customary word or phrase when available.

locale, value .relativeTimeFormatter( "day" )( value );
en, -15 "15 days ago"
en, 0 "today"
en, 1 "tomorrow"

 

Number formatting and parsing

The number module provides methods that format and parse numbers. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal. Though, it can still conveniently control various aspects of the formatted number like the minimum and maximum fraction digits, integer padding, rounding method, display as percentage, and others.

locale .numberFormatter()( Math.PI );
en (English) "3.142"
es (Spanish) "3,142"
ar (Arabic) "٣٫١٤٢"

Formatting thousands-separators:

locale .numberFormatter()( 1000000 );
en-US (English as spoken in the United States) "1,000,000"
en-IN (English as spoken in India) "10,00,000"

Formatting percentages:

locale .numberFormatter({ style: "percent" })( 0.15 );
en (English) "15%"
es (Spanish) "15 %"
ar (Arabic) "١٥٪"

 

Currency formatting

The currency module provides methods that allow to format a currency. Your code can be completely independent of the locale conventions for which currency symbol to use, whether or not there’s a space between the currency symbol and the value, the side where the currency symbol must be placed, or even decimal digits used by particular currencies. Currencies can be displayed using symbols (the default), accounting form, 3-letter code, or plural messages.

Formatting currencies using symbols:

3-letter currency code en (English) de (German) zh (Chinese) ar (Arabic)
.currencyFormatter( "USD" )( 1 ); "$1.00" "1,00 $" "US$ 1.00" "US$ ١٫٠٠"
.currencyFormatter( "EUR" )( 1 ); "€1.00" "1,00 €" "€ 1.00" "€ ١٫٠٠"
.currencyFormatter( "CNY" )( 1 ); "CN¥1.00" "1,00 CN¥" "¥ 1.00" "ي.ص ١٫٠٠"
.currencyFormatter( "JPY" )( 1 ); "¥1" "1 ¥" "JP¥ 1" "JP¥ ١"
.currencyFormatter( "GBP" )( 1 ); "£1.00" "1,00 £" "£ 1.00" "£ ١٫٠٠"
.currencyFormatter( "BRL" )( 1 ); "R$1.00" "1,00 R$" "R$ 1.00" "R$ ١٫٠٠"

Formatting currencies in their full names:

locale .currencyFormatter( "USD", { style: "name" })( 1 );
en (English) "1.00 US dollar"
de (German) "1,00 US-Dollar"
zh (Chinese) "1.00美元"
ar (Arabic) "١٫٠٠ دولار أمريكي"

Formatting currencies in the accounting form, which, for example, in the English locale uses parens instead of the minus sign for negative numbers:

locale .currencyFormatter( "USD", { style: "accounting" })( -1 );
en (English) "($1.00)"

 

ICU message format support (with gender and pluralization support)

The message module provides methods that allow for the creation of internationalized messages, with optional arguments (variables/placeholders) allowing for simple replacement, gender and plural inflections. The arguments can occur in any order, which is necessary for translation into languages with different grammars.

Globalize.loadMessages({
  en: {
   likeIncludingMe: [
      "{count, plural,",
      "    one {You have one task remaining}",
      "  other {You have {count} tasks remaining}",
      "}"
    ]
  }
});

 

locale, count .messageFormatter( "likeIncludingMe" )({ count: count });
en, 1 "You have one task remaining"
en, 99 "You have 99 tasks remaining"

 

Built on standards

Globalize is based on the Unicode Consortium standards and specifications (UTS#35) and it uses its Common Locale Data Repository (CLDR), the largest and most extensive standard repository of locale data available. CLDR is constantly updated and is used by many large applications and operating systems, so you’ll always have access to the most accurate and up-to-date locale data.

CLDR content

Globalize needs CLDR content to function properly, although it doesn’t embed or host such content. Instead, Globalize empowers developers to load CLDR data the way they want. Vanilla CLDR in its official JSON format (no pre-processing) is expected to be provided. As a consequence, (a) Globalize avoids bugs caused by outdated i18n content. Developers can use up-to-date CLDR data directly from Unicode as soon as it’s released, without having to wait for any pipeline on our side. (b) Developers have full control over which locale coverage they want to provide on their applications. (c) Developers are able to share the same i18n dataset between Globalize and other libraries that leverage CLDR. There’s no need for duplicating data. For more information read our documentation on CLDR Usage.

Browser and Node.js Support

Globalize is systematically tested against desktop and mobile browsers and Node.js. So, using it you’ll get consistent results across the various browsers and between client and server. For more details read our Browser Support section.

Get Started

Install it and use it today. See examples for AMD + bower, or Node.js + npm, or plain JavaScript in our Usage section.

If you’re coming from Globalize 0.x, don’t panic. We’ve created a migration guide for you.

Team and Community

We’re grateful for all the support we have received, specifically from Jörn Zaefferer and Scott González for their help with the initial rewrite concept and for being constant advisors; John Emmons, Steven R. Loomis, and Mark Davis (Unicode) for their help with CLDR and UTS#35 specification questions; Alex Sexton and Eemeli Aro for their messageformat.js and make-plural.js libraries that power respectively our MessageFormat and Plural modules; and the jQuery Foundation for the community building, collaborative efforts and its continued support of Globalize and web internationalization.

We want to also thank Nebojša Ćirić, Mihai Niță, and Shanjian Li (Google); Steven Loomis, Steven Atkin, and John Emmons (IBM); Rick Waldron (Ecma-402 2nd Edition editor); Caridy Patiño and Eric Ferraiuolo (Yahoo); Christophe Jolif and Clement Mathieu (Dojo); Cameron Dutro and Kirill Lashuk (Twitter); Craig Cummings and Tex Texin (jsi18n.com); Santhosh Thottingal and Kartik Mistry (Wikipedia); Axel Hecht (Mozilla); Bruno Lewin and Daniel Goldschmidt (Microsoft); Lily Wen (Adobe); Edwin Hoogerbeets (LG); Eirik Rude (Oracle); Xiang Xu (Paypal); Iskren Chernev (moment.js); and Tingan Ho (l10ns.org) to have joined us in an effort to better coordinate the globalization (internationalization and localization) activity of the JavaScript community. If you want to get involved or read more about it, head over to the javascript-globalization@googlegroups.com mailing list or take a look at our JavaScript Globalization overview page.

Upcoming

We’re working on even more exciting features that will soon be part of Globalize. To name a few: runtime optimization and non-gregorian calendar support. So, if any of these are of your interest, make sure you chime in. Express your thoughts and your needs (e.g., which calendars you want to be supported).
We are always looking for contributors to join our team. If you want to get involved, please read the contributing guide. Your help is very welcome.

17 thoughts on “Announcing Globalize 1.0

  1. Great news, seems a really cool library and other projects might benefit from it!

    PS: I think there’s a typo here:

    `.dateFormatter({ skeleton “GyMMMd” })( new Date() );`

    You are missing the colon after “skeleton”

    :)

  2. This would be very useful for us, probably will be, but why only BC and AD? The bce and ce alternative should have been offered. The name of the common era is a touchy point with some readers who are not Christians.

  3. Marçal Juan Llaó on said:

    What about number abbreviations? 1.000 => 1K. For number bigger than 1 million we don’t abbreviate it for the billion/trillion inconsistency problems. Thanks!