Last active
July 23, 2022 23:46
-
-
Save pcnoic/5987bc528192d112f09e6c95acb37481 to your computer and use it in GitHub Desktop.
BCP47 language list for JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const data = [{ "af-ZA": "Afrikaans (South Africa)" }, | |
{ "en-NR": "English (Nauru)" }, | |
{ "fr-RE": "French (Réunion)" }, | |
{ "ar-AE": "Arabic (United Arab Emirates)" }, | |
{ "en-NU": "English (Niue)" }, | |
{ "fr-RW": "French (Rwanda)" }, | |
{ "ar-AR": "Arabic (Arabic)" }, | |
{ "en-NZ": "English (New Zealand)" }, | |
{ "fr-SC": "French (Seychelles)" }, | |
{ "ar-BH": "Arabic (Bahrain)" }, | |
{ "en-PG": "English (Papua New Guinea)" }, | |
{ "fr-SN": "French (Senegal)" }, | |
{ "ar-DJ": "Arabic (Djibouti)" }, | |
{ "en-PH": "English (Philippines)" }, | |
{ "fr-TD": "French (Chad)" }, | |
{ "ar-DZ": "Arabic (Algeria)" }, | |
{ "en-PI": "English (Pirate)" }, | |
{ "fr-TG": "French (Togo)" }, | |
{ "ar-EG": "Arabic (Egypt)" }, | |
{ "en-PK": "English (Pakistan)" }, | |
{ "fr-VU": "French (Vanuatu)" }, | |
{ "ar-EH": "Arabic (Western Sahara)" }, | |
{ "en-PN": "English (Pitcairn Islands)" }, | |
{ "fr-WF": "French (Wallis and Futuna)" }, | |
{ "ar-ER": "Arabic (Eritrea)" }, | |
{ "en-PR": "English (Puerto Rico)" }, | |
{ "fr-YT": "French (Mayotte)" }, | |
{ "ar-IL": "Arabic (Israel)" }, | |
{ "en-PW": "English (Palau)" }, | |
{ "fy-NL": "Frisian (Netherlands)" }, | |
{ "ar-IQ": "Arabic (Iraq)" }, | |
{ "en-RW": "English (Rwanda)" }, | |
{ "ga-GB": "Irish (United Kingdom)" }, | |
{ "ar-JO": "Arabic (Jordan)" }, | |
{ "en-SB": "English (Solomon Islands)" }, | |
{ "ga-IE": "Irish (Ireland)" }, | |
{ "ar-KM": "Arabic (Comoros)" }, | |
{ "en-SC": "English (Seychelles)" }, | |
{ "gl-ES": "Galician (Spain)" }, | |
{ "ar-KW": "Arabic (Kuwait)" }, | |
{ "en-SD": "English (Sudan)" }, | |
{ "he-IL": "Hebrew (Israel)" }, | |
{ "ar-LB": "Arabic (Lebanon)" }, | |
{ "en-SG": "English (Singapore)" }, | |
{ "hi-FJ": "Hindi (Fiji)" }, | |
{ "ar-LY": "Arabic (Libya)" }, | |
{ "en-SH": "English (Saint Helena)" }, | |
{ "hi-IN": "Hindi (India)" }, | |
{ "ar-MA": "Arabic (Morocco)" }, | |
{ "en-SL": "English (Sierra Leone)" }, | |
{ "hi-PK": "Hindi (Pakistan)" }, | |
{ "ar-MR": "Arabic (Mauritania)" }, | |
{ "en-SO": "English (Somalia)" }, | |
{ "hr-BA": "Croatian (Bosnia and Herzegovina)" }, | |
{ "ar-OM": "Arabic (Oman)" }, | |
{ "en-SS": "English (South Sudan)" }, | |
{ "hr-HR": "Croatian (Croatia)" }, | |
{ "ar-PS": "Arabic (West Bank and Gaza)" }, | |
{ "en-SZ": "English (Swaziland)" }, | |
{ "hu-HU": "Hungarian (Hungary)" }, | |
{ "ar-QA": "Arabic (Qatar)" }, | |
{ "en-TC": "English (Turks and Caicos Islands)" }, | |
{ "hy-AM": "Armenian (Armenia)" }, | |
{ "ar-SA": "Arabic (Saudi Arabia)" }, | |
{ "en-TO": "English (Tonga)" }, | |
{ "id-ID": "Indonesian (Indonesia)" }, | |
{ "ar-SD": "Arabic (Sudan)" }, | |
{ "en-TT": "English (Trinidad and Tobago)" }, | |
{ "is-IS": "Icelandic (Iceland)" }, | |
{ "ar-SO": "Arabic (Somalia)" }, | |
{ "en-TV": "English (Tuvalu)" }, | |
{ "it-CH": "Italian (Switzerland)" }, | |
{ "ar-SY": "Arabic (Syria)" }, | |
{ "en-TZ": "English (Tanzania)" }, | |
{ "it-IT": "Italian (Italy)" }, | |
{ "ar-TD": "Arabic (Chad)" }, | |
{ "en-UD": "English (Upside Down)" }, | |
{ "it-SM": "Italian (San Marino)" }, | |
{ "ar-TN": "Arabic (Tunisia)" }, | |
{ "en-UG": "English (Uganda)" }, | |
{ "it-VA": "Italian (Vatican City)" }, | |
{ "ar-YE": "Arabic (Yemen)" }, | |
{ "en-US": "English (United States)" }, | |
{ "ja-JP": "Japanese (Japan)" }, | |
{ "az-AZ": "Azerbaijani (Azerbaijan)" }, | |
{ "en-VC": "English (St. Vincent and the Grenadines)" }, | |
{ "ja-PW": "Japanese (Palau)" }, | |
{ "be-BY": "Belarusian (Belarus)" }, | |
{ "en-VG": "English (British Virgin Islands)" }, | |
{ "ka-GE": "Georgian (Georgia)" }, | |
{ "bg-BG": "Bulgarian (Bulgaria)" }, | |
{ "en-VI": "English (United States Virgin Islands)" }, | |
{ "km-KH": "Khmer (Cambodia)" }, | |
{ "bn-IN": "Bengali (India)" }, | |
{ "en-VU": "English (Vanuatu)" }, | |
{ "ko-KP": "Korean (DPRK)" }, | |
{ "bs-BA": "Bosnian (Bosnia and Herzegovina)" }, | |
{ "en-WS": "English (Samoa)" }, | |
{ "ko-KR": "Korean (South Korea)" }, | |
{ "ca-AD": "Catalan (Andorra)" }, | |
{ "en-ZA": "English (South Africa)" }, | |
{ "ku-TR": "Kurdish (Turkey)" }, | |
{ "ca-ES": "Catalan (Spain)" }, | |
{ "en-ZM": "English (Zambia)" }, | |
{ "la-VA": "Latin (Vatican City)" }, | |
{ "cs-CZ": "Czech (Czech Republic)" }, | |
{ "en-ZW": "English (Zimbabwe)" }, | |
{ "lt-LT": "Lithuanian (Lithuania)" }, | |
{ "cs-SK": "Czech (Slovak Republic)" }, | |
{ "eo-EO": "Esperanto (Esperanto)" }, | |
{ "lv-LV": "Latvian (Latvia)" }, | |
{ "cy-GB": "Welsh (United Kingdom)" }, | |
{ "es-AR": "Spanish (Argentina)" }, | |
{ "mk-MK": "Macedonian (Macedonia)" }, | |
{ "da-DK": "Danish (Denmark)" }, | |
{ "es-BO": "Spanish (Bolivia)" }, | |
{ "ml-IN": "Malayalam (India)" }, | |
{ "da-FO": "Danish (Faeroe Islands)" }, | |
{ "es-CL": "Spanish (Chile)" }, | |
{ "ms-BN": "Malay (Brunei)" }, | |
{ "da-GL": "Danish (Greenland)" }, | |
{ "es-CO": "Spanish (Colombia)" }, | |
{ "ms-ID": "Malay (Indonesia)" }, | |
{ "de-AT": "German (Austria)" }, | |
{ "es-CR": "Spanish (Costa Rica)" }, | |
{ "ms-MY": "Malay (Malaysia)" }, | |
{ "de-BE": "German (Belgium)" }, | |
{ "es-CU": "Spanish (Cuba)" }, | |
{ "ms-SG": "Malay (Singapore)" }, | |
{ "de-CH": "German (Switzerland)" }, | |
{ "es-DO": "Spanish (Dominican Republic)" }, | |
{ "mt-MT": "Maltese (Malta)" }, | |
{ "de-DE": "German (Germany)" }, | |
{ "es-EC": "Spanish (Ecuador)" }, | |
{ "nb-NO": "Norwegian Bokmål (Norway)" }, | |
{ "de-LI": "German (Liechtenstein)" }, | |
{ "es-ES": "Spanish (Spain)" }, | |
{ "ne-NP": "Nepali (Nepal)" }, | |
{ "de-LU": "German (Luxembourg)" }, | |
{ "es-GI": "Spanish (Gibraltar)" }, | |
{ "nl-AN": "Dutch (Netherlands Antilles)" }, | |
{ "de-NA": "German (Namibia)" }, | |
{ "es-GQ": "Spanish (Equatorial Guinea)" }, | |
{ "nl-AW": "Dutch (Aruba)" }, | |
{ "el-CY": "Greek (Cyprus)" }, | |
{ "es-GT": "Spanish (Guatemala)" }, | |
{ "nl-BE": "Dutch (Belgium)" }, | |
{ "el-GR": "Greek (Greece)" }, | |
{ "es-HN": "Spanish (Honduras)" }, | |
{ "nl-CW": "Dutch (Curaçao)" }, | |
{ "en-AG": "English (Antigua and Barbuda)" }, | |
{ "es-LA": "Spanish (Spanish)" }, | |
{ "nl-NL": "Dutch (Netherlands)" }, | |
{ "en-AI": "English (Anguilla)" }, | |
{ "es-MX": "Spanish (Mexico)" }, | |
{ "nl-SR": "Dutch (Suriname)" }, | |
{ "en-AS": "English (American Samoa)" }, | |
{ "es-NI": "Spanish (Nicaragua)" }, | |
{ "nl-SX": "Dutch (Sint Maarten (Dutch part)" }, | |
{ "en-AU": "English (Australia)" }, | |
{ "es-PA": "Spanish (Panama)" }, | |
{ "nn-NO": "Norwegian Nynorsk (Norway)" }, | |
{ "en-BB": "English (Barbados)" }, | |
{ "es-PE": "Spanish (Peru)" }, | |
{ "no-NO": "Norwegian (Norway)" }, | |
{ "en-BD": "English (Bangladesh)" }, | |
{ "es-PR": "Spanish (Puerto Rico)" }, | |
{ "pa-IN": "Punjabi (India)" }, | |
{ "en-BM": "English (Bermuda)" }, | |
{ "es-PY": "Spanish (Paraguay)" }, | |
{ "pl-PL": "Polish (Poland)" }, | |
{ "en-BS": "English (The Bahamas)" }, | |
{ "es-SV": "Spanish (El Salvador)" }, | |
{ "ps-AF": "Pashto (Afghanistan)" }, | |
{ "en-BW": "English (Botswana)" }, | |
{ "es-US": "Spanish (United States)" }, | |
{ "pt-AO": "Portuguese (Angola)" }, | |
{ "en-BZ": "English (Belize)" }, | |
{ "es-UY": "Spanish (Uruguay)" }, | |
{ "pt-BR": "Portuguese (Brazil)" }, | |
{ "en-CA": "English (Canada)" }, | |
{ "es-VE": "Spanish (Venezuela)" }, | |
{ "pt-CV": "Portuguese (Cape Verde)" }, | |
{ "en-CK": "English (Cook Islands)" }, | |
{ "et-EE": "Estonian (Estonia)" }, | |
{ "pt-GQ": "Portuguese (Equatorial Guinea)" }, | |
{ "en-CM": "English (Cameroon)" }, | |
{ "eu-ES": "Basque (Spain)" }, | |
{ "pt-GW": "Portuguese (Guinea-Bissau)" }, | |
{ "en-CW": "English (Curaçao)" }, | |
{ "fa-IR": "Persian (Iran)" }, | |
{ "pt-MO": "Portuguese (Macao)" }, | |
{ "en-DM": "English (Dominica)" }, | |
{ "fb-LT": "Leet Speak" }, | |
{ "pt-MZ": "Portuguese (Mozambique)" }, | |
{ "en-ER": "English (Eritrea)" }, | |
{ "fi-FI": "Finnish (Finland)" }, | |
{ "pt-PT": "Portuguese (Portugal)" }, | |
{ "en-FJ": "English (Fiji)" }, | |
{ "fo-FO": "Faroese (Faeroe Islands)" }, | |
{ "pt-ST": "Portuguese (São Tomé and Principe)" }, | |
{ "en-FK": "English (Falkland Islands)" }, | |
{ "fr-BE": "French (Belgium)" }, | |
{ "pt-TL": "Portuguese (Timor-Leste)" }, | |
{ "en-FM": "English (Micronesia)" }, | |
{ "fr-BF": "French (Burkina Faso)" }, | |
{ "ro-MD": "Romanian (Moldova)" }, | |
{ "en-GB": "English (United Kingdom)" }, | |
{ "fr-BI": "French (Burundi)" }, | |
{ "ro-RO": "Romanian (Romania)" }, | |
{ "en-GD": "English (Grenada)" }, | |
{ "fr-BJ": "French (Benin)" }, | |
{ "ru-BY": "Russian (Belarus)" }, | |
{ "en-GG": "English (Guernsey)" }, | |
{ "fr-CA": "French (Canada)" }, | |
{ "ru-KG": "Russian (Kyrgyz Republic)" }, | |
{ "en-GH": "English (Ghana)" }, | |
{ "fr-CD": "French (Dem. Rep. Congo)" }, | |
{ "ru-KZ": "Russian (Kazakhstan)" }, | |
{ "en-GI": "English (Gibraltar)" }, | |
{ "fr-CF": "French (Central African Republic)" }, | |
{ "ru-RU": "Russian (Russia)" }, | |
{ "en-GM": "English (The Gambia)" }, | |
{ "fr-CG": "French (Congo)" }, | |
{ "ru-TJ": "Russian (Tajikistan)" }, | |
{ "en-GU": "English (Guam)" }, | |
{ "fr-CH": "French (Switzerland)" }, | |
{ "sk-CZ": "Slovak (Czech Republic)" }, | |
{ "en-GY": "English (Guyana)" }, | |
{ "fr-CI": "French (Côte d’Ivoire)" }, | |
{ "sk-SK": "Slovak (Slovakia)" }, | |
{ "en-HK": "English (Hong Kong)" }, | |
{ "fr-CM": "French (Cameroon)" }, | |
{ "sl-SI": "Slovenian (Slovenia)" }, | |
{ "en-IE": "English (Ireland)" }, | |
{ "fr-DJ": "French (Djibouti)" }, | |
{ "sq-AL": "Albanian (Albania)" }, | |
{ "en-IM": "English (Isle of Man)" }, | |
{ "fr-FR": "French (France)" }, | |
{ "sq-KS": "Albanian (Kosovo)" }, | |
{ "en-IN": "English (India)" }, | |
{ "fr-GA": "French (Gabon)" }, | |
{ "sr-BA": "Serbian (Bosnia and Herzegovina)" }, | |
{ "en-JE": "English (Jersey)" }, | |
{ "fr-GD": "French (Grenada)" }, | |
{ "sr-ME": "Serbian (Montenegro)" }, | |
{ "en-JM": "English (Jamaica)" }, | |
{ "fr-GF": "French (French Guianna)" }, | |
{ "sr-RS": "Serbian (Serbia)" }, | |
{ "en-KE": "English (Kenya)" }, | |
{ "fr-GN": "French (Guinea)" }, | |
{ "sv-FI": "Swedish (Finland)" }, | |
{ "en-KI": "English (Kiribati)" }, | |
{ "fr-GP": "French (Guadeloupe)" }, | |
{ "sv-SE": "Swedish (Sweden)" }, | |
{ "en-KN": "English (St. Kitts and Nevis)" }, | |
{ "fr-GQ": "French (Equatorial Guinea)" }, | |
{ "sw-KE": "Swahili (Kenya)" }, | |
{ "en-KY": "English (Cayman Islands)" }, | |
{ "fr-HT": "French (Haiti)" }, | |
{ "ta-IN": "Tamil (India)" }, | |
{ "en-LC": "English (St. Lucia)" }, | |
{ "fr-KM": "French (Comoros)" }, | |
{ "te-IN": "Telugu (India)" }, | |
{ "en-LK": "English (Sri Lanka)" }, | |
{ "fr-LC": "French (St. Lucia)" }, | |
{ "th-TH": "Thai (Thailand)" }, | |
{ "en-LR": "English (Liberia)" }, | |
{ "fr-LU": "French (Luxembourg)" }, | |
{ "tl-PH": "Filipino (Philippines)" }, | |
{ "en-LS": "English (Lesotho)" }, | |
{ "fr-MC": "French (Monaco)" }, | |
{ "tr-CY": "Turkish (Cyprus)" }, | |
{ "en-MH": "English (Marshall Islands)" }, | |
{ "fr-MF": "French (St. Martin (French part)" }, | |
{ "tr-TR": "Turkish (Turkey)" }, | |
{ "en-MP": "English (Northern Mariana Islands)" }, | |
{ "fr-MG": "French (Madagascar)" }, | |
{ "uk-UA": "Ukrainian (Ukraine)" }, | |
{ "en-MS": "English (Montserrat)" }, | |
{ "fr-ML": "French (Mali)" }, | |
{ "vi-VN": "Vietnamese (Vietnam)" }, | |
{ "en-MT": "English (Malta)" }, | |
{ "fr-MQ": "French (Martinique)" }, | |
{ "zh-CN": "Chinese (China)" }, | |
{ "en-MU": "English (Mauritius)" }, | |
{ "fr-MU": "French (Mauritius)" }, | |
{ "zh-HK": "Chinese (Hong Kong)" }, | |
{ "en-MW": "English (Malawi)" }, | |
{ "fr-NC": "French (New Caledonia)" }, | |
{ "zh-MO": "Chinese (Macao)" }, | |
{ "en-MY": "English (Malaysia)" }, | |
{ "fr-NE": "French (Niger)" }, | |
{ "zh-SG": "Chinese (Singapore)" }, | |
{ "en-NA": "English (Namibia)" }, | |
{ "fr-PF": "French (French Polynesia)" }, | |
{ "zh-TW": "Chinese (Taiwan)" }, | |
{ "en-NG": "English (Nigeria)" }, | |
{ "fr-PM": "French (Saint Pierre and Miquelon)" }] | |
function sortLanguages() { | |
var sorted = []; | |
for (var i = 0; i < data.length; i++) { | |
var lang = data[i]; | |
var key = Object.keys(lang)[0]; | |
var value = lang[key]; | |
sorted.push({ key: key, value: value }); | |
} | |
sorted.sort(function (a, b) { | |
return a.value.localeCompare(b.value); | |
}); | |
return sorted; | |
} | |
const sorted = sortLanguages(); | |
function getAllLanguages() { | |
var languages = []; | |
for (var i = 0; i < sorted.length; i++) { | |
languages.push(sorted[i][Object.keys(sorted[i])[1]]); | |
} | |
return languages; | |
} | |
function getLanguageCode(languageName) { | |
for (var i = 0; i < sorted.length; i++) { | |
if (sorted[i][Object.keys(sorted[i])[1]] === languageName) { | |
return sorted[i][Object.keys(sorted[i])[0]]; | |
} | |
} | |
} | |
function getLanguageName(languageCode) { | |
for (var i = 0; i < sorted.length; i++) { | |
if (sorted[i][Object.keys(sorted[i])[0]] === languageCode) { | |
return sorted[i][Object.keys(sorted[i])[1]]; | |
} | |
} | |
} | |
export { getAllLanguages, getLanguageCode, getLanguageName }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
data
array is manual labor and it's not sorted. Feel free to sort it in source to avoid programmatic sorting in runtime. Also,getLanguageName
andgetLanguageCode
could avoid BF search. Again, feel free.