Getting Parent Culture

by Jun 2, 2023

Most of the time, localized resources are tagged with a culture name such as “en-us” or “de-de”. If you’d like to know what such an ID stands for, simply convert it to [System.Globalization.CultureInfo]:

 
PS> [System.Globalization.CultureInfo]'en-us'

LCID             Name             DisplayName
----             ----             -----------
1033             en-US            English (United States)



PS> [System.Globalization.CultureInfo]'de-de'

LCID             Name             DisplayName
----             ----             -----------
1031             de-DE            German (Germany)
 

As you see, there are culture names on a very granular level. For example, there are 106 sub-cultures that all share the same English base culture:

 
PS> [System.Globalization.CultureInfo]::GetCultures( [System.Globalization.CultureTypes]::AllCultures) | Where-Object Parent -eq 'en'

LCID             Name             DisplayName              
----             ----             -----------          
4096             en-001           English (World)  
9225             en-029           English (Caribbean)
4096             en-150           English (Europe)
19465            en-AE            English (United Arab Emirates)
4096             en-AG            English (Antigua and Barbuda)
4096             en-AI            English (Anguilla)
4096             en-AS            English (American Samoa)
4096             en-AT            English (Austria)
3081             en-AU            English (Australia)
4096             en-BB            English (Barbados)
4096             en-BE            English (Belgium)
4096             en-BI            English (Burundi)
4096             en-BM            English (Bermuda) 
4096             en-BS            English (Bahamas) 
4096             en-BW            English (Botswana)
10249            en-BZ            English (Belize)
4105             en-CA            English (Canada)
4096             en-CC            English (Cocos [Keeling] Islands)
4096             en-CH            English (Switzerland)
4096             en-CK            English (Cook Islands)
4096             en-CM            English (Cameroon)
4096             en-CX            English (Christmas Island)
4096             en-CY            English (Cyprus) 
4096             en-DE            English (Germany)
4096             en-DK            English (Denmark) 
4096             en-DM            English (Dominica)
4096             en-ER            English (Eritrea)  
4096             en-FI            English (Finland) 
4096             en-FJ            English (Fiji)   
4096             en-FK            English (Falkland Islands)
4096             en-FM            English (Micronesia)
2057             en-GB            English (United Kingdom)
4096             en-GD            English (Grenada)
4096             en-GG            English (Guernsey)
4096             en-GH            English (Ghana)
4096             en-GI            English (Gibraltar)
4096             en-GM            English (Gambia)   
4096             en-GU            English (Guam)      
4096             en-GY            English (Guyana)
15369            en-HK            English (Hong Kong SAR)
14345            en-ID            English (Indonesia)
6153             en-IE            English (Ireland) 
4096             en-IL            English (Israel)
4096             en-IM            English (Isle of Man)
16393            en-IN            English (India)
4096             en-IO            English (British Indian Ocean Territory)
4096             en-JE            English (Jersey)  
8201             en-JM            English (Jamaica)  
4096             en-KE            English (Kenya)  
4096             en-KI            English (Kiribati)
4096             en-KN            English (Saint Kitts and Nevis)
4096             en-KY            English (Cayman Islands)
4096             en-LC            English (Saint Lucia)
4096             en-LR            English (Liberia)
4096             en-LS            English (Lesotho)
4096             en-MG            English (Madagascar)
4096             en-MH            English (Marshall Islands)
4096             en-MO            English (Macao SAR)
4096             en-MP            English (Northern Mariana Islands)
4096             en-MS            English (Montserrat)
4096             en-MT            English (Malta)
4096             en-MU            English (Mauritius)
4096             en-MW            English (Malawi)
17417            en-MY            English (Malaysia)
4096             en-NA            English (Namibia)
4096             en-NF            English (Norfolk Island)
4096             en-NG            English (Nigeria)
4096             en-NL            English (Netherlands)
4096             en-NR            English (Nauru)   
4096             en-NU            English (Niue)
5129             en-NZ            English (New Zealand)
4096             en-PG            English (Papua New Guinea)
13321            en-PH            English (Republic of the Philippines)
4096             en-PK            English (Pakistan)
4096             en-PN            English (Pitcairn Islands)
4096             en-PR            English (Puerto Rico)
4096             en-PW            English (Palau)
4096             en-RW            English (Rwanda)
4096             en-SB            English (Solomon Islands)
4096             en-SC            English (Seychelles)
4096             en-SD            English (Sudan)   
4096             en-SE            English (Sweden)
18441            en-SG            English (Singapore)
4096             en-SH            English (St Helena, Ascension, Tristan da Cunha)
4096             en-SI            English (Slovenia)
4096             en-SL            English (Sierra Leone)
4096             en-SS            English (South Sudan)
4096             en-SX            English (Sint Maarten)
4096             en-SZ            English (Swaziland)
4096             en-TC            English (Turks and Caicos Islands)
4096             en-TK            English (Tokelau) 
4096             en-TO            English (Tonga)  
11273            en-TT            English (Trinidad and Tobago)
4096             en-TV            English (Tuvalu)  
4096             en-TZ            English (Tanzania)  
4096             en-UG            English (Uganda)        
4096             en-UM            English (US Minor Outlying Islands)
1033             en-US            English (United States)
4096             en-VC            English (Saint Vincent and the Grenadines)
4096             en-VG            English (British Virgin Islands)
4096             en-VI            English (US Virgin Islands)
4096             en-VU            English (Vanuatu)
4096             en-WS            English (Samoa)
7177             en-ZA            English (South Africa)
4096             en-ZM            English (Zambia)
12297            en-ZW            English (Zimbabwe)  
 

If your code eventually needs to check whether a given resource culture matches your interest, rather than comparing the resource culture to your UI culture, you may want to retrieve the *parent* cultures of both your UI culture and the resource and see if these match.

That way, British users (en-GB) will also find US documentation (en-us). Likewise, Swiss users (de-ch) would find German resources (de-de).


Tweet this Tip! Tweet this Tip!