2020-07-24 03:19:26 +02:00
# iso-countries-languages
2016-11-07 23:15:09 +01:00
2020-07-24 11:55:37 +02:00
[![npm version ](https://badge.fury.io/js/%40hotosm%2Fiso-countries-languages.svg )](https://badge.fury.io/js/%40hotosm%2Fiso-countries-languages)
2016-11-07 23:15:09 +01:00
This library provides the full list of [ISO 639-1 languages ](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ) and the full list of [ISO 3166-1 countries ](https://en.wikipedia.org/wiki/ISO_3166-1 ). The library supports 89 languages (the full list is available by querying the library API itself) and it is designed to be easy to import and use.
2020-07-24 03:19:26 +02:00
## Installation
2016-11-07 23:15:09 +01:00
Simply run the following code and look at the examples to see typical usages:
2020-07-24 03:19:26 +02:00
2016-11-07 23:15:09 +01:00
```
2020-07-24 03:19:26 +02:00
yarn add @hotosm/iso -countries-languages
2016-11-07 23:15:09 +01:00
```
2020-07-24 03:19:26 +02:00
## Customization
2016-11-07 23:15:09 +01:00
2020-07-24 03:19:26 +02:00
This library includes data for more than 150 languages. To make the build smaller, we have only 24 languages enabled, but you can easily build that package with more languages enabled. Follow those steps:
2016-11-07 23:15:09 +01:00
2020-07-24 03:19:26 +02:00
- Modify [supportedLangs.json ](/src/supportedLangs.json )
- Run `yarn all`
2016-11-07 23:15:09 +01:00
2020-07-24 11:55:37 +02:00
To update the countries data from OpenStreetMap, execute `yarn update-countries` .
2020-07-24 03:19:26 +02:00
## API list
### getSupportedLangs
2016-11-07 23:15:09 +01:00
Returns the list of supported languages.
```
var isoCountriesLanguages = require('iso-countries-languages');
var supportedLangs = isoCountriesLanguages.getSupportedLangs();
console.log("Supported languages: ");
console.log(supportedLangs);
```
2020-07-24 03:19:26 +02:00
#### Output
2016-11-07 23:15:09 +01:00
```
2020-07-24 03:19:26 +02:00
Supported languages:
2016-11-07 23:15:09 +01:00
[ 'af',
'am',
'ar',
'az',
'ba',
2020-07-24 03:19:26 +02:00
2016-11-07 23:15:09 +01:00
...
2020-07-24 03:19:26 +02:00
2016-11-07 23:15:09 +01:00
'udm',
'uk',
'ur',
'uz',
'vi',
'xh',
'yi',
'zh' ]
```
2020-07-24 03:19:26 +02:00
### getCountries
2016-11-07 23:15:09 +01:00
Returns the ISO 3166-1 list of countries translated in the language passed as a parameter.
2020-07-24 03:19:26 +02:00
2016-11-07 23:15:09 +01:00
```
var isoCountriesLanguages = require('iso-countries-languages');
var countriesInFrench = isoCountriesLanguages.getCountries('fr');
console.log("Countries in french: ");
console.log(countriesInFrench);
```
2020-07-24 03:19:26 +02:00
#### Output
2016-11-07 23:15:09 +01:00
```
2020-07-24 03:19:26 +02:00
Countries in french:
2016-11-07 23:15:09 +01:00
{ AF: 'Afghanistan',
AX: 'Les Îles D\'Åland',
AL: 'L\'albanie',
DZ: 'L\'algérie',
AS: 'Samoa Américaines',
AD: 'Andorre',
2020-07-24 03:19:26 +02:00
2016-11-07 23:15:09 +01:00
...
WF: 'Wallis-et-Futuna',
EH: 'Sahara Occidental',
YE: 'Yémen',
ZM: 'La zambie',
ZW: 'Zimbabwe' }
```
2020-07-24 03:19:26 +02:00
### getCountry
2016-11-07 23:15:09 +01:00
Returns the translation for the country code passed as a parameter in the language passed as a parameter.
2020-07-24 03:19:26 +02:00
2016-11-07 23:15:09 +01:00
```
var isoCountriesLanguages = require('iso-countries-languages');
var italyInFrench = isoCountriesLanguages.getCountry('fr', 'IT');
console.log("Italy in french: ");
console.log(italyInFrench);
```
2020-07-24 03:19:26 +02:00
#### Output
2016-11-07 23:15:09 +01:00
```
2020-07-24 03:19:26 +02:00
Italy in french:
2016-11-07 23:15:09 +01:00
Italie
```
2020-07-24 03:19:26 +02:00
### getLanguages
2016-11-07 23:15:09 +01:00
Returns the ISO 639-1 list of languages translated in the language passed as a parameter
2020-07-24 03:19:26 +02:00
2016-11-07 23:15:09 +01:00
```
var isoCountriesLanguages = require('iso-countries-languages');
var languagesInItalian = isoCountriesLanguages.getLanguages('it');
console.log("Languages in italian: ");
console.log(languagesInItalian);
```
2020-07-24 03:19:26 +02:00
#### Output
2016-11-07 23:15:09 +01:00
```
2020-07-24 03:19:26 +02:00
Languages in italian:
2016-11-07 23:15:09 +01:00
{ ab: 'Di abcasia',
aa: 'Lontano',
af: 'Afrikaans',
ak: 'Akan',
sq: 'Albanese',
am: 'Amarico',
ar: 'Arabo',
2020-07-24 03:19:26 +02:00
2016-11-07 23:15:09 +01:00
...
xh: 'Xhosa',
yi: 'Yiddish',
yo: 'Yoruba',
za: 'Zhuang, Chuang',
zu: 'Zulu' }
```
2020-07-24 03:19:26 +02:00
### getLanguage
2016-11-07 23:15:09 +01:00
Returns the translation for the language code passed as a parameter in the language passed as a parameter
2020-07-24 03:19:26 +02:00
2016-11-07 23:15:09 +01:00
```
var isoCountriesLanguages = require('iso-countries-languages');
var spanishInItalian = isoCountriesLanguages.getLanguage('it', 'es');
console.log("Spanish in italian: ");
console.log(spanishInItalian);
```
2020-07-24 03:19:26 +02:00
#### Output
2016-11-07 23:15:09 +01:00
```
2020-07-24 03:19:26 +02:00
Spanish in italian:
2016-11-07 23:15:09 +01:00
Spagnolo
2020-07-24 03:19:26 +02:00
```
#### License
MIT License
2020-07-24 11:55:37 +02:00
The country names included in this project came from [OpenStreetMap ](https://osm.org/copyright ). The data is made available under [ODbL ](https://opendatacommons.org/licenses/odbl/ ).