Last post Dec 17, 2008 07:42 AM by retroviz
Dec 17, 2008 07:14 AM|enriquevald|LINK
I'm using the code: CultureInfo.CurrentUICulture.DisplayName for get the language name but I get the combination "language + (country)", for example "English (United States)".
How can I get only the language name : "English"?
Dec 17, 2008 07:42 AM|retroviz|LINK
This is because the the CurrentUICulture displays the specific culture e.g. "en-US" (English in United States), "en-GB" (English in Great Britain) or "fr-FR" (French in France).
To retrieve just the language you need to get the neutral culture. One method is just to retrieve the first two letters from the specific culture that represent the neutral culture. The following code would do what you want:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lang As String = Left(CultureInfo.CurrentUICulture.Name, 2)
Dim ci As CultureInfo = CultureInfo.GetCultureInfo(lang)
Hope that helps,