none
CultureInfo.DisplayName not localized RRS feed

  • Question

  • Hello everybody,

    currently I'm working with the CultureInfo class. I want to use the DisplayName property to show the localized name of a language with respect to the choosen UI-language.

    The MSDN-Library description says that this property provides the full localized name. But it seems that this doesn't work.

    You can test it with the following simple code:

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
                List<int> lcids = new List<int>() { 1031,1033,1044};
                foreach(int lcid in lcids)
                {
                    CultureInfo culture = CultureInfo.GetCultureInfo(lcid);
                    System.Threading.Thread.CurrentThread.CurrentCulture = culture;
                    System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
                    
                    Console.WriteLine(String.Format("set lang: {0} --- active lang: {1}", culture.Name, CultureInfo.CurrentCulture.Name));
                    foreach (int lcid1 in lcids)
                    {
                        CultureInfo culture1 = CultureInfo.GetCultureInfo(lcid1);
    
                        Console.WriteLine(String.Format("     {0} \t  {1} \t  {2}", culture1.Name, culture1.DisplayName, culture1.NativeName));
    
                    }
                }
                Console.WriteLine("Press any key to close...");
                Console.ReadKey();
            }
        }
    }
    

    The corresponding output is the following:

    set lang: de-DE --- active lang: de-DE
         de-DE        Deutsch (Deutschland)           Deutsch (Deutschland)
         en-US        Englisch (USA)          English (United States)
         nb-NO        Norwegisch, Bokmål (Norwegen)           norsk, bokmål (Norge)
    set lang: en-US --- active lang: en-US
         de-DE        Deutsch (Deutschland)           Deutsch (Deutschland)
         en-US        Englisch (USA)          English (United States)
         nb-NO        Norwegisch, Bokmål (Norwegen)           norsk, bokmål (Norge)
    set lang: nb-NO --- active lang: nb-NO
         de-DE        Deutsch (Deutschland)           Deutsch (Deutschland)
         en-US        Englisch (USA)          English (United States)
         nb-NO        Norwegisch, Bokmål (Norwegen)           norsk, bokmål (Norge)
    Press any key to close...

    Is this realy the expected behaviour?

    Regards

    Volker

    Monday, October 20, 2014 1:52 PM

Answers

  • By “localized” it probably means the translated variants of .NET Framework. For example, here you can download the preferred localisations: http://www.microsoft.com/en-us/download/details.aspx?id=30667.


    Monday, October 20, 2014 6:16 PM
  • Yes, the CultureInfo.DisplayName property returns the name of the culture in the in the installed .NET language. If you want the native name, you should use the NativeName property:

    CultureInfo culture = CultureInfo.GetCultureInfo("sv-SE");
                System.Threading.Thread.CurrentThread.CurrentCulture = culture;
                System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
    
    
                string displayName = culture.DisplayName;
                string nativeName = culture.NativeName;
                string engName = culture.EnglishName;


    Please remember to mark helpful posts as answer and/or helpful.
    Monday, October 20, 2014 9:48 PM

All replies

  • By “localized” it probably means the translated variants of .NET Framework. For example, here you can download the preferred localisations: http://www.microsoft.com/en-us/download/details.aspx?id=30667.


    Monday, October 20, 2014 6:16 PM
  • Yes, the CultureInfo.DisplayName property returns the name of the culture in the in the installed .NET language. If you want the native name, you should use the NativeName property:

    CultureInfo culture = CultureInfo.GetCultureInfo("sv-SE");
                System.Threading.Thread.CurrentThread.CurrentCulture = culture;
                System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
    
    
                string displayName = culture.DisplayName;
                string nativeName = culture.NativeName;
                string engName = culture.EnglishName;


    Please remember to mark helpful posts as answer and/or helpful.
    Monday, October 20, 2014 9:48 PM
  • Okay, thanks!

    I thought the Display Name property indicates the translation of the language name in the language currently set in CurrentCulture ...

    Tuesday, October 21, 2014 7:54 AM