How to force culture / region to RegionInfo.DisplayName

I am showing the country as part of some other information. The country is read from the database as a country code.

This is done as follows:

Location location = new Location()
{                                
    Company = reader.GetString("Company"),
    Address1 = reader.GetString("Address"),
    Address2 = reader.GetString("Address2", string.Empty),
    ZipCity = reader.GetString("ZipCity"),
    Country = new RegionInfo(reader.GetString("Country", string.Empty)).DisplayName,
    CountryCode = new RegionInfo(reader.GetString("Country", string.Empty)).TwoLetterISORegionName,
    Att = reader.GetString("Att", string.Empty),
    Phone = reader.GetString("Phone", string.Empty)
};

      

My problem is that I really would like to force the display name to be in Danish. Keep in mind that now the country will always be denmark, so using your own name is not an option.

Thank you in advance

0


source to share


3 answers


So, after checking the possibility of installing the language pack for the .NET Framework, which for some reason we failed, we found the following solution.

Add this line to your web.config in the system.web node file.



<globalization enableClientBasedCulture="false" culture="da-DK" uiCulture="da"/>

      

If an OS language pack is installed on the computer that is running your software, it will be forced to be translated to that language.

+1


source


From MSDN :

The DisplayName property displays the country / region name in the language of the localized version of the .NET Framework . For example, the DisplayName property displays a country / region in English to the English version of the .NET Framework and in Spanish to the Spanish language version of the .NET Framework.



So, if you install the Danish version of .NET it works the way you want it to.

However, it might be better not to depend on this and just create your own table of Danish country names.

+1


source


You can solve this by writing this line before you initiate RegionInfo:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("da-DK");

      

0


source







All Articles