README
inter
A JavaScript locale library that can be used to render dates, date and date-time intervals, numbers, lists, and more. Also contains localized display names for countries, regions, languages, time zones, and currencies. Most of the informations comes from the Unicode CLDR (Common Localization Data Repository) and is extracted using the cldr module.
Installation
Make sure you have node.js and npm installed, then run:
$ npm install -g inter
Usage
To use inter in node.js, just require the library and use the load
method to get an inter
object with information about a specific
locale:
var localeId = 'en_US',
inter = require('inter').load(localeId);
In the browser you'll most likely want to build a version with only
the specific features and locales you need. There's a buildInter
script in the package that's useful for that. You can build one
completely self-contained file per locale by specifying --type browser
.
You can also build a single file with the data for all locales using
--type bundle
. The active locale will be determined by the value of
the LOCALEID
variable when the bundle is loaded into the
browser. This is tailored especially for assetgraph-builder
with the --locales
switch. Working with a single file is convenient
during development. When doing a production build UglifyJS' dead code
elimination will be used to strip the library down after
buildProduction
has created separate versions of your JavaScript
for each locale.
Reference
inter.countries
An array of objects representing country display names. The array is ordered by display name and contains some additional properties:
require('inter').load('da').countries[0];
{ id: 'AF',
displayName: 'Afghanistan',
regionId: '034',
hasTimeZones: true }
inter.getCountry(countryId)
Get info about a specific country (queried by ID):
require('inter').load('sv').getCountry('SE');
{ id: 'SE',
displayName: 'Sverige',
regionId: '154',
hasTimeZones: true }
inter.regions
An array of objects with region display names and some additional info. The array is
ordered by display name. Superset of inter.countries
and
inter.regions
.
require('inter').load('en_US').regions;
[ { id: '002',
displayName: 'Africa',
hasTimeZones: false },
{ id: '019',
displayName: 'Americas',
hasTimeZones: false },
[...]
{ id: '001',
displayName: 'World',
hasTimeZones: false } ]
inter.getRegion(regionId)
Get info about a specific region, queried by ID:
require('inter').load('en_US').getRegion('018');
{ id: '018',
displayName: 'Southern Africa',
hasTimeZones: false }
inter.territories
An array of objects with territory display names and some additional info. The array is
ordered by display name and contains some additional
properties. Superset of inter.countries
and inter.regions
.
require('inter').load('en_US').territories;
[ { id: 'AF',
displayName: 'Afghanistan',
regionId: '034',
hasTimeZones: true },
{ id: '002',
displayName: 'Africa',
hasTimeZones: false },
[...]
{ id: 'AX',
displayName: 'Åland Islands',
regionId: '154',
hasTimeZones: true } ]
inter.getTerritory(territoryId)
Get info about a specific territory, queried by ID (can be either a region or a country):
require('inter').load('en_US').getTerritory('US');
{ id: 'US',
displayName: 'United States',
regionId: '021',
hasTimeZones: true }
inter.timeZones
An array of objects representing all available time zone display names plus some additional info (Olson/tzdata ID, UTC offset, and the ID of the country it belongs to). The array is ordered by UTC offset and secondarily by display name:
require('inter').load('da').timeZones;
[ { id: 'Pacific/Midway',
utcStandardOffsetSeconds: -39600,
displayName: 'Midway',
countryId: 'UM' },
[...]
{ id: 'Pacific/Kiritimati',
regionId: '057',
utcStandardOffsetSeconds: 50400,
displayName: 'Kiritimati',
countryId: 'KI' } ]
inter.getTimeZone(timeZoneId)
Get info about a specific time zone (queried by its Olson/tzdata ID):
require('inter').load('da').getTimeZone('Europe/Copenhagen');
{ id: 'Europe/Copenhagen',
regionId: '154',
utcStandardOffsetSeconds: 3600,
displayName: 'København',
countryId: 'DK' }
inter.languages
An array of objects representing all available language display names plus some additional info. The array is ordered by display name:
require('inter').load('en_US').languages;
[ { id: 'aa',
displayName: 'Afar',
nativeDisplayName: 'Qafar' },
{ id: 'ab', displayName: 'Abkhazian' },
{ id: 'ace', displayName: 'Achinese' },
[...]
{ id: 'zxx',
displayName: 'No linguistic content' },
{ id: 'zza', displayName: 'Zaza' } ]
inter.getLanguage(languageId)
Get info about a specific language, queried by its ID:
require('inter').load('en_US').getLanguage('zh_hans');
{ id: 'zh_hans',
displayName: 'Simplified Chinese',
nativeDisplayName: '简体中文' }
inter.currencies
An array of objects with all available currency display names, including ids and symbols and instructions for displaying different quantities:
require('inter').load('sv').currencies;
[ { id: 'AWG',
displayName: 'Aruba-gulden',
one: 'Aruba-florin',
other: 'Aruba-floriner' },
{ id: 'BSD',
displayName: 'Bahamas-dollar',
symbol: 'BS