Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

CultureInfo.DisplayName not localized

$
0
0

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


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>