Reputation: 168
I need to convert a country code to its adjectival equivalent. I am currently using RegionInfo which will get me the country name.
RegionInfo ri = new RegionInfo(languages[0]);
subtitle = ri.NativeName;
If the country code is 'en', this will give me England but what i want is 'English'.
So, how can I can get the country adjectival?
Thanks
Upvotes: 3
Views: 218
Reputation: 2356
There is no class in the standard .NET API that contains information about citizen-naming adjectives.
You can, however, use the CultureInfo
class to convert from a country code to a list of spoken languages - taking an arbitrary element from that list often gives the right answer (but not always, as in "Chinese (Simplified)")
For instance:
var cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures).Where(c => c.Name.EndsWith("CH"));
var cultureInfo = cultureInfos.SingleOrDefault();
string language = cultureInfo.EnglishName;
But I'm afraid the only option that will work correctly for all cultures is to create your own mapping.
Dictionary<string, string> adjectiveMap = new Dictionary<string, string>();
adjectiveMap.Add("en", "English");
adjectiveMap.Add("cn", "Chinese");
// etc. etc...
If you're prepared to take on this task, check out this wiki page! http://en.wikipedia.org/wiki/List_of_adjectival_and_demonymic_forms_for_countries_and_nations
Upvotes: 4
Reputation: 5684
Don't use RegionInfo
, better try to use CultureInfo
.
There you can try it like the following:
CultureInfo c = new CultureInfo(languages[0]);
subtitle = c.DisplayName;
Upvotes: 1