Reputation: 20697
I've a website and I need to display some language name in the current culture, based of the two character language name.
E.g. I need to display when the culture is FRench:
In German(de) culture
...
The currentThread culture is already correct(meaning that I'm in "FR" localization).
The problem is that if I'm in the french culture and I do:
System.Globalization.CultureInfo.GetCultureInfo("de")
I receive this object:
Calendar: {System.Globalization.GregorianCalendar}
CompareInfo: {CompareInfo - de}
CultureTypes: NeutralCultures | InstalledWin32Cultures | FrameworkCultures
DateTimeFormat: {System.Globalization.DateTimeFormatInfo}
DisplayName: "German"
EnglishName: "German"
IetfLanguageTag: "de"
IsNeutralCulture: true
IsReadOnly: true
KeyboardLayoutId: 7
LCID: 7
Name: "de"
NativeName: "Deutsch"
NumberFormat: {System.Globalization.NumberFormatInfo}
OptionalCalendars: {System.Globalization.Calendar[1]}
Parent: {}
TextInfo: {TextInfo - de}
ThreeLetterISOLanguageName: "deu"
ThreeLetterWindowsLanguageName: "DEU"
TwoLetterISOLanguageName: "de"
UseUserOverride: false
And I wished that the display name is in the current locale(So "Allemand").
I'm sure it's possible, am I missing a language pack? At which level? Windows? ASP? MVC? Or should I use a different code?
Upvotes: 0
Views: 1627
Reputation: 15400
The .NET Framework does not provide what you are asking for (i.e. the name of a culture in an arbitrary language). The properties EnglishName
and NativeName
are self-explanatory. As for DisplayName
, this gives you the name of the culture in the language of your system (so if you're running the .NET Framework in French, you'll get "Allemand"--if you're running it in English, you'll get "German").
To clarify this last point, the .NET Framework itself has been localized into a number of languages, and you can get localized versions of the .NET Framework by downloading language packs (e.g. http://www.microsoft.com/en-us/download/details.aspx?id=3324 for .NET 4.0). If you do this then what DisplayName
gives you will depend both on your system's locale and on whether or not a language pack for the corresponding language is installed. In any case, I don't believe that you can rely on this for your scenario as you can't dynamically switch the system locale.
Update: I forgot to mention the solution in case it's not obvious: You can add your list of languages to your localizable resources alongside all your other user interface strings, i.e. include strings "French", "English" and "German" which for example your French translator will localize as "Français", "Anglais", "Allemand".
Upvotes: 1