New age globalization and localization. Formats and parses strings, dates and numbers in over 350 cultures.
Want to see pretty graphs? Log in now!
npm install globalize
|59||downloads in the last day|
|295||downloads in the last week|
|1 182||downloads in the last month|
|Last Published By|
|Version||1.0.0-alpha.2 last updated 6 days ago|
|Keywords||utility, globalization, internationalization, multilingualization, localization, g11n, i18n, m17n, L10n, localize, format, parse, translate, strings, numbers, dates, times, calendars, cultures, languages, locales|
- Heads up!
- About Globalize
- Getting started
This is an alpha 1.x version
We're working on the migration to using the Unicode CLDR. This is an alpha version of Globalize. In other words, this is not a software for production environment (yet).
Not accepting 0.x fixes anymore
Patches to the previous 0.x codebase probably can't be used. If you have a problem, please create an issue first before trying to patch it.
Are you looking for 0.x docs? Find them here.
Each language, and the countries that speak that language, have different expectations when it comes to how numbers (including currency and percentages) and dates should appear. Obviously, each language has different names for the days of the week and the months of the year. But they also have different expectations for the structure of dates, such as what order the day, month and year are in. In number formatting, not only does the character used to delineate number groupings and the decimal portion differ, but the placement of those characters differ as well.
A user using an application should be able to read and write dates and numbers in the format they are accustomed to. This library makes this possible, providing an API to convert user-entered number and date strings - in their own format - into actual numbers and dates, and conversely, to format numbers and dates into that string format.
Where to use it?
Where does the data come from?
Globalize uses the Unicode CLDR, the largest and most extensive standard repository of locale data.
We do NOT embed any i18n data within our library. However, we make it really easy to use. Read How to get and load CLDR JSON data for more information on its usage.
Pick the modules you need
|globalize/date.js||+9.2KB||Date module provides date formatting and parsing|
|globalize/number.js||+3.7KB||Number module provides number formatting and parsing|
|globalize/translate.js||+0.7KB||Message module provides message translation|
You need to satisfy Globalize dependencies prior to using it. The good news is, there is only one. It's the cldr.js, which is a CLDR low level manipulation tool.
If you use a package manager like bower or npm, you don't need to worry about it. If this isn't the case, then you need to manually download cldr.js yourself. Check the Hello World examples for more information.
2. CLDR content
Globalize is the i18n software (the engine). Unicode CLDR is the i18n content (the fuel). You need to feed Globalize on the appropriate portions of CLDR prior to using it.
(a) How do I figure out which CLDR portions are appropriate for my needs?
Each Globalize function requires a special set of CLDR portions. Once you know which Globalize functionalities you need, you can deduce its respective CLDR requirements. See table below.
|Module||Required CLDR JSON files|
(b) How am I supposed to get and load CLDR content?
By downloading a ZIP or a TAR.GZ...
Click the github releases tab and download the latest available Globalize package.
By using a package manager...
bower install globalize, or npm
npm install globalize.
By using source files...
git clone https://github.com/jquery/globalize.git.
- Build the distribution files.
Globalize's consumable-files are located in the
./dist directory. If you
don't find it, it's because you are using a development branch. You should
either use a tagged version or build the distribution files yourself.
Read installation above if you need more information on how to
Globalize can be used for a variety of different i18n tasks, eg. formatting or
parsing dates, formatting or parsing numbers, formatting messages, etc. You may
NOT need Globalize in its entirety. For that reason, we made it modular. So, you
can cherry-pick the pieces you need, eg. load
dist/globalize.js to get
Globalize core, load
dist/globalize/date.js to extend Globalize with Date
An example is worth a thousand words. Check out our Hello World demo (available to you in different flavors):
Globalize.load( cldrJSONData )
This method allows you to load CLDR JSON locale data.
Globalize.load()is a proxy to
Globalize.locale( [locale] )
Set default locale, or get it if locale argument is omitted.
Globalize.formatNumber( value [, attributes] [, locale] )
Format a number according to the given attributes and the given locale (or the default locale if not specified).
Globalize.parseNumber( value [, formats], [locale] )
Globalize.formatDate( value, format [, locale] )
Format a date according to the given format and locale (or the current locale if not specified).
Globalize.parseDate( value [, formats] [, locale] )
Globalize.loadMessages( locale, messageData )
Load message data per locale.
Globalize.translate( path [, locale] )
Translate item given its path.
The source files are as granular as possible. When combined to generate the build file, all the excessive/overhead wrappers are cut off. It's following the same build model of jQuery and Modernizr.
Core, and all modules' public APIs are located in the
src/ directory. For
npm install && bower install
Build distribution files.
Tests can be run either in the browser or using Node.js (via Grunt).
To run the unit tests, run
grunt test:unit, or open
file:///.../globalize/test/unit.html in a browser. It tests the very specific functionality
of each function (sometimes internal/private).
The goal of the unit tests is to make it easy to spot bugs, easy to debug.
To run the functional tests, create the dist files by running
grunt. Then, run
grunt test:functional, or open
file:///.../globalize/test/functional.html in a browser. Note that
automatically run unit and functional tests for you to ensure the built files
The goal of the functional tests is to ensure that everything works as expected when it is combined.
MIT © jQuery Foundation and other contributors.