0

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:

  • fr -> Français
  • en -> Anglais
  • de -> Allemand

In German(de) culture

  • fr -> Français
  • en -> Anglais
  • de -> Allemand

...

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?

3
  • 5
    I don't believe the framework stores the name of each language in every other language - this is something you'd have to provide yourself along with other text for your site. May I also point out that if you're using this for a language selector, there's nothing worse than going to a site written in (say Arabic/Chinese/any non-Latin character set) and trying to guess which option is English Commented Sep 7, 2012 at 7:11
  • I'd agree with Basic and prefer the DisplayName or NativeName for making a list. Commented Sep 7, 2012 at 7:13
  • It works on my colleague laptop(which is installed in english too), but we don't know what is the difference between our computers. I can't use native name or display name(customer requirement). Commented Sep 7, 2012 at 9:24

1 Answer 1

1

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".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.