Search code examples
pythonlocale

Python: Get verbose information from locale in ISO8859-1


If I have locale en_US is there anyway in Python using locale library to get the verbose information of that locale.

Like en_US equals English - United States. es_AR equals Spanish - Argentina.

Solution for future users:

ISO_LOCALE_LANGUAGE_CODES = {'ia': 'Interlingua', 'ik': 'Inupiak; Inupiaq', 'am': 'Amharic', 'km': 'Central Khmer; Cambodian', 'wa': 'Walloon', 'gn': 'Guarani', 'hi': 'Hindi', 'tl': 'Tagalog', 'tk': 'Turkmen', 'ca': 'Catalan', 'iu': 'Inuktitut', 'sn': 'Shona', 'to': 'Tonga', 'lu': 'Luba-Katanga', 'kr': 'Kanuri', 'yo': 'Yoruba', 'uz': 'Uzbek', 'ks': 'Kashmiri', 'sq': 'Albanian', 'sl': 'Slovenian', 'be': 'Belarusian', 'kk': 'Kazakh', 'gl': 'Galician', 'ug': 'Uighur', 'bo': 'Tibetan', 'af': 'Afrikaans', 'fi': 'Finnish', 'fo': 'Faroese', 'ee': 'Éwé', 'sw': 'Swahili', 'gv': 'Manx', 'zu': 'Zulu', 'cr': 'Cree', 'ro': 'Romanian', 'ab': 'Abkhazian', 'ng': 'Ndonga', 'tw': 'Twi', 'pa': 'Panjabi; Punjabi', 'mi': 'Maori', 'bh': 'Bihari', 'lv': 'Latvian; Lettish', 'mt': 'Maltese', 'zh': 'Chinese', 'ae': 'Avestan', 'ne': 'Nepali', 'ig': 'Igbo', 'kv': 'Komi', 'es': 'Spanish', 'xh': 'Xhosa', 'eo': 'Esperanto', 'pi': 'Pali', 'no': 'Norwegian', 'kg': 'Kongo', 'nb': 'Norwegian Bokmål', 'si': 'Sinhala; Sinhalese', 'ar': 'Arabic', 'so': 'Somali', 'tt': 'Tatar', 'nl': 'Dutch', 'or': 'Oriya', 'da': 'Danish', 'ps': 'Pashto; Pushto', 'bi': 'Bislama', 'ky': 'Kirghiz', 'tr': 'Turkish', 'ru': 'Russian', 'ho': 'Hiri Motu', 'eu': 'Basque', 'bn': 'Bengali; Bangla', 'su': 'Sundanese', 'hr': 'Croatian', 'ka': 'Georgian', 've': 'Venda', 'nd': 'Ndebele, North', 'ff': 'Fulah', 'nr': 'Ndebele, South', 'fa': 'Persian', 'io': 'Ido', 'oc': 'Occitan; Provençal', 'aa': 'Afar', 'ha': 'Hausa', 'jv': 'Javanese', 'sa': 'Sanskrit', 'ms': 'Malay', 'dz': 'Dzongkha; Bhutani', 'ht': 'Haitian; Haitian Creole', 'kl': 'Kalaallisut; Greenlandic', 'en': 'English', 'sm': 'Samoan', 'lo': 'Lao; Laotian', 'mh': 'Marshallese', 'sd': 'Sindhi', 'he': 'Hebrew (formerly iw)', 'ja': 'Japanese', 'ki': 'Kikuyu; Gikuyu', 'ii': 'Sichuan Yi; Nuosu', 'li': 'Limburgish; Limburger; Limburgan', 'hu': 'Hungarian', 'la': 'Latin', 'tg': 'Tajik', 'cv': 'Chuvash', 'co': 'Corsican', 'ln': 'Lingala', 'th': 'Thai', 'bm': 'Bambara', 'mn': 'Mongolian', 'sv': 'Swedish', 'nn': 'Norwegian Nynorsk', 'lb': 'Letzeburgesch; Luxembourgish', 'mg': 'Malagasy', 'lg': 'Ganda', 'yi': 'Yiddish (formerly ji)', 'gd': 'Scottish Gaelic', 'mo': 'Moldavian', 'dv': 'Divehi; Maldivian', 'te': 'Telugu', 'om': '(Afan) Oromo', 'fy': 'Western Frisian', 'br': 'Breton', 'kj': 'Kuanyama; Kwanyama', 'sc': 'Sardinian', 'cu': 'Church Slavic', 'bg': 'Bulgarian', 'kn': 'Kannada', 'mr': 'Marathi', 'sk': 'Slovak', 'st': 'Sesotho; Sotho, Southern', 'ta': 'Tamil', 'ga': 'Irish', 'el': 'Greek', 'ti': 'Tigrinya', 'wo': 'Wolof', 'hz': 'Herero', 'rw': 'Kinyarwanda', 'is': 'Icelandic', 'ko': 'Korean', 'id': 'Indonesian (formerly in)', 'ml': 'Malayalam', 'ch': 'Chamorro', 'ku': 'Kurdish', 'gu': 'Gujarati', 'ak': 'Akan', 'kw': 'Cornish', 'ba': 'Bashkir', 'ce': 'Chechen', 'de': 'German', 'my': 'Burmese', 'ay': 'Aymara', 'cs': 'Czech', 'mk': 'Macedonian', 'tn': 'Tswana; Setswana', 'lt': 'Lithuanian', 'sg': 'Sango; Sangro', 'ss': 'Swati; Siswati', 'an': 'Aragonese', 'sr': 'Serbian', 'av': 'Avaric', 'it': 'Italian', 'fr': 'French', 'na': 'Nauru', 'cy': 'Welsh', 'ur': 'Urdu', 'hy': 'Armenian', 'as': 'Assamese', 'et': 'Estonian', 'os': 'Ossetian; Ossetic', 'rm': 'Romansh', 'ie': 'Interlingue; Occidental', 'rn': 'Rundi; Kirundi', 'nv': 'Navajo; Navaho', 'se': 'Northern Sami', 'ty': 'Tahitian', 'fj': 'Fijian; Fiji', 'ts': 'Tsonga', 'bs': 'Bosnian', 'ny': 'Chichewa; Nyanja', 'vo': 'Volapük; Volapuk', 'pt': 'Portuguese', 'vi': 'Vietnamese', 'oj': 'Ojibwa', 'uk': 'Ukrainian', 'za': 'Zhuang', 'qu': 'Quechua', 'pl': 'Polish', 'az': 'Azerbaijani'}
ISO_LOCALE_COUNTRY_CODES = {'PL': 'Poland', 'AI': 'Anguilla', 'DJ': 'Djibouti', 'PT': 'Portugal', 'DE': 'Germany', 'TD': 'Chad', 'BL': 'Saint Barthelemy', 'IN': 'India', 'TL': 'Timor-Leste', 'WF': 'Wallis and Futuna', 'GI': 'Gibraltar', 'MY': 'Malaysia', 'BW': 'Botswana', 'LT': 'Lithuania', 'SD': 'Sudan', 'TC': 'Turks and Caicos Islands', 'SX': 'Sint Maarten (Dutch part)', 'LU': 'Luxembourg', 'KH': 'Cambodia', 'AD': 'Andorra', 'HM': 'Heard Island and McDonald Islands', 'PN': 'Pitcairn', 'GP': 'Guadeloupe', 'BN': 'Brunei Darussalam', 'IR': 'Iran, Islamic Republic of', 'DZ': 'Algeria', 'ZA': 'South Africa', 'TJ': 'Tajikistan', 'MD': 'Moldova, Republic of', 'ZW': 'Zimbabwe', 'LS': 'Lesotho', 'BG': 'Bulgaria', 'ET': 'Ethiopia', 'FR': 'France', 'SL': 'Sierra Leone', 'HN': 'Honduras', 'PE': 'Peru', 'GD': 'Grenada', 'EG': 'Egypt', 'TW': 'Taiwan, Province of China', 'GH': 'Ghana', 'IS': 'Iceland', 'PK': 'Pakistan', 'KM': 'Comoros', 'SB': 'Solomon Islands', 'BQ': 'Bonaire, Sint Eustatius and Saba', 'BJ': 'Benin', 'KN': 'Saint Kitts and Nevis', 'UY': 'Uruguay', 'VN': 'Viet Nam', 'EC': 'Ecuador', 'ID': 'Indonesia', 'SE': 'Sweden', 'GY': 'Guyana', 'IL': 'Israel', 'AM': 'Armenia', 'CL': 'Chile', 'UG': 'Uganda', 'VI': 'Virgin Islands, US', 'RW': 'Rwanda', 'KE': 'Kenya', 'BH': 'Bahrain', 'NO': 'Norway', 'NR': 'Nauru', 'SV': 'El Salvador', 'GG': 'Guernsey', 'PG': 'Papua New Guinea', 'KI': 'Kiribati', 'RU': 'Russian Federation', 'RO': 'Romania', 'MV': 'Maldives', 'VU': 'Vanuatu', 'PA': 'Panama', 'LV': 'Latvia', 'AO': 'Angola', 'NA': 'Namibia', 'BY': 'Belarus', 'NG': 'Nigeria', 'AF': 'Afghanistan', 'GB': 'United Kingdom', 'SA': 'Saudi Arabia', 'GQ': 'Equatorial Guinea', 'GA': 'Gabon', 'EE': 'Estonia', 'NC': 'New Caledonia', 'MG': 'Madagascar', 'MC': 'Monaco', 'CZ': 'Czech Republic', 'BE': 'Belgium', 'MA': 'Morocco', 'MF': 'Saint Martin (French part)', 'SJ': 'Svalbard and Jan Mayen', 'NP': 'Nepal', 'LY': 'Libya', 'CH': 'Switzerland', 'BS': 'Bahamas', 'CG': 'Congo', 'MK': 'Macedonia, The Former Yugoslav Republic of', 'TN': 'Tunisia', 'NL': 'Netherlands', 'JM': 'Jamaica', 'HT': 'Haiti', 'MU': 'Mauritius', 'CK': 'Cook Islands', 'CA': 'Canada', 'ME': 'Montenegro', 'DO': 'Dominican Republic', 'SM': 'San Marino', 'PF': 'French Polynesia', 'NF': 'Norfolk Island', 'CV': 'Cape Verde', 'LB': 'Lebanon', 'UZ': 'Uzbekistan', 'CI': 'Côte dIvoire', 'VG': 'Virgin Islands, British', 'KZ': 'Kazakhstan', 'RS': 'Serbia', 'CC': 'Cocos (Keeling) Islands', 'BI': 'Burundi', 'US': 'United States', 'SN': 'Senegal', 'VE': 'Venezuela, Bolivarian Republic of', 'FO': 'Faroe Islands', 'NE': 'Niger', 'EH': 'Western Sahara', 'AE': 'United Arab Emirates', 'TK': 'Tokelau', 'KW': 'Kuwait', 'CW': 'Curaçao', 'NI': 'Nicaragua', 'CF': 'Central African Republic', 'MN': 'Mongolia', 'JE': 'Jersey', 'BR': 'Brazil', 'HK': 'Hong Kong', 'AQ': 'Antarctica', 'TH': 'Thailand', 'PM': 'Saint Pierre and Miquelon', 'TM': 'Turkmenistan', 'LA': 'Lao Peoples Democratic Republic', 'BM': 'Bermuda', 'BD': 'Bangladesh', 'AL': 'Albania', 'GE': 'Georgia', 'TO': 'Tonga', 'MM': 'Myanmar', 'BO': 'Bolivia, Plurinational State of', 'IE': 'Ireland', 'WS': 'Samoa', 'FK': 'Falkland Islands (Malvinas)', 'YE': 'Yemen', 'CN': 'China', 'CX': 'Christmas Island', 'SC': 'Seychelles', 'JO': 'Jordan', 'DM': 'Dominica', 'BV': 'Bouvet Island', 'LR': 'Liberia', 'VA': 'Holy See (Vatican City State)', 'SY': 'Syrian Arab Republic', 'SG': 'Singapore', 'MW': 'Malawi', 'CD': 'Congo, The Democratic Republic of the', 'BZ': 'Belize', 'KY': 'Cayman Islands', 'SK': 'Slovakia', 'ML': 'Mali', 'PW': 'Palau', 'FJ': 'Fiji', 'UA': 'Ukraine', 'CY': 'Cyprus', 'GM': 'Gambia', 'DK': 'Denmark', 'SH': 'Saint Helena, Ascension and Tristan da Cunha', 'PR': 'Puerto Rico', 'AS': 'American Samoa', 'BF': 'Burkina Faso', 'AR': 'Argentina', 'TZ': 'Tanzania, United Republic of', 'RE': 'Reunion', 'AW': 'Aruba', 'CM': 'Cameroon', 'MR': 'Mauritania', 'NU': 'Niue', 'GT': 'Guatemala', 'LI': 'Liechtenstein', 'KR': 'Korea, Republic of', 'SZ': 'Swaziland', 'ES': 'Spain', 'FM': 'Micronesia, Federated States of', 'AZ': 'Azerbaijan', 'FI': 'Finland', 'OM': 'Oman', 'NZ': 'New Zealand', 'KG': 'Kyrgyzstan', 'TV': 'Tuvalu', 'AT': 'Austria', 'MS': 'Montserrat', 'GN': 'Guinea', 'MX': 'Mexico', 'GU': 'Guam', 'TF': 'French Southern Territories', 'MP': 'Northern Mariana Islands', 'UM': 'United States Minor Outlying Islands', 'CU': 'Cuba', 'PH': 'Philippines', 'PY': 'Paraguay', 'JP': 'Japan', 'IO': 'British Indian Ocean Territory', 'IT': 'Italy', 'TG': 'Togo', 'IQ': 'Iraq', 'LK': 'Sri Lanka', 'AG': 'Antigua and Barbuda', 'BT': 'Bhutan', 'QA': 'Qatar', 'SO': 'Somalia', 'SI': 'Slovenia', 'BA': 'Bosnia and Herzegovina', 'LC': 'Saint Lucia', 'SR': 'Suriname', 'AU': 'Australia', 'GF': 'French Guiana', 'PS': 'Palestine, State of', 'IM': 'Isle of Man', 'HR': 'Croatia', 'ER': 'Eritrea', 'GW': 'Guinea-Bissau', 'GR': 'Greece', 'CO': 'Colombia', 'VC': 'Saint Vincent and the Grenadines', 'GL': 'Greenland', 'AX': 'Aaland Islands', 'TT': 'Trinidad and Tobago', 'MZ': 'Mozambique', 'ST': 'Sao Tome and Principe', 'GS': 'South Georgia and the South Sandwich Islands', 'KP': 'Korea, Democratic Peoples Republic of', 'YT': 'Mayotte', 'MQ': 'Martinique', 'CR': 'Costa Rica', 'SS': 'South Sudan', 'MT': 'Malta', 'MO': 'Macao', 'HU': 'Hungary', 'TR': 'Turkey', 'MH': 'Marshall Islands', 'ZM': 'Zambia', 'BB': 'Barbados'}

Solution

  • Take a look here:

    https://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html

    One approach is to download both text files (listed in the first paragraph), and combine the values the codes map to.

    For example "en" is defined as "English" in the first file, and "US" as "United States" in the second file. These appear in separate files, because the list would be exhaustive if every combination of language+country was listed.