localizable-intl1.2.8 • Public • Published
I once got a little in trouble with localizing my NodeJS-module properly since NodeJS has no locales but the English one.
Sadly I'm not an English user and I want NodeJS to print dates and numbers in the format according to my current culture (language and region).
For that reason I started to look for some way to get NodeJS' globalization to work.
After some days or hours or... actually I don't really remember... I stumbled over
Intl.js generally adds some classes to the
Intl-namespaces which will make you able to format dates or numbers properly, for instance:
Which prints the current month in German.
Sadly the normal
toLocaleString-calls are still performed in English.
That's why I came to the decision to fork and extend this module.
You can install this module using npm:
npm install --save localizable-intl
At first you need to patch the NodeJS-runtime using Intl polyfill:
You may want to set the default locale after this using the
Intl as any.__setDefaultLocale'de-CH';
After this you're done!
NodeJS' globalization will work like a dream now!
You can try it out using this example:
new Date9E8.toLocaleString;// This prints the correclty localized date// rather than the date in English.//// Output with Polyfilled Intl and default-locale set to 'de-CH':// 11.1.1970, 11:00:00//// Output without Pollyfilled Intl:// 1970-1-11 11:00:00
What does it do?
LocalizableIntl.js overwrites the classes
NumberFormat with new versions which support globalization. These are provided by
Additionally it overwrites following localizable functions in order to make them using the new
You may run into troubles using localizable functions, for instance when using
mocha, causing weird RegEx-errors.
You may want to disable RegEx-cache to make it work properly.
Have a look at Disable RegEx-Cache in order to do so.
Only do this when it's really necessary.
Intl.js uses the Unicode CLDR locale data, as recommended by the specification. The main
Intl.js file contains no locale data itself. In browser environments, the
Intl.__addLocaleData() method. In Node.js, or when using
require('intl'), the data
is automatically added to the runtime and does not need to be provided.
Contents of the
locale-data directory are a modified form of the Unicode CLDR data found at http://www.unicode.org/cldr/.
Intl.js attempts to cache and restore static RegExp properties before executing any regular expressions in order to comply with ECMA-402. This process is imperfect, and some situations are not supported. This behavior is not strictly necessary, and is only required if the app depends on RegExp static properties not changing (which is highly unlikely). To disable this functionality, invoke
Setting the default locale
Node's behaviour causes all localizable calls to be processed in English.
In order to set the default language, invoke following code-line:
Copyright (c) 2017 by Manuel Thalmann
This software is licensed under the MIT license. See the