Question

I wish to force danish culture in my web application, but I can not get it work. I am trying to populate a dropdown list with danish country names, but they return in english.

public static IEnumerable<SelectListItem> GetCountries(string selectedDisplayName)
{
    var countryNames = new List<SelectListItem>();
    foreach (var cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
    {
        var country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);
        var item = new SelectListItem()
        {
            Text = country.DisplayName,
            Value = country.DisplayName
        };
        if (!String.IsNullOrEmpty(selectedDisplayName) && country.DisplayName.Equals(selectedDisplayName))
        {
            item.Selected = true;
        }
        countryNames.Add(item);
    }
    IEnumerable<SelectListItem> nameAdded = countryNames.GroupBy(x => x.Text).Select(x => x.FirstOrDefault()).ToList().OrderBy(x => x.Text);
    return nameAdded;
}

My web.config has this (with no effect):

<system.web>
    <globalization uiCulture="da-DK" culture="da-DK" />
</system.web>

Anyone got any suggestions?

Was it helpful?

Solution

According to MSDN ( http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.displayname(v=vs.110).aspx ), RegionInfo.DisplayName will use the language of the installed version of .NET, which invariably is the same as the language of your Windows installation.

Instead, use RegionInfo.NativeName ( http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.nativename(v=vs.110).aspx ) which is always the local name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top