2023-10-01 08:51:38 +02:00
|
|
|
package iso639
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-10-02 23:45:21 +02:00
|
|
|
|
|
|
|
"git.0x0001f346.de/andreas/utils"
|
2023-10-01 08:51:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var iso639_2TCodeToName = map[string]string{
|
|
|
|
"aar": "Afar",
|
|
|
|
"abk": "Abkhazian",
|
|
|
|
"afr": "Afrikaans",
|
|
|
|
"aka": "Akan",
|
|
|
|
"amh": "Amharic",
|
|
|
|
"ara": "Arabic",
|
|
|
|
"arg": "Aragonese",
|
|
|
|
"asm": "Assamese",
|
|
|
|
"ava": "Avaric",
|
|
|
|
"ave": "Avestan",
|
|
|
|
"aym": "Aymara",
|
|
|
|
"aze": "Azerbaijani",
|
|
|
|
"bak": "Bashkir",
|
|
|
|
"bam": "Bambara",
|
|
|
|
"bel": "Belarusian",
|
|
|
|
"ben": "Bengali",
|
|
|
|
"bis": "Bislama",
|
|
|
|
"bod": "Tibetan",
|
|
|
|
"bos": "Bosnian",
|
|
|
|
"bre": "Breton",
|
|
|
|
"bul": "Bulgarian",
|
|
|
|
"cat": "Catalan",
|
|
|
|
"ces": "Czech",
|
|
|
|
"cha": "Chamorro",
|
|
|
|
"che": "Chechen",
|
|
|
|
"chu": "Church Slavonic",
|
|
|
|
"chv": "Chuvash",
|
|
|
|
"cor": "Cornish",
|
|
|
|
"cos": "Corsican",
|
|
|
|
"cre": "Cree",
|
|
|
|
"cym": "Welsh",
|
|
|
|
"dan": "Danish",
|
|
|
|
"deu": "German",
|
|
|
|
"div": "Divehi",
|
|
|
|
"dzo": "Dzongkha",
|
|
|
|
"ell": "Greek",
|
|
|
|
"eng": "English",
|
|
|
|
"epo": "Esperanto",
|
|
|
|
"est": "Estonian",
|
|
|
|
"eus": "Basque",
|
|
|
|
"ewe": "Ewe",
|
|
|
|
"fao": "Faroese",
|
|
|
|
"fas": "Persian",
|
|
|
|
"fij": "Fijian",
|
|
|
|
"fin": "Finnish",
|
|
|
|
"fra": "French",
|
|
|
|
"fry": "Western Frisian",
|
|
|
|
"ful": "Fulah",
|
|
|
|
"gla": "Gaelic",
|
|
|
|
"gle": "Irish",
|
|
|
|
"glg": "Galician",
|
|
|
|
"glv": "Manx",
|
|
|
|
"grn": "Guarani",
|
|
|
|
"guj": "Gujarati",
|
|
|
|
"hat": "Haitian",
|
|
|
|
"hau": "Hausa",
|
|
|
|
"heb": "Hebrew",
|
|
|
|
"her": "Herero",
|
|
|
|
"hin": "Hindi",
|
|
|
|
"hmo": "Hiri Motu",
|
|
|
|
"hrv": "Croatian",
|
|
|
|
"hun": "Hungarian",
|
|
|
|
"hye": "Armenian",
|
|
|
|
"ibo": "Igbo",
|
|
|
|
"ido": "Ido",
|
|
|
|
"iii": "Sichuan Yi",
|
|
|
|
"iku": "Inuktitut",
|
|
|
|
"ile": "Interlingue",
|
|
|
|
"ina": "Interlingua",
|
|
|
|
"ind": "Indonesian",
|
|
|
|
"ipk": "Inupiaq",
|
|
|
|
"isl": "Icelandic",
|
|
|
|
"ita": "Italian",
|
|
|
|
"jav": "Javanese",
|
|
|
|
"jpn": "Japanese",
|
|
|
|
"kal": "Kalaallisut",
|
|
|
|
"kan": "Kannada",
|
|
|
|
"kas": "Kashmiri",
|
|
|
|
"kat": "Georgian",
|
|
|
|
"kau": "Kanuri",
|
|
|
|
"kaz": "Kazakh",
|
|
|
|
"khm": "Central Khmer",
|
|
|
|
"kik": "Kikuyu",
|
|
|
|
"kin": "Kinyarwanda",
|
|
|
|
"kir": "Kirghiz",
|
|
|
|
"kom": "Komi",
|
|
|
|
"kon": "Kongo",
|
|
|
|
"kor": "Korean",
|
|
|
|
"kua": "Kuanyama",
|
|
|
|
"kur": "Kurdish",
|
|
|
|
"lao": "Lao",
|
|
|
|
"lat": "Latin",
|
|
|
|
"lav": "Latvian",
|
|
|
|
"lim": "Limburgan",
|
|
|
|
"lin": "Lingala",
|
|
|
|
"lit": "Lithuanian",
|
|
|
|
"ltz": "Luxembourgish",
|
|
|
|
"lub": "Luba-Katanga",
|
|
|
|
"lug": "Ganda",
|
|
|
|
"mah": "Marshallese",
|
|
|
|
"mal": "Malayalam",
|
|
|
|
"mar": "Marathi",
|
|
|
|
"mkd": "Macedonian",
|
|
|
|
"mlg": "Malagasy",
|
|
|
|
"mlt": "Maltese",
|
|
|
|
"mon": "Mongolian",
|
|
|
|
"mri": "Maori",
|
|
|
|
"msa": "Malay",
|
|
|
|
"mya": "Burmese",
|
|
|
|
"nau": "Nauru",
|
|
|
|
"nav": "Navajo",
|
|
|
|
"nbl": "South Ndebele",
|
|
|
|
"nde": "North Ndebele",
|
|
|
|
"ndo": "Ndonga",
|
|
|
|
"nep": "Nepali",
|
|
|
|
"nld": "Dutch",
|
|
|
|
"nno": "Norwegian Nynorsk",
|
|
|
|
"nob": "Norwegian Bokmål",
|
|
|
|
"nor": "Norwegian",
|
|
|
|
"nya": "Chichewa",
|
|
|
|
"oci": "Occitan",
|
|
|
|
"oji": "Ojibwa",
|
|
|
|
"ori": "Oriya",
|
|
|
|
"orm": "Oromo",
|
|
|
|
"oss": "Ossetian",
|
|
|
|
"pan": "Punjabi",
|
|
|
|
"pli": "Pali",
|
|
|
|
"pol": "Polish",
|
|
|
|
"por": "Portuguese",
|
|
|
|
"pus": "Pashto",
|
|
|
|
"que": "Quechua",
|
|
|
|
"roh": "Romansh",
|
|
|
|
"ron": "Romanian",
|
|
|
|
"run": "Rundi",
|
|
|
|
"rus": "Russian",
|
|
|
|
"sag": "Sango",
|
|
|
|
"san": "Sanskrit",
|
|
|
|
"sin": "Sinhala",
|
|
|
|
"slk": "Slovak",
|
|
|
|
"slv": "Slovenian",
|
|
|
|
"sme": "Northern Sami",
|
|
|
|
"smo": "Samoan",
|
|
|
|
"sna": "Shona",
|
|
|
|
"snd": "Sindhi",
|
|
|
|
"som": "Somali",
|
|
|
|
"sot": "Southern Sotho",
|
|
|
|
"spa": "Spanish",
|
|
|
|
"sqi": "Albanian",
|
|
|
|
"srd": "Sardinian",
|
|
|
|
"srp": "Serbian",
|
|
|
|
"ssw": "Swati",
|
|
|
|
"sun": "Sundanese",
|
|
|
|
"swa": "Swahili",
|
|
|
|
"swe": "Swedish",
|
|
|
|
"tah": "Tahitian",
|
|
|
|
"tam": "Tamil",
|
|
|
|
"tat": "Tatar",
|
|
|
|
"tel": "Telugu",
|
|
|
|
"tgk": "Tajik",
|
|
|
|
"tgl": "Tagalog",
|
|
|
|
"tha": "Thai",
|
|
|
|
"tir": "Tigrinya",
|
|
|
|
"ton": "Tonga",
|
|
|
|
"tsn": "Tswana",
|
|
|
|
"tso": "Tsonga",
|
|
|
|
"tuk": "Turkmen",
|
|
|
|
"tur": "Turkish",
|
|
|
|
"twi": "Twi",
|
|
|
|
"uig": "Uighur",
|
|
|
|
"ukr": "Ukrainian",
|
|
|
|
"urd": "Urdu",
|
|
|
|
"uzb": "Uzbek",
|
|
|
|
"ven": "Venda",
|
|
|
|
"vie": "Vietnamese",
|
|
|
|
"vol": "Volapück",
|
|
|
|
"wln": "Walloon",
|
|
|
|
"wol": "Wolof",
|
|
|
|
"xho": "Xhosa",
|
|
|
|
"yid": "Yiddish",
|
|
|
|
"yor": "Yoruba",
|
|
|
|
"zha": "Zhuang",
|
|
|
|
"zho": "Chinese",
|
|
|
|
"zul": "Zulu",
|
|
|
|
}
|
|
|
|
|
|
|
|
var iso639_2TNameToCode = map[string]string{
|
|
|
|
"Abkhazian": "abk",
|
|
|
|
"Afar": "aar",
|
|
|
|
"Afrikaans": "afr",
|
|
|
|
"Akan": "aka",
|
|
|
|
"Albanian": "sqi",
|
|
|
|
"Amharic": "amh",
|
|
|
|
"Arabic": "ara",
|
|
|
|
"Aragonese": "arg",
|
|
|
|
"Armenian": "hye",
|
|
|
|
"Assamese": "asm",
|
|
|
|
"Avaric": "ava",
|
|
|
|
"Avestan": "ave",
|
|
|
|
"Aymara": "aym",
|
|
|
|
"Azerbaijani": "aze",
|
|
|
|
"Bambara": "bam",
|
|
|
|
"Bashkir": "bak",
|
|
|
|
"Basque": "eus",
|
|
|
|
"Belarusian": "bel",
|
|
|
|
"Bengali": "ben",
|
|
|
|
"Bislama": "bis",
|
|
|
|
"Bosnian": "bos",
|
|
|
|
"Breton": "bre",
|
|
|
|
"Bulgarian": "bul",
|
|
|
|
"Burmese": "mya",
|
|
|
|
"Catalan": "cat",
|
|
|
|
"Central Khmer": "khm",
|
|
|
|
"Chamorro": "cha",
|
|
|
|
"Chechen": "che",
|
|
|
|
"Chichewa": "nya",
|
|
|
|
"Chinese": "zho",
|
|
|
|
"Church Slavonic": "chu",
|
|
|
|
"Chuvash": "chv",
|
|
|
|
"Cornish": "cor",
|
|
|
|
"Corsican": "cos",
|
|
|
|
"Cree": "cre",
|
|
|
|
"Croatian": "hrv",
|
|
|
|
"Czech": "ces",
|
|
|
|
"Danish": "dan",
|
|
|
|
"Divehi": "div",
|
|
|
|
"Dutch": "nld",
|
|
|
|
"Dzongkha": "dzo",
|
|
|
|
"English": "eng",
|
|
|
|
"Esperanto": "epo",
|
|
|
|
"Estonian": "est",
|
|
|
|
"Ewe": "ewe",
|
|
|
|
"Faroese": "fao",
|
|
|
|
"Fijian": "fij",
|
|
|
|
"Finnish": "fin",
|
|
|
|
"French": "fra",
|
|
|
|
"Fulah": "ful",
|
|
|
|
"Gaelic": "gla",
|
|
|
|
"Galician": "glg",
|
|
|
|
"Ganda": "lug",
|
|
|
|
"Georgian": "kat",
|
|
|
|
"German": "deu",
|
|
|
|
"Greek": "ell",
|
|
|
|
"Guarani": "grn",
|
|
|
|
"Gujarati": "guj",
|
|
|
|
"Haitian": "hat",
|
|
|
|
"Hausa": "hau",
|
|
|
|
"Hebrew": "heb",
|
|
|
|
"Herero": "her",
|
|
|
|
"Hindi": "hin",
|
|
|
|
"Hiri Motu": "hmo",
|
|
|
|
"Hungarian": "hun",
|
|
|
|
"Icelandic": "isl",
|
|
|
|
"Ido": "ido",
|
|
|
|
"Igbo": "ibo",
|
|
|
|
"Indonesian": "ind",
|
|
|
|
"Interlingua": "ina",
|
|
|
|
"Interlingue": "ile",
|
|
|
|
"Inuktitut": "iku",
|
|
|
|
"Inupiaq": "ipk",
|
|
|
|
"Irish": "gle",
|
|
|
|
"Italian": "ita",
|
|
|
|
"Japanese": "jpn",
|
|
|
|
"Javanese": "jav",
|
|
|
|
"Kalaallisut": "kal",
|
|
|
|
"Kannada": "kan",
|
|
|
|
"Kanuri": "kau",
|
|
|
|
"Kashmiri": "kas",
|
|
|
|
"Kazakh": "kaz",
|
|
|
|
"Kikuyu": "kik",
|
|
|
|
"Kinyarwanda": "kin",
|
|
|
|
"Kirghiz": "kir",
|
|
|
|
"Komi": "kom",
|
|
|
|
"Kongo": "kon",
|
|
|
|
"Korean": "kor",
|
|
|
|
"Kuanyama": "kua",
|
|
|
|
"Kurdish": "kur",
|
|
|
|
"Lao": "lao",
|
|
|
|
"Latin": "lat",
|
|
|
|
"Latvian": "lav",
|
|
|
|
"Limburgan": "lim",
|
|
|
|
"Lingala": "lin",
|
|
|
|
"Lithuanian": "lit",
|
|
|
|
"Luba-Katanga": "lub",
|
|
|
|
"Luxembourgish": "ltz",
|
|
|
|
"Macedonian": "mkd",
|
|
|
|
"Malagasy": "mlg",
|
|
|
|
"Malay": "msa",
|
|
|
|
"Malayalam": "mal",
|
|
|
|
"Maltese": "mlt",
|
|
|
|
"Manx": "glv",
|
|
|
|
"Maori": "mri",
|
|
|
|
"Marathi": "mar",
|
|
|
|
"Marshallese": "mah",
|
|
|
|
"Mongolian": "mon",
|
|
|
|
"Nauru": "nau",
|
|
|
|
"Navajo": "nav",
|
|
|
|
"Ndonga": "ndo",
|
|
|
|
"Nepali": "nep",
|
|
|
|
"North Ndebele": "nde",
|
|
|
|
"Northern Sami": "sme",
|
|
|
|
"Norwegian Bokmål": "nob",
|
|
|
|
"Norwegian Nynorsk": "nno",
|
|
|
|
"Norwegian": "nor",
|
|
|
|
"Occitan": "oci",
|
|
|
|
"Ojibwa": "oji",
|
|
|
|
"Oriya": "ori",
|
|
|
|
"Oromo": "orm",
|
|
|
|
"Ossetian": "oss",
|
|
|
|
"Pali": "pli",
|
|
|
|
"Pashto": "pus",
|
|
|
|
"Persian": "fas",
|
|
|
|
"Polish": "pol",
|
|
|
|
"Portuguese": "por",
|
|
|
|
"Punjabi": "pan",
|
|
|
|
"Quechua": "que",
|
|
|
|
"Romanian": "ron",
|
|
|
|
"Romansh": "roh",
|
|
|
|
"Rundi": "run",
|
|
|
|
"Russian": "rus",
|
|
|
|
"Samoan": "smo",
|
|
|
|
"Sango": "sag",
|
|
|
|
"Sanskrit": "san",
|
|
|
|
"Sardinian": "srd",
|
|
|
|
"Serbian": "srp",
|
|
|
|
"Shona": "sna",
|
|
|
|
"Sichuan Yi": "iii",
|
|
|
|
"Sindhi": "snd",
|
|
|
|
"Sinhala": "sin",
|
|
|
|
"Slovak": "slk",
|
|
|
|
"Slovenian": "slv",
|
|
|
|
"Somali": "som",
|
|
|
|
"South Ndebele": "nbl",
|
|
|
|
"Southern Sotho": "sot",
|
|
|
|
"Spanish": "spa",
|
|
|
|
"Sundanese": "sun",
|
|
|
|
"Swahili": "swa",
|
|
|
|
"Swati": "ssw",
|
|
|
|
"Swedish": "swe",
|
|
|
|
"Tagalog": "tgl",
|
|
|
|
"Tahitian": "tah",
|
|
|
|
"Tajik": "tgk",
|
|
|
|
"Tamil": "tam",
|
|
|
|
"Tatar": "tat",
|
|
|
|
"Telugu": "tel",
|
|
|
|
"Thai": "tha",
|
|
|
|
"Tibetan": "bod",
|
|
|
|
"Tigrinya": "tir",
|
|
|
|
"Tonga": "ton",
|
|
|
|
"Tsonga": "tso",
|
|
|
|
"Tswana": "tsn",
|
|
|
|
"Turkish": "tur",
|
|
|
|
"Turkmen": "tuk",
|
|
|
|
"Twi": "twi",
|
|
|
|
"Uighur": "uig",
|
|
|
|
"Ukrainian": "ukr",
|
|
|
|
"Urdu": "urd",
|
|
|
|
"Uzbek": "uzb",
|
|
|
|
"Venda": "ven",
|
|
|
|
"Vietnamese": "vie",
|
|
|
|
"Volapück": "vol",
|
|
|
|
"Walloon": "wln",
|
|
|
|
"Welsh": "cym",
|
|
|
|
"Western Frisian": "fry",
|
|
|
|
"Wolof": "wol",
|
|
|
|
"Xhosa": "xho",
|
|
|
|
"Yiddish": "yid",
|
|
|
|
"Yoruba": "yor",
|
|
|
|
"Zhuang": "zha",
|
|
|
|
"Zulu": "zul",
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAllISO639_2TCodes returns all ISO 639-2/T codes
|
|
|
|
func GetAllISO639_2TCodes() []string {
|
2023-10-02 23:45:21 +02:00
|
|
|
return utils.GetAllStringKeysOfMap(iso639_2TCodeToName)
|
2023-10-01 08:51:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAllISO639_2TNames returns all ISO 639-2/T language names
|
|
|
|
func GetAllISO639_2TNames() []string {
|
2023-10-02 23:45:21 +02:00
|
|
|
return utils.GetAllStringKeysOfMap(iso639_2TNameToCode)
|
2023-10-01 08:51:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetISO639_2TCodeForLanguageName tries to match a language name to an ISO 639-2/T code
|
|
|
|
func GetISO639_2TCodeForLanguageName(s string) (string, error) {
|
|
|
|
code, languageNameExists := iso639_2TNameToCode[s]
|
|
|
|
if !languageNameExists {
|
|
|
|
return "", fmt.Errorf("no ISO 639-2/T code found for language name: %s", s)
|
|
|
|
}
|
|
|
|
|
|
|
|
return code, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLanguageNameForISO639_2TCode tries to match an ISO 639-2/T code to a language name
|
|
|
|
func GetLanguageNameForISO639_2TCode(s string) (string, error) {
|
|
|
|
languageName, codeExists := iso639_2TCodeToName[s]
|
|
|
|
if !codeExists {
|
|
|
|
return "", fmt.Errorf("no language name found for ISO 639-2/T code: %s", s)
|
|
|
|
}
|
|
|
|
|
|
|
|
return languageName, nil
|
|
|
|
}
|