Installations
npm install country-language
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
*
NPM Version
1.3.24
Score
99
Supply Chain
98.9
Quality
75.5
Maintenance
25
Vulnerability
99.5
License
Releases
Unable to fetch releases
Download Statistics
Total Downloads
13,331,338
Last Day
5,362
Last Week
28,349
Last Month
92,796
Last Year
963,581
Bundle Size
148.71 kB
Minified
31.55 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.1.7
Package Id
country-language@0.1.7
Size
31.58 kB
NPM Version
1.3.24
Publised On
19 Nov 2014
Total Downloads
Cumulative downloads
Total Downloads
13,331,338
Last day
1.2%
5,362
Compared to previous day
Last week
-12.7%
28,349
Compared to previous week
Last month
90.8%
92,796
Compared to previous month
Last year
-27.1%
963,581
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
country-language
Query any country's spoken languages or countries where a language is spoken.
Installation
Node.js
country-language
is available on npm.
$ npm install country-language
Usage
Once you require country-language
, the following API will be available.
1var CountryLanguage = require('country-language');
.getLanguageCodes (languageCodeType, cb)
- @param {String} language code type. Acceptable values: 1, 2 or 3.
- @param {Function} callback on complete or error
- @cb {Error|null} if error
- @cb {Object} array String with language codes
Acceptable language code type parameter values: 1, 2, 3 for returning ISO-639-1, ISO-639-2, ISO-639-3 codes respectively. If not provided, ISO-639-1 codes will be returned.
1var allLanguageCodes = CountryLanguage.getLanguageCodes(2);
.getCountryCodes (countryCodeType, cb)
- @param {String} country code type. Acceptable values: 1, 2 or 3.
- @param {Function} callback on complete or error
- @cb {Error|null} if error
- @cb {Object} array String with country codes
Acceptable country code type parameter values: 1, 2, 3 for returning numerical code, alpha-2, alpha-3 codes respectively. If not provided, alpha-2 codes will be returned.
1var allCountryCodes = CountryLanguage.getCountryCodes(2);
.languageCodeExists (languageCode)
- @param {String} language code to check.
Returns Boolean indicating language existance. Language code parameter can be either a ISO-639-1, ISO-639-2 or ISO-639-3 code.
1var languageExists = CountryLanguage.languageCodeExists('en');
.countryCodeExists (countryCode)
- @param {String} country code to check.
Returns Boolean indicating country existance. Country code parameter can be either an alpha-2, alpha-3 or numerical code.
1var countryExists = CountryLanguage.countryCodeExists('GB');
.getCountry (code, cb)
- @param {String} country code
- @param {Function} callback on complete or error
- @cb {Error|null} if error
- @cb {Object} object containing country info
Country code can be either an Alpha-2 or Alpha-3 code. The returned object includes the following info:
code_2
: Country alpha-2 code (2 letters)code_3
: Country alpha-3 code (3 letters)numCode
: Country numeric codename
: Country namelanguages
: Array of language objects for each language spoken in the countrylangCultureMs
: Array of language cultures for the country supported by Microsoft©
Each language object in languages
property includes the following info:
iso639_1
: language iso639-1 code (2 letters)iso639_2
: language iso639-2 code (3 letters)iso639_2en
: language iso639-2 code with some codes derived from English names rather than native names of languages (3 letters)iso639_3
: language iso639-3 code (3 letters)name
: String array with one or more language names (in English)nativeName
: String array with one or more language names (in native language)direction
: Language script direction (either 'LTR' or 'RTL') - Left-to-Right, Right-to-Leftfamily
: language familycountries
: Array of country objects where this language is spoken
Each Microsoft© language culture object in langCultureMs
property icludes the following info:
langCultureName
: language culture namedisplayName
: language culture dispaly namecultureCode
: language culture code
1CountryLanguage.getCountry('GB', function (err, country) { 2 if (err) { 3 console.log(err); 4 } else { 5 var languagesInGB = country.languages; 6 } 7});
.getLanguage (code, cb)
- @param {String} language code
- @param {Function} callback on complete or error
- @cb {Error|null} if error
- @cb {Object} object containing language info
Language code can be either iso639-1, iso639-2, iso639-2en or iso639-3 code.
Contents of the returned language object are described in .getCountry
method.
1CountryLanguage.getLanguage('en', function (err, language) {
2 if (err) {
3 console.log(err);
4 } else {
5 var countriesSpeakingEN = language.countries;
6 }
7});
.getCountryLanguages (code, cb)
- @param {String} country code
- @param {Function} callback on complete or error
- @cb {Error|null} if error
- @cb {Object} object array containing country languages info
Country code can be either an Alpha-2 or Alpha-3 code. Each language object contains the following info:
iso639_1
: language iso639-1 code (2 letters)iso639_2
: language iso639-2 code with some codes derived from English names rather than native names of languages (3 letters)iso639_3
: language iso639-3 code (3 letters)
1CountryLanguage.getCountryLanguages('GB', function (err, languages) { 2 if (err) { 3 console.log(err); 4 } else { 5 languages.forEach(function (languageCodes) { 6 console.log(languageCodes.iso639_1); 7 }); 8 } 9});
.getLanguageCountries (code, cb)
- @param {String} language code
- @param {Function} callback on complete or error
- @cb {Error|null} if error
- @cb {Object} object array containing country info
Language code can be either iso639-1, iso639-2, iso639-2en or iso639-3 code. Each Country object contains the following info:
code_2
: Country alpha-2 code (2 letters)code_3
: Country alpha-3 code (3 letters)numCode
: Country numeric code
1CountryLanguage.getLanguageCountries('en', function (err, countries) { 2 if (err) { 3 console.log(err); 4 } else { 5 countries.forEach(function (countryCodes) { 6 console.log(countryCodes.code_3); 7 }); 8 } 9});
.getCountryMsLocales (code, cb)
- @param {String} country code
- @param {Function} callback on complete or error
- @cb {Error|null} if error
- @cb {Object} object array containing Language Cultures info for the country
Country code can be either an Alpha-2 or Alpha-3 code.
Contents of each Language Culture object are described in .getCountry
method.
1CountryLanguage.getCountryMsLocales('GB', function (err, locales) { 2 if (err) { 3 console.log(err); 4 } else { 5 locales.forEach(function (locale) { 6 console.log(locale.langCultureName); 7 }); 8 } 9});
.getLanguageMsLocales (code, cb)
- @param {String} language code
- @param {Function} callback on complete or error
- @cb {Error|null} if error
- @cb {Object} object array containing Language Cultures info for the language
Language code can be either iso639-1, iso639-2, iso639-2en or iso639-3 code.
Contents of each Language Culture object are described in .getCountry
method.
1CountryLanguage.getLanguageMsLocales('en', function (err, locales) { 2 if (err) { 3 console.log(err); 4 } else { 5 locales.forEach(function (locale) { 6 console.log(locale.langCultureName); 7 }); 8 } 9});
.getCountries ()
Returns an array object with info for every country in the world having an ISO 3166 code.
Contents of each country object in the array is described in .getCountry
method.
1var allCountries = CountryLanguage.getCountries();
.getLanguages ()
Returns an array object with info for every language in the world having an ISO 639-2 code (and a few more).
Contents of each language object in the array is described in .getCountry
method.
1var allLanguages = CountryLanguage.getLanguages();
.getLanguageFamilies ()
Returns an array of strings with the names of each language family.
1var allLanguageFamilies = CountryLanguage.getLanguageFamilies();
.getLocales (mode)
- @param {Boolean} locale symbols mode
Returns an array of strings with all locale codes. If mode ommited or false, locales with 3 parts will be returned like: az-Cyrl-AZ
If mode is set to true, they will be returned like: az-AZ-Cyrl
1var localesSymbols = CountryLanguage.getLocales(); 2var localesSymbols = CountryLanguage.getLocales(true);
.getLanguageFamilyMembers (family, cb)
Returns an array object with info for every language in the world having an ISO 639-2 code (and a few more).
Contents of each language object in the array is described in .getCountry
method.
- @param {String} language family name (
- @param {Function} callback on complete or error
- @cb {Error|null} if error
- @cb {Object} object array containing languages info for each language member in the family.
Contents of the returned language object are described in .getCountry
method.
1CountryLanguage.getLanguageFamilyMembers('Indo-European', function (err, languages) { 2 if (err) { 3 console.log(err); 4 } else { 5 languages.forEach(function (language) { 6 console.log(language.name); 7 }); 8 } 9});
## Notes
For the following methods:
- .getLanguageCodes
- .getCountryCodes
- .getCountry
- .getLanguage
- .getCountryLanguages
- .getLanguageCountries
- .getCountryMsLocales
- .getLanguageMsLocales
- .getLanguageFamilyMembers
the cb
parameter is optional. When not provided, each method returns either an Object when there is no error, or a String in case of an error.
Any input parameter (country code, language code, language family name) is case insensitive.
Language#nativeName
string is not displayed correclty on the console for Right-to-Left (RTL) languages. However, there is no issue on string rendering (either on the browser or any text editor).
License
Copyright (c) 2014 BDSwiss
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No security vulnerabilities found.
Other packages similar to country-language
os-locale
Get the system locale
@ladjs/country-language
Maintained fork of country-language with zero-dependencies. Query languages spoken to a country or countries where people speak a language.
country-codes-list
List of codes per country (languages, calling codes, currency codes, etc)
country-language-lodash
Query languages spoken to a country or countries where people speak a language.