i18n-nationality
Nationalities as adjectives mapped to Country codes. This repository is heavily based on the i18n-iso-countries repository by michaelwittig.
https://github.com/michaelwittig/node-i18n-iso-countries
i18n for nationalities of ISO 3166-1 country codes. We support Alpha-2, Alpha-3 and Numeric codes from http://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements
Installing
Install it using npm: npm install i18n-nationality
var nationalities = require("i18n-nationality");
If you use i18n-nationality
with Node.js your are done. If you use the package in a browser environment you also have to register the languages you want to use to minimize file size.
nationalities.registerLocale(require("i18n-nationality/langs/en.json"));
nationalities.registerLocale(require("i18n-nationality/langs/de.json"));
Code to Nationality
Get the name of a nationality by its ISO 3166-1 Alpha-2, Alpha-3 or Numeric code
var nationalities = require("i18n-nationality");
console.log("US (Alpha-2) => " + nationalities.getName("US", "en"));
console.log("US (Alpha-2) => " + nationalities.getName("US", "de"));
console.log("USA (Alpha-3) => " + nationalities.getName("USA", "en"));
console.log("USA (Numeric) => " + nationalities.getName("840", "en"));
Get all names by their ISO 3166-1 Alpha-2 code
var nationalities = require("i18n-nationality");
console.log(nationalities.getNames("en"));
Supported languages (ISO 639-1)
de
: Germanen
: Englishfr
: Frenchno
: Norwegianit
: Italianfi
: Finnishnl
: Dutches
: Español
List of ISO 639-1 codes
Nationality to Code
var nationalities = require("i18n-nationality");
console.log("American => " + nationalities.getAlpha2Code('American', 'en'));
console.log("American => " + nationalities.getAlpha3Code('American', 'en'));
Codes
Convert Alpha-3 to Alpha-2 code
var nationalities = require("i18n-nationality");
console.log("USA (Alpha-3) => " + nationalities.alpha3ToAlpha2("USA") + " (Alpha-2)");
Convert Numeric to Alpha-2 code
var nationalities = require("i18n-nationality");
console.log("840 (Numeric) => " + nationalities.numericToAlpha2("840") + " (Alpha-2)");
Convert Alpha-2 to Alpha-3 code
var nationalities = require("i18n-nationality");
console.log("DE (Alpha-2) => " + nationalities.alpha2ToAlpha3("DE") + " (Alpha-3)");
Convert Numeric to Alpha-3 code
var nationalities = require("i18n-nationality");
console.log("840 (Numeric) => " + nationalities.numericToAlpha3("840") + " (Alpha-3)");
Convert Alpha-3 to Numeric code
var nationalities = require("i18n-nationality");
console.log(nationalities.alpha3ToNumeric("SWE"));
Convert Alpha-2 to Numeric code
var nationalities = require("i18n-nationality");
console.log(nationalities.alpha2ToNumeric("SE"));
Get all Alpha-2 codes
var nationalities = require("i18n-nationality");
console.log(nationalities.getAlpha2Codes());
Get all Alpha-3 codes
var nationalities = require("i18n-nationality");
console.log(nationalities.getAlpha3Codes());
Get all Numeric codes
var nationalities = require("i18n-nationality");
console.log(nationalities.getNumericCodes());
Validate country code
var nationalities = require("i18n-nationality");
console.log(nationalities.isValid("US"), nationalities.isValid("USA"), nationalities.isValid("XX")));
Contribution
To add a language:
- add a json file under langs/
- add the language to the
data
object in entry-node.js at the top - add language to section Supported languages in README.md
- run
npm install && make test
to make sure that tests are passing - open a PR on GitHub
You can check codes here: https://www.iso.org/obp/ui/#home