A JavaScript library for globalization and localization. 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.
Globalize.culture( “fr-FR” ); console.log( Globalize.culture().name ) // “fr-FR”
Globalize.culture([ “es-MX”, “fr-FR” ]); console.log( Globalize.culture().name ) // “es-MX”
In any case, if no match is found, the neutral English culture “en” is selected by default.
If you don't pass a selector, .culture() will return the current Globalize culture.
In this example, the neutral Hebrew culture “he” is given top priority (an unspecified quality is equal to 1). If that language is not an exact match for any of the cultures available in Globalize.cultures, then “es” is the next highest priority with 0.5, etc. If none of these match, just like with the array syntax, the search starts over and the same rules are applied to the corresponding neutral language culture for each. If still none match, the neutral English culture “en” is used.
// assuming a culture with “/” as the date separator symbol Globalize.format( new Date(1955,10,5), “yyyy/MM/dd” ); // “1955/11/05” Globalize.format( new Date(1955,10,5), “dddd MMMM d, yyyy” ); // “Saturday November 5, 1955”
If a percentage is passed into parseInt, the percent sign will be removed and the number parsed as is. Example: 12.34% would be returned as 12.
If a percentage is passed into parseFloat, the percent sign will be removed and the number parsed as is. Example: 12.34% would be returned as 12.34
Globalize.format( 123.45, “d” ); // 123 Globalize.format( 12, “d3” ); // 012
Globalize.format( 123.45, “c” ); // $123.45 Globalize.format( 123.45, “c0” ); // $123 Globalize.format( 123.45, “c1” ); // $123.5 Globalize.format( -123.45, “c” ); // ($123.45)
Globalize.format( 0.12345, “p” ); // 12.35 % Globalize.format( 0.12345, “p0” ); // 12 % Globalize.format( 0.12345, “p4” ); // 12.3450 % Parsing with parseInt and parseFloat also accepts any of these formats.
The Globalize culture files are generated JavaScript containing metadata and functions based on culture info in the Microsoft .Net Framework 4.
“C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild” generator\generator.csproj
“generator\bin\Debug\generator.exe”
Globalize is built using grunt, a node-based build utility. First, make sure grunt is installed globally:
then you can lint and test by simply running grunt in the globalize folder