Skip to Content

Language Code Functions

Convert and validate language codes between ISO-639-1, ISO-639-3, and BCP-47.

toISO639_3

Convert any language code to ISO-639-3 format.

function toISO639_3(code: string): string
toISO639_3("en") // "eng" toISO639_3("en-US") // "eng" toISO639_3("zh-Hans") // "zho"

toISO639_1

Convert to ISO-639-1 format if possible.

function toISO639_1(code: string): string | undefined
toISO639_1("eng") // "en" toISO639_1("cmn") // undefined (no ISO-639-1) toISO639_1("th") // "th"

getLanguageName

Get the English name of a language.

function getLanguageName(code: string): string
getLanguageName("th") // "Thai" getLanguageName("cmn") // "Mandarin Chinese"

getNativeLanguageName

Get the native name of a language.

function getNativeLanguageName(code: string): string
getNativeLanguageName("ja") // "日本語" getNativeLanguageName("th") // "ไทย" getNativeLanguageName("ar") // "العربية"

isValidLanguageCode

Check if a code is a known language code.

function isValidLanguageCode(code: string): boolean
isValidLanguageCode("en") // true isValidLanguageCode("en-US") // true isValidLanguageCode("xyz") // false

isSpecialCode

Check if a code is a special (non-language) code.

function isSpecialCode(code: string): boolean
isSpecialCode("ipa") // true isSpecialCode("und") // true isSpecialCode("en") // false

getLanguageInfo

Get complete information about a language.

function getLanguageInfo(code: string): { code: string iso3: string iso1: string | undefined name: string nativeName: string bcp47: string }
getLanguageInfo("th") // { // code: "th", // iso3: "tha", // iso1: "th", // name: "Thai", // nativeName: "ไทย", // bcp47: "tha-TH" // }
Last updated on