Skip to content
/ language Public

ES6 module for looking up ISO 639-1 language code info.

License

Notifications You must be signed in to change notification settings

doga/language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

language

ES6 JavaScript module for looking up ISO 639-1 language code info.

Importing this library

import { Language } from "https://esm.sh/gh/doga/language@1.0.2/mod.mjs";

Usage

Tip: Run the following example by typing this in your terminal (requires Deno):

deno run \
  --allow-net --allow-run --allow-env --allow-read \
  https://deno.land/x/mdrb@2.0.0/mod.ts \
  --dax=false --mode=isolated \
  https://raw.githubusercontent.com/doga/language/main/README.md
Print out language info for some language codes.
description = '''
Running this example is safe, it will not read or write anything to your filesystem.
'''
import { Language } from "https://esm.sh/gh/doga/language@1.0.2/mod.mjs";

['en', 'fr', 'de', 'tr'].forEach(iso639_1 => {
    const lang = Language.fromCode(iso639_1);
    if(!lang)return;
    console.info(`Language info for ${lang}:`);
    console.info(`  ISO 639-1:   ${lang.iso639_1}`);
    console.info(`  ISO 639-2:   ${lang.iso639_2}`);
    console.info(`  Name:        ${lang.name}`);
    console.info(`  Native name: ${lang.nativeName}`);
    console.info(`  Family:      ${lang.family}`);
    console.info(`  Wiki URL:    ${lang.wikiUrl}`);
});

Sample output for the code above:

Language info for en:
  ISO 639-1:   "en"
  ISO 639-2:   "eng"
  Name:        "English"
  Native name: "English"
  Family:      "Indo-European"
  Wiki URL:    "https://en.wikipedia.org/wiki/English_language"
Language info for fr:
  ISO 639-1:   "fr"
  ISO 639-2:   "fra"
  Name:        "French"
  Native name: "français, langue française"
  Family:      "Indo-European"
  Wiki URL:    "https://en.wikipedia.org/wiki/French_language"
Language info for de:
  ISO 639-1:   "de"
  ISO 639-2:   "deu"
  Name:        "German"
  Native name: "Deutsch"
  Family:      "Indo-European"
  Wiki URL:    "https://en.wikipedia.org/wiki/German_language"
Language info for tr:
  ISO 639-1:   "tr"
  ISO 639-2:   "tur"
  Name:        "Turkish"
  Native name: "Türkçe"
  Family:      "Turkic"
  Wiki URL:    "https://en.wikipedia.org/wiki/Turkish_language"