iso-639-language
v1.0.1
Published
A package which lookup for the language name for a given locale ISO-639-1 or, 639-2 /B, 639-3 and return the correct name in English German, French,Italian,Albanian
Downloads
510
Readme
ISO-639-LANGUAGE
Simple interface for iso-639-language language codes
Installation
npm i iso-639-language
Usage Javascript
Node.js
const Iso639Type = require('iso-639-language');
// ISO_639_1 = 1,
// ISO_639_2 = 2,
// ISO_639_3 = 3
const iso639_1 = Iso639Type.getType(1);
console.log(iso639_1.getNameByCodeEnglish('en')); // 'English'
console.log(iso639_1.getNameByCodeGerman('en')); // 'Englisch'
console.log(iso639_1.getNameByCodeFrench('en')); // 'Anglais'
console.log(iso639_1.getNameByCodeItalian('en')); // 'Inglese'
console.log(iso639_1.getNameByCodeAlbanian('en')); // 'Anglisht'
// Accept 2 params, code: string, translate:"en"|"de"|"fr"|"it"
console.log(iso639_1.getNameByCodeTranslate('de','en')); // 'German'
ES Module
import Iso639Type from 'iso-639-language';
// ISO_639_1 = 1,
// ISO_639_2 = 2,
// ISO_639_3 = 3
const iso639_1 = Iso639Type.getType(1);
console.log(iso639_1.getNameByCodeEnglish('en')); // 'English'
console.log(iso639_1.getNameByCodeGerman('en')); // 'Englisch'
console.log(iso639_1.getNameByCodeFrench('en')); // 'Anglais'
console.log(iso639_1.getNameByCodeItalian('en')); // 'Inglese'
console.log(ISO6391.getNameByCodeAlbanian('en')); // 'Anglisht'
// Accept 2 params, code: string, translate:"en"|"de"|"fr"|"it"|"al"
console.log(iso639_1.getNameByCodeTranslate('de','en')); // 'German'
Usage TypeScript
import Iso639Type,{Language,IsoType} from 'iso-639-language';
// ISO_639_1, ISO_639_2, ISO_639_3
const iso639_1 = Iso639Type.getType(IsoType.ISO_639_1);
let language:Language;
language=iso639_1.getFullLanguageByCode('en');
console.log(language);
/*
{
al: "Anglisht"
de: "Englisch"
en: "English"
familyName: "Indo-European"
fr: "anglais"
iso639_1: "en"
iso639_2: "eng"
iso639_3: "eng"
it: "Inglese"
name: "English"
nativeName: "English"
wikiUrl: "https://en.wikipedia.org/wiki/English_language"
}
*/
Methods
getNameByCode(code: string): string;
- @param code {string}
- @return {string}
Get name by code
getNameAll(): Array;
- @return {array}
Get array of all language names
getNameByCodeNative(code: string): string;
- @param code {string}
- @return {string}
Get language native name by code
getNameByCodeEnglish(code: string): string;
- @param code {string}
- @return {string}
Get name in English by code
getNameByCodeGerman(code: string): string;
- @param name {string}
- @return {string}
Get name in German by code
getNameByCodeFrench(code: string): string;
- @param name {string}
- @return {array}
Get name in French by code
getNameByCodeItalian(code: string): string;
- @param name {string}
- @return {array}
Get name in Italian by code
getNameByCodeAlbanian(code: string): string;
- @param name {string}
- @return {array}
Get name in Albanian by code
getNameByCodeTranslate(code: string,translate:string): string;
- @param name {string}
- @param translate {string} |"en"|"de"|"fr"|"it"|"al"
- @return {array}
Get name by code and Language // default is "en"
getCodeByName(name: string): string;
- @param name {string}
- @return {boolean}
Get Code by name
getCodeAll(): Array;
- @return {array}
Get the array of Code
checkExist(code: string): boolean;
- @param code {string}
- @return {array}
Check if exist a specific Code
getFullLanguageByCode(code: string): Language;
- @param code {string}
- @return {Object} Language
Get all properties of language by Code
getFullLanguageByName(name: string): Language;
- @param name {string}
- @return {Object} Language
Get all properties of language by Name
getFullLanguageAll(): Array;
- @return {array}
Get array of all properties of language
More Info
Language
class Language {
name = '';
iso639_1 = '';
iso639_2 = '';
iso639_3 = '';
familyName = '';
nativeName = '';
en = '';
it = '';
fr = '';
al = '';
de = '';
wikiUrl = '';
}
IsoType
enum IsoType {
ISO_639_1 = 1,
ISO_639_2 = 2,
ISO_639_3 = 3
}