Skip to content

Instantly share code, notes, and snippets.

@MatthewCallis
Last active December 6, 2023 09:25
Show Gist options
  • Save MatthewCallis/69eed34013a8abb1f747 to your computer and use it in GitHub Desktop.
Save MatthewCallis/69eed34013a8abb1f747 to your computer and use it in GitHub Desktop.
Country / Language / Locale Code List / Hash / Array
getLanguage: (language_code) ->
key = language_code.toLowerCase().replace(/-/, '_')
isoLangs = [
{ code:"aa", name:"Afar" },
{ code:"ab", name:"Abkhaz" },
{ code:"ae", name:"Avestan" },
{ code:"af", name:"Afrikaans" },
{ code:"ak", name:"Akan" },
{ code:"am", name:"Amharic" },
{ code:"an", name:"Aragonese" },
{ code:"ar", name:"Arabic" },
{ code:"ar_ae", name:"Arabic (United Arab Emirates)" },
{ code:"ar_bh", name:"Arabic (Bahrain)" },
{ code:"ar_dz", name:"Arabic (Algeria)" },
{ code:"ar_eg", name:"Arabic (Egypt)" },
{ code:"ar_iq", name:"Arabic (Iraq)" },
{ code:"ar_jo", name:"Arabic (Jordan)" },
{ code:"ar_kw", name:"Arabic (Kuwait)" },
{ code:"ar_lb", name:"Arabic (Lebanon)" },
{ code:"ar_ly", name:"Arabic (Libya)" },
{ code:"ar_ma", name:"Arabic (Morocco)" },
{ code:"ar_om", name:"Arabic (Oman)" },
{ code:"ar_qa", name:"Arabic (Qatar)" },
{ code:"ar_sa", name:"Arabic (Saudi Arabia)" },
{ code:"ar_sd", name:"Arabic (Sudan)" },
{ code:"ar_sy", name:"Arabic (Syria)" },
{ code:"ar_tn", name:"Arabic (Tunisia)" },
{ code:"ar_ye", name:"Arabic (Yemen)" },
{ code:"as", name:"Assamese" },
{ code:"av", name:"Avaric" },
{ code:"ay", name:"Aymara" },
{ code:"az", name:"Azerbaijani" },
{ code:"ba", name:"Bashkir" },
{ code:"be", name:"Belarusian" },
{ code:"be_by", name:"Belarusian (Belarus)" },
{ code:"bg", name:"Bulgarian" },
{ code:"bg_bg", name:"Bulgarian (Bulgaria)" },
{ code:"bh", name:"Bihari" },
{ code:"bi", name:"Bislama" },
{ code:"bm", name:"Bambara" },
{ code:"bn", name:"Bengali" },
{ code:"bo", name:"Tibetan Standard, Tibetan, Central" },
{ code:"br", name:"Breton" },
{ code:"bs", name:"Bosnian" },
{ code:"ca", name:"Catalan; Valencian" },
{ code:"ca_es", name:"Catalan (Spain)" },
{ code:"ce", name:"Chechen" },
{ code:"ch", name:"Chamorro" },
{ code:"co", name:"Corsican" },
{ code:"cr", name:"Cree" },
{ code:"cs", name:"Czech" },
{ code:"cs_cz", name:"Czech (Czech Republic)" },
{ code:"cu", name:"Old Church Slavonic, Church Slavic, Church Slavonic, Old Bulgarian, Old Slavonic" },
{ code:"cv", name:"Chuvash" },
{ code:"cy", name:"Welsh" },
{ code:"da", name:"Danish" },
{ code:"da_dk", name:"Danish (Denmark)" },
{ code:"de", name:"German" },
{ code:"de_at", name:"German (Austria)" },
{ code:"de_ch", name:"German (Switzerland)" },
{ code:"de_de", name:"German (Germany)" },
{ code:"de_lu", name:"German (Luxembourg)" },
{ code:"dv", name:"Divehi; Dhivehi; Maldivian;" },
{ code:"ee", name:"Ewe" },
{ code:"el", name:"Greek, Modern" },
{ code:"el_cy", name:"Greek (Cyprus)" },
{ code:"el_gr", name:"Greek (Greece)" },
{ code:"en", name:"English" },
{ code:"en_au", name:"English (Australia)" },
{ code:"en_ca", name:"English (Canada)" },
{ code:"en_gb", name:"English (United Kingdom)" },
{ code:"en_ie", name:"English (Ireland)" },
{ code:"en_in", name:"English (India)" },
{ code:"en_mt", name:"English (Malta)" },
{ code:"en_nz", name:"English (New Zealand)" },
{ code:"en_ph", name:"English (Philippines)" },
{ code:"en_sg", name:"English (Singapore)" },
{ code:"en_us", name:"English (United States)" },
{ code:"en_za", name:"English (South Africa)" },
{ code:"eo", name:"Esperanto" },
{ code:"es", name:"Spanish; Castilian" },
{ code:"es_ar", name:"Spanish (Argentina)" },
{ code:"es_bo", name:"Spanish (Bolivia)" },
{ code:"es_cl", name:"Spanish (Chile)" },
{ code:"es_co", name:"Spanish (Colombia)" },
{ code:"es_cr", name:"Spanish (Costa Rica)" },
{ code:"es_do", name:"Spanish (Dominican Republic)" },
{ code:"es_ec", name:"Spanish (Ecuador)" },
{ code:"es_es", name:"Spanish (Spain)" },
{ code:"es_gt", name:"Spanish (Guatemala)" },
{ code:"es_hn", name:"Spanish (Honduras)" },
{ code:"es_mx", name:"Spanish (Mexico)" },
{ code:"es_ni", name:"Spanish (Nicaragua)" },
{ code:"es_pa", name:"Spanish (Panama)" },
{ code:"es_pe", name:"Spanish (Peru)" },
{ code:"es_pr", name:"Spanish (Puerto Rico)" },
{ code:"es_py", name:"Spanish (Paraguay)" },
{ code:"es_sv", name:"Spanish (El Salvador)" },
{ code:"es_us", name:"Spanish (United States)" },
{ code:"es_uy", name:"Spanish (Uruguay)" },
{ code:"es_ve", name:"Spanish (Venezuela)" },
{ code:"et", name:"Estonian" },
{ code:"et_ee", name:"Estonian (Estonia)" },
{ code:"eu", name:"Basque" },
{ code:"fa", name:"Persian" },
{ code:"ff", name:"Fula; Fulah; Pulaar; Pular" },
{ code:"fi", name:"Finnish" },
{ code:"fi_fi", name:"Finnish (Finland)" },
{ code:"fj", name:"Fijian" },
{ code:"fo", name:"Faroese" },
{ code:"fr", name:"French" },
{ code:"fr_be", name:"French (Belgium)" },
{ code:"fr_ca", name:"French (Canada)" },
{ code:"fr_ch", name:"French (Switzerland)" },
{ code:"fr_fr", name:"French (France)" },
{ code:"fr_lu", name:"French (Luxembourg)" },
{ code:"fy", name:"Western Frisian" },
{ code:"ga", name:"Irish" },
{ code:"ga_ie", name:"Irish (Ireland)" },
{ code:"gd", name:"Scottish Gaelic; Gaelic" },
{ code:"gl", name:"Galician" },
{ code:"gn", name:"Guaraní" },
{ code:"gu", name:"Gujarati" },
{ code:"gv", name:"Manx" },
{ code:"ha", name:"Hausa" },
{ code:"he", name:"Hebrew (modern)" },
{ code:"hi", name:"Hindi" },
{ code:"hi_in", name:"Hindi (India)" },
{ code:"ho", name:"Hiri Motu" },
{ code:"hr", name:"Croatian" },
{ code:"hr_hr", name:"Croatian (Croatia)" },
{ code:"ht", name:"Haitian; Haitian Creole" },
{ code:"hu", name:"Hungarian" },
{ code:"hu_hu", name:"Hungarian (Hungary)" },
{ code:"hy", name:"Armenian" },
{ code:"hz", name:"Herero" },
{ code:"ia", name:"Interlingua" },
{ code:"id", name:"Indonesian" },
{ code:"ie", name:"Interlingue" },
{ code:"ig", name:"Igbo" },
{ code:"ii", name:"Nuosu" },
{ code:"ik", name:"Inupiaq" },
{ code:"in", name:"Indonesian" },
{ code:"in_id", name:"Indonesian (Indonesia)" },
{ code:"io", name:"Ido" },
{ code:"is", name:"Icelandic" },
{ code:"is_is", name:"Icelandic (Iceland)" },
{ code:"it", name:"Italian" },
{ code:"it_ch", name:"Italian (Switzerland)" },
{ code:"it_it", name:"Italian (Italy)" },
{ code:"iu", name:"Inuktitut" },
{ code:"iw", name:"Hebrew" },
{ code:"iw_il", name:"Hebrew (Israel)" },
{ code:"ja", name:"Japanese" },
{ code:"ja_jp", name:"Japanese (Japan)" },
{ code:"jv", name:"Javanese" },
{ code:"ka", name:"Georgian" },
{ code:"kg", name:"Kongo" },
{ code:"ki", name:"Kikuyu, Gikuyu" },
{ code:"kj", name:"Kwanyama, Kuanyama" },
{ code:"kk", name:"Kazakh" },
{ code:"kl", name:"Kalaallisut, Greenlandic" },
{ code:"km", name:"Khmer" },
{ code:"kn", name:"Kannada" },
{ code:"ko", name:"Korean" },
{ code:"ko_kr", name:"Korean (South Korea)" },
{ code:"kr", name:"Kanuri" },
{ code:"ks", name:"Kashmiri" },
{ code:"ku", name:"Kurdish" },
{ code:"kv", name:"Komi" },
{ code:"kw", name:"Cornish" },
{ code:"ky", name:"Kirghiz, Kyrgyz" },
{ code:"la", name:"Latin" },
{ code:"lb", name:"Luxembourgish, Letzeburgesch" },
{ code:"lg", name:"Luganda" },
{ code:"li", name:"Limburgish, Limburgan, Limburger" },
{ code:"ln", name:"Lingala" },
{ code:"lo", name:"Lao" },
{ code:"lt", name:"Lithuanian" },
{ code:"lt_lt", name:"Lithuanian (Lithuania)" },
{ code:"lu", name:"Luba-Katanga" },
{ code:"lv", name:"Latvian" },
{ code:"lv_lv", name:"Latvian (Latvia)" },
{ code:"mg", name:"Malagasy" },
{ code:"mh", name:"Marshallese" },
{ code:"mi", name:"Māori" },
{ code:"mk", name:"Macedonian" },
{ code:"mk_mk", name:"Macedonian (Macedonia)" },
{ code:"ml", name:"Malayalam" },
{ code:"mn", name:"Mongolian" },
{ code:"mr", name:"Marathi (Marāṭhī)" },
{ code:"ms", name:"Malay" },
{ code:"ms_my", name:"Malay (Malaysia)" },
{ code:"mt", name:"Maltese" },
{ code:"mt_mt", name:"Maltese (Malta)" },
{ code:"my", name:"Burmese" },
{ code:"na", name:"Nauru" },
{ code:"nb", name:"Norwegian Bokmål" },
{ code:"nd", name:"North Ndebele" },
{ code:"ne", name:"Nepali" },
{ code:"ng", name:"Ndonga" },
{ code:"nl", name:"Dutch" },
{ code:"nl_be", name:"Dutch (Belgium)" },
{ code:"nl_nl", name:"Dutch (Netherlands)" },
{ code:"nn", name:"Norwegian Nynorsk" },
{ code:"no", name:"Norwegian" },
{ code:"no_no", name:"Norwegian (Norway)" },
{ code:"nr", name:"South Ndebele" },
{ code:"nv", name:"Navajo, Navaho" },
{ code:"ny", name:"Chichewa; Chewa; Nyanja" },
{ code:"oc", name:"Occitan" },
{ code:"oj", name:"Ojibwe, Ojibwa" },
{ code:"om", name:"Oromo" },
{ code:"or", name:"Oriya" },
{ code:"os", name:"Ossetian, Ossetic" },
{ code:"pa", name:"Panjabi, Punjabi" },
{ code:"pi", name:"Pāli" },
{ code:"pl", name:"Polish" },
{ code:"pl_pl", name:"Polish (Poland)" },
{ code:"ps", name:"Pashto, Pushto" },
{ code:"pt", name:"Portuguese" },
{ code:"pt_br", name:"Portuguese (Brazil)" },
{ code:"pt_pt", name:"Portuguese (Portugal)" },
{ code:"qu", name:"Quechua" },
{ code:"rm", name:"Romansh" },
{ code:"rn", name:"Kirundi" },
{ code:"ro", name:"Romanian, Moldavian, Moldovan" },
{ code:"ro_ro", name:"Romanian (Romania)" },
{ code:"ru", name:"Russian" },
{ code:"ru_ru", name:"Russian (Russia)" },
{ code:"rw", name:"Kinyarwanda" },
{ code:"sa", name:"Sanskrit (Saṁskṛta)" },
{ code:"sc", name:"Sardinian" },
{ code:"sd", name:"Sindhi" },
{ code:"se", name:"Northern Sami" },
{ code:"sg", name:"Sango" },
{ code:"si", name:"Sinhala, Sinhalese" },
{ code:"sk", name:"Slovak" },
{ code:"sk_sk", name:"Slovak (Slovakia)" },
{ code:"sl", name:"Slovene" },
{ code:"sl_si", name:"Slovenian (Slovenia)" },
{ code:"sm", name:"Samoan" },
{ code:"sn", name:"Shona" },
{ code:"so", name:"Somali" },
{ code:"sq", name:"Albanian" },
{ code:"sq_al", name:"Albanian (Albania)" },
{ code:"sr", name:"Serbian" },
{ code:"sr_ba", name:"Serbian (Bosnia and Herzegovina)" },
{ code:"sr_cs", name:"Serbian (Serbia and Montenegro)" },
{ code:"sr_me", name:"Serbian (Montenegro)" },
{ code:"sr_rs", name:"Serbian (Serbia)" },
{ code:"ss", name:"Swati" },
{ code:"st", name:"Southern Sotho" },
{ code:"su", name:"Sundanese" },
{ code:"sv", name:"Swedish" },
{ code:"sv_se", name:"Swedish (Sweden)" },
{ code:"sw", name:"Swahili" },
{ code:"ta", name:"Tamil" },
{ code:"te", name:"Telugu" },
{ code:"tg", name:"Tajik" },
{ code:"th", name:"Thai" },
{ code:"th_th", name:"Thai (Thailand)" },
{ code:"ti", name:"Tigrinya" },
{ code:"tk", name:"Turkmen" },
{ code:"tl", name:"Tagalog" },
{ code:"tn", name:"Tswana" },
{ code:"to", name:"Tonga (Tonga Islands)" },
{ code:"tr", name:"Turkish" },
{ code:"tr_tr", name:"Turkish (Turkey)" },
{ code:"ts", name:"Tsonga" },
{ code:"tt", name:"Tatar" },
{ code:"tw", name:"Twi" },
{ code:"ty", name:"Tahitian" },
{ code:"ug", name:"Uighur, Uyghur" },
{ code:"uk", name:"Ukrainian" },
{ code:"uk_ua", name:"Ukrainian (Ukraine)" },
{ code:"ur", name:"Urdu" },
{ code:"uz", name:"Uzbek" },
{ code:"ve", name:"Venda" },
{ code:"vi", name:"Vietnamese" },
{ code:"vi_vn", name:"Vietnamese (Vietnam)" },
{ code:"vo", name:"Volapük" },
{ code:"wa", name:"Walloon" },
{ code:"wo", name:"Wolof" },
{ code:"xh", name:"Xhosa" },
{ code:"yi", name:"Yiddish" },
{ code:"yo", name:"Yoruba" },
{ code:"za", name:"Zhuang, Chuang" },
{ code:"zh", name:"Chinese" },
{ code:"zh_cn", name:"Chinese (Simplified, China)" },
{ code:"zh_hk", name:"Chinese (Hong Kong)" },
{ code:"zh_sg", name:"Chinese (Singapore)" },
{ code:"zh_tw", name:"Chinese (Traditional, Taiwan)" },
]
language = _.find(isoLangs, (lang) -> lang.code is key)
language = _.find(isoLangs, (lang) -> new RegExp('^' + lang.code, 'i').test(key)) unless language
language = {code:key, name:"Unknown (#{key})"} unless language
language
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment