1 | # ISO-639-1
|
2 | [![NPM Version][npm-image]][npm-url]
|
3 | [![Build Status][travis-image]][travis-url]
|
4 | [![Download Count][download-url]][npm-url]
|
5 |
|
6 | [travis-image]: https://travis-ci.org/meikidd/iso-639-1.svg?branch=master
|
7 | [travis-url]: https://travis-ci.org/meikidd/iso-639-1
|
8 | [npm-image]: https://img.shields.io/npm/v/iso-639-1.svg?style=flat-square
|
9 | [npm-url]: https://npmjs.org/package/iso-639-1
|
10 | [download-url]: https://img.shields.io/npm/dt/iso-639-1.svg?style=flat-square
|
11 |
|
12 |
|
13 | Simple interface for [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language codes
|
14 |
|
15 | ## Installation
|
16 |
|
17 | ```
|
18 | npm install iso-639-1
|
19 | ```
|
20 |
|
21 | ## Usage
|
22 |
|
23 | ### Node.js
|
24 |
|
25 | ```javascript
|
26 | const ISO6391 = require('iso-639-1');
|
27 | console.log(ISO6391.getName('en')); // 'English'
|
28 | ```
|
29 |
|
30 | ### ES Module
|
31 |
|
32 | ```javascript
|
33 | import ISO6391 from 'iso-639-1';
|
34 | console.log(ISO6391.getName('en')); // 'English'
|
35 | ```
|
36 |
|
37 | ### Browsers
|
38 |
|
39 | HTML
|
40 |
|
41 | ```html
|
42 | <script type="text/javascript" src="./node_modules/iso-639-1/build/index.js"></script>
|
43 | ```
|
44 |
|
45 | Visit global variable ISO6391 in js
|
46 |
|
47 | ```javascript
|
48 | console.log(ISO6391.getName('en')); // 'English'
|
49 | ```
|
50 |
|
51 | ## Methods
|
52 |
|
53 | ### getName(code)
|
54 | - @param code {string}
|
55 | - @return {string}
|
56 |
|
57 | Lookup language english name by code
|
58 |
|
59 | ### getAllNames()
|
60 | - @return {array}
|
61 |
|
62 | Get array of all language english names
|
63 |
|
64 | ### getNativeName(code)
|
65 | - @param code {string}
|
66 | - @return {string}
|
67 |
|
68 | Lookup language native name by code
|
69 |
|
70 | ### getAllNativeNames()
|
71 | - @return {array}
|
72 |
|
73 | Get array of all language native names
|
74 |
|
75 |
|
76 | ### getCode(name)
|
77 | - @param name {string}
|
78 | - @return {string}
|
79 |
|
80 | Lookup code by english name or native name
|
81 |
|
82 | ### getAllCodes()
|
83 | - @return {array}
|
84 |
|
85 | Get array of all codes
|
86 |
|
87 | ### validate(code)
|
88 | - @param code {string}
|
89 | - @return {boolean}
|
90 |
|
91 | Check whether the given code is in the list of [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
|
92 |
|
93 | ### getLanguages(codes)
|
94 | - @param codes {array}
|
95 | - @return {array}
|
96 |
|
97 | Get the array of the language objects by the given codes
|
98 |
|
99 | ## Example
|
100 |
|
101 | ```
|
102 | const ISO6391 = require('iso-639-1')
|
103 |
|
104 | console.log(ISO6391.getName('zh')) // 'Chinese'
|
105 | console.log(ISO6391.getNativeName('zh')) // '中文'
|
106 |
|
107 | console.log(ISO6391.getAllNames()) // ['Afar','Abkhaz', ... ,'Zulu']
|
108 | console.log(ISO6391.getAllNativeNames()) //['Afaraf','аҧсуа бызшәа', ... ,'isiZulu' ]
|
109 |
|
110 | console.log(ISO6391.getCode('Chinese')) // 'zh'
|
111 | console.log(ISO6391.getCode('中文')) // 'zh'
|
112 |
|
113 | console.log(ISO6391.getAllCodes()) //['aa','ab',...,'zu']
|
114 |
|
115 | console.log(ISO6391.validate('en')) // true
|
116 | console.log(ISO6391.validate('xx')) // false
|
117 |
|
118 | console.log(ISO6391.getLanguages(['en', 'zh']))
|
119 | // [{code:'en',name:'English',nativeName:'English'},{code:'zh',name:'Chinese',nativeName:'中文'}]
|
120 |
|
121 | ```
|