-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Intl
This page applies to v0.12 and following.
The Intl object is available when EcmaScript 402
support is enabled.
Node.js uses ICU4C to implement the Intl object natively.
There are multiple ways to build Node with ICU. Most of this page discusses different ways to build ICU.
You can find other ICU releases at
the ICU homepage.
Download the file named something like icu4c-**##.#**-src.tgz (or
.zip).
Unix/Macintosh: from an already-unpacked ICU
./configure --with-intl=[small-icu,full-icu] --with-icu-source=/path/to/icuUnix/Macintosh: from a local ICU tarball
./configure --with-intl=[small-icu,full-icu] --with-icu-source=/path/to/icu.tgzUnix/Macintosh: from a tarball URL
./configure --with-intl=[small-icu,full-icu] --with-icu-source=http://url/to/icu.tgzWindows: first unpack latest ICU to deps/icu
icu4c-##.#-src.tgz (or .zip)
as deps/icu (You'll have: deps/icu/source/...)
vcbuild.bat small-icu|full-icuThe Intl package can use an ICU which is already built.
Here are some ways to obtain a pre-built ICU:
Run one of these or similar as appropriate for your system:
apt-get install libicu-dev
yum install libicu-dev
-
Download ICU source http://icu-project.org/download
-
Follow the enclosed
readme.htmlto build ICU, particularly paying attention to the--prefixargument -
build ICU and then:
make install
pkg-config --modversion icu-i18n
If this command fails, node will not be able to find the installed ICU.
Verify that the PKG_CONFIG_PATH points to the newly installed icu-i18n.pc file
./configure --with-intl=system-icu
- Download the latest
icu4c-##.#-src.tgz (or
.zip) - Unpack the source as
deps/icu(you should havedeps/icu/source/...)
First: Unpack latest ICU
icu4c-##.#-src.tgz (or .zip)
as deps/icu (You'll have: deps/icu/source/...)
- ./configure ... --with-intl=full-icu
Or, to build the "small" variant (English only):
- ./configure ... --with-intl=small-icu
- vsbuild.bat ...
full-icu
Or, to build the "small" variant (English only):
- vsbuild.bat ...
small-icu
- If you use the "small-icu" option,
you can provide additional data at runtime.
- Two methods:
- The
NODE_ICU_DATAenv variable:env NODE_ICU_DATA=/some/path node - The
--icu-data-dirparameter:node --icu-data-dir=/some/path
- The
- Example: If you use the path
/some/path, then ICU 53 on Little Endian (l) finds:- individual files such as
/some/path/icudt53l/root.res - a packaged data file
/some/path/icudt53l.datsuch as from http://apps.icu-project.org/datacustom/
- individual files such as
- Notes:
- See
u_setDataDirectory()and the ICU Users Guide for many more details. - "53l" will be "53b" on a big endian machine.
- See
- Two methods:
- With the
small-icumode, you can also choose different locales than "English only". For example,--with-icu-locales=de,zh,frwill include only German, Chinese and French but not English. The http://apps.icu-project.org/datacustom/ page will list currently available locale IDs. - Note that this option is also useful for updating ICU's time zone data.
node test/simple/test-intl.js-
btest402.js is a very basic but verbose test of whether
Intlis built correctly.
- See: EcmaScript 402 and http://jsi18n.com/
- Tutorial: Working with Intl
From the ICU documentation:
Time zone data changes often in response to governments around the world changing their local rules and the areas where they apply. ICU derives its tz data from the IANA Time Zone Database.
The ICU project publishes updated timezone resource data in response to IANA updates, and these can be used to patch existing ICU installations. Several update strategies are possible, depending on the ICU version and configuration.
As the ICU Userguide states, it is possible to update time zone data (when ICU 54 and following is used) by:
- setting the
ICU_TIMEZONE_FILES_DIRvariable to point to some directory, such as/timezones - Download the
.resfiles from the appropriate subdirectory of the ICU TZ site (from the44/ledirectory for little endian machines or the44/bedirectory for big endian machines) to the/timezonesdirectory - On node's next restart, it will use the
.resfiles from theICU_TIMEZONE_FILES_DIRvariable to get the latest timezone data.
Note: not recommended. This build is missing some locales, is an older revision, and has a larger output size. It is included here for completeness.
svn checkout --force --revision 214189 \
http://src.chromium.org/svn/trunk/deps/third_party/icu46 \
deps/v8/third_party/icu46
./configure --with-icu-path=deps/v8/third_party/icu46/icu.gyp
make
make install