iso-countries-languages/README.md

169 lines
3.6 KiB
Markdown
Raw Normal View History

2020-07-24 03:19:26 +02:00
# iso-countries-languages
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)
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
Simply run the following code and look at the examples to see typical usages:
2020-07-24 03:19:26 +02:00
```
2020-07-24 03:19:26 +02:00
yarn add @hotosm/iso-countries-languages
```
2020-07-24 03:19:26 +02:00
## Customization
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:
2020-07-24 03:19:26 +02:00
- Modify [supportedLangs.json](/src/supportedLangs.json)
- Run `yarn all`
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
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
```
2020-07-24 03:19:26 +02:00
Supported languages:
[ 'af',
'am',
'ar',
'az',
'ba',
2020-07-24 03:19:26 +02:00
...
2020-07-24 03:19:26 +02:00
'udm',
'uk',
'ur',
'uz',
'vi',
'xh',
'yi',
'zh' ]
```
2020-07-24 03:19:26 +02:00
### getCountries
Returns the ISO 3166-1 list of countries translated in the language passed as a parameter.
2020-07-24 03:19:26 +02: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
```
2020-07-24 03:19:26 +02:00
Countries in french:
{ 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
...
WF: 'Wallis-et-Futuna',
EH: 'Sahara Occidental',
YE: 'Yémen',
ZM: 'La zambie',
ZW: 'Zimbabwe' }
```
2020-07-24 03:19:26 +02:00
### getCountry
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
```
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
```
2020-07-24 03:19:26 +02:00
Italy in french:
Italie
```
2020-07-24 03:19:26 +02:00
### getLanguages
Returns the ISO 639-1 list of languages translated in the language passed as a parameter
2020-07-24 03:19:26 +02: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
```
2020-07-24 03:19:26 +02:00
Languages in italian:
{ ab: 'Di abcasia',
aa: 'Lontano',
af: 'Afrikaans',
ak: 'Akan',
sq: 'Albanese',
am: 'Amarico',
ar: 'Arabo',
2020-07-24 03:19:26 +02:00
...
xh: 'Xhosa',
yi: 'Yiddish',
yo: 'Yoruba',
za: 'Zhuang, Chuang',
zu: 'Zulu' }
```
2020-07-24 03:19:26 +02:00
### getLanguage
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
```
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
```
2020-07-24 03:19:26 +02:00
Spanish in italian:
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/).