displaying country name in current UI culture?

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

I have a two-letter country code and I need to display the name of this
country in the current UI culture.

Sadly I can't create a CultureInfo and use the DisplayName property
because this displays it in the localised version of the .NET framework
and not in the current UI culture which I might have changed (it is
calculated regardless of the language that the system is set to
display).

e.g:
country code: US
current ui culture: Spanish:
test string i need: "Estados Unidos"

Any suggestions?
 
From: "Rich" <[email protected]>
| I have a two-letter country code and I need to display the name of this
| country in the current UI culture.
|
| Sadly I can't create a CultureInfo and use the DisplayName property
| because this displays it in the localised version of the .NET framework
| and not in the current UI culture which I might have changed (it is
| calculated regardless of the language that the system is set to
| display).

CultureInfo.NativeName is in the language of that culture. So if you're
looking for the native name of the current UI culture, use that.
CultureInfo.DisplayName is (as you found) based on the language of the .NET
framework.
CultureInfo.EnglishName is always the English name for the culture.

If you want to display the name of a culture in some other language (e.g.,
Framework is English, current UI is Spanish, and you want the name of
German culture in Spanish), I'm not sure how to get that.

Katy
 
Hi,
If you want to display the name of a culture in some
other language (e.g., Framework is English, current UI
is Spanish, and you want the name of German culture in
Spanish), I'm not sure how to get that.

Thanks for replying - that's exactly what I want! Anybody else have any
suggestions?

cheers,
rich
 
Rich Urwin said:
Hi,


Thanks for replying - that's exactly what I want! Anybody else have any
suggestions?

I would suggest asking in microsoft.public.dotnet.internationalization

:)
 
How about the same way the CultureInfo class does it? e.g.:

public string GetLocalizedName(CultureInfo targetCulture, CultureInfo
languageCulture)
{
ResourceManager manager = new ResourceManager("mscorlib",
typeof(string).Assembly);
return manager.GetString("Globalization.ci_" + targetCulture.Name,
languageCulture);
}

One important detail is that the mscorlib resources file for the specified
language must be installed on the machine. If not, the usual
ResourceManager language fallback rules will be applied. In other words,
it's probably pretty useless even if all available language packs have been
installed (which is extremely unlikely).
 
Back
Top