![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
globalize
Advanced tools
Readme
A JavaScript library for internationalization and localization that leverage the official Unicode CLDR JSON data. The library works both for the browser and as a Node.js module.
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).
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.
It's designed to work both in the browser, or in Node.js. It supports both AMD and CommonJS.
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.
File | Minified + gzipped size | Summary |
---|---|---|
globalize.js | 1.1KB | Core library |
globalize/date.js | +3.8KB | Date module provides date formatting and parsing |
globalize/message.js | +0.5KB | Message module provides message translation |
globalize/number.js | +2.6KB | Number module provides number formatting and parsing |
globalize/plural.js | +2.0KB | Plural module provides pluralization support |
Globalize 1.x supports the following browsers:
(Current - 1) or Current denotes that we support the current stable version of the browser and the version that preceded it. For example, if the current version of a browser is 24.x, we support the 24.x and 23.x versions.
IE 8 is supported, but it depends on the polyfill of the ES5 methods below, for which we suggest using es5-shim. Alternatives or more information can be found at Modernizr's polyfills list.
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.
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 |
---|---|
Core module | cldr/supplemental/likelySubtags.json |
Date module | cldr/main/locale /ca-gregorian.jsoncldr/main/ locale /timeZoneNames.jsoncldr/supplemental/timeData.json cldr/supplemental/weekData.json |
Number module | cldr/main/locale /numbers.json |
Plural module | cldr/supplemental/plurals.json |
(b) How am I supposed to get and load CLDR content?
Learn how 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...
Use bower bower install globalize
, or npm npm install globalize
.
By using source files...
git clone https://github.com/jquery/globalize.git
.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
download.
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
functionalities, etc.
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 Cldr.load()
.
Globalize.locale( [locale|cldr] )
Set default locale, or get it if locale argument is omitted.
[new] Globalize( locale|cldr )
Create a Globalize instance.
.dateFormatter( pattern )
Return a function that formats a date according to the given pattern
.
.dateParser( pattern )
Return a function that parses a string date according to the given pattern
.
.formatDate( value, pattern )
Format a date value
according to the given pattern
.
.parseDate( value, pattern )
Parse a string representing a date into a JavaScript Date object according to the given pattern.
Globalize.loadTranslations( json )
Load translation data.
.translate( path )
Translate item given its path.
.numberFormatter( [options] )
Return a function that formats a number according to the given options or locale's defaults.
.numberParser( [options] )
Return a function that parses a string representing a number according to the given options or locale's defaults.
.formatNumber( value [, options] )
Format a number according to the given options or locale's defaults.
.parseNumber( value [, options] )
Parse a string representing a number according to the given options or locale's defaults. If value is invalid, NaN
is returned.
Globalize.formatPlural( value, messageData [, formatValue ] )
Return the appropriate message based on value's plural group: zero
, one
,
two
, few
, many
, or other
.
Globalize.plural( value )
Return the value's corresponding plural group: zero
, one
, two
, few
, many
, or other
.
E_INVALID_CLDR
Thrown when a CLDR item has an invalid or unexpected value.
E_MISSING_CLDR
Thrown when any required CLDR item is NOT found.
E_INVALID_PAR_TYPE
Thrown when a parameter has an invalid type on any static or instance methods.
E_INVALID_PAR_VALUE
Thrown for certain parameters when the type is correct, but the value is invalid.
E_MISSING_PARAMETER
Thrown when a required parameter is missing on any static or instance methods.
E_PAR_MISSING_KEY
Thrown when a parameter misses a required key.
E_PAR_OUT_OF_RANGE
Thrown when a parameter is not within a valid range of values.
E_DEFAULT_LOCALE_NOT_DEFINED
Thrown when any static method, eg. Globalize.formatNumber()
is used prior to
setting the Global locale with Globalize.locale( <locale> )
.
Read more...
E_UNSUPPORTED
Thrown for unsupported features, eg. to format unsupported date patterns. Read more...
āāā bower.json (metadata file)
āāā CONTRIBUTING.md (doc file)
āāā dist/ (consumable files, the built files)
āāā external/ (external dependencies, eg. cldr.js, QUnit, RequireJS)
āāā Gruntfile.js (Grunt tasks)
āāā LICENSE.txt (license file)
āāā package.json (metadata file)
āāā README.md (doc file)
āāā src/ (source code)
ā āāā build/ (build helpers, eg. intro, and outro)
ā āāā common/ (common function helpers across modules)
ā āāā core.js (core module)
ā āāā date/ (date source code)
ā āāā date.js (date module)
ā āāā message.js (message module)
ā āāā number.js (number module)
ā āāā number/ (number source code)
ā āāā plural.js (plural module)
ā āāā plural/ (plural source code)
ā āāā util/ (basic JavaScript helpers polyfills, eg array.map)
āāā test/ (unit and functional test files)
āāā fixtures/ (CLDR fixture data)
āāā functional/ (functional tests)
āāā functional.html
āāā functional.js
āāā unit/ (unit tests)
āāā unit.html
āāā unit.js
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, ie.
core.js
, date.js
, message.js
, number.js
, and plural.js
.
Install Grunt and external dependencies. First, install the
grunt-cli and
bower packages if you haven't before. These should be
installed globally (like this: npm install -g grunt-cli bower
). Then:
npm install && bower install
Tests can be run either in the browser or using Node.js (via Grunt) after having installed the external development dependencies (for more details, see above).
Unit tests
To run the unit tests, run grunt test:unit
, or run grunt connect:keepalive
and open http://localhost:9001/test/unit.html
in a browser (or
http://localhost:9001/test/unit-es5-shim.html
for IE8). 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.
Functional tests
To run the functional tests, create the dist files by running grunt
. Then, run
grunt test:functional
, or open http://localhost:9001/test/functional.html
in
a browser (or http://localhost:9001/test/functional-es5-shim.html
for IE8).
Note that grunt
will automatically run unit and functional tests for you to
ensure the built files are safe.
The goal of the functional tests is to ensure that everything works as expected when it is combined.
Build the distribution files after having installed the external development dependencies (for more details, see above).
grunt
FAQs
A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data.
The npm package globalize receives a total of 327,234 weekly downloads. As such, globalize popularity was classified as popular.
We found that globalize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Ā It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.