G.Dealmeida
G.Dealmeida

Reputation: 335

CultureInfo : display the language with its own culture

The title may not be very clear but what I want to do is really simple: I want to display a list of culture by their names like this:

Upvotes: 0

Views: 978

Answers (3)

vahdet
vahdet

Reputation: 6749

See CultureInfo.NativeName:

CultureInfo myCultureInfo = new CultureInfo("es", false);
Console.Write(myCultureInfo.NativeName);

EDIT: changed DisplayName method to NativeName as I realized the OP asked for it.

Upvotes: 1

Fuzzybear
Fuzzybear

Reputation: 1418

The below little code snippet will get all the available culture and print it in tabular format. The output of the code is given below,

protected void Page_Load(object sender, EventArgs e)

    {

        CultureInfo[] cinfo = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);

        Response.Write("<table border=\"1\"><tr><th>Country Name</th><th>Language-Country code</th></tr>");

        foreach (CultureInfo cul in cinfo)

        {

            Response.Write("<tr>");

            Response.Write("<td>" + cul.DisplayName + " </td><td> " + cul.Name + "</td>");

            Response.Write("</tr>");

        }

        Response.Write("</table>");

    }

Upvotes: 0

Stevo
Stevo

Reputation: 1444

This will display the name in the required (native) language:

Console.WriteLine(System.Globalization.CultureInfo.GetCultureInfo("en").NativeName);
Console.WriteLine(System.Globalization.CultureInfo.GetCultureInfo("de").NativeName);
Console.WriteLine(System.Globalization.CultureInfo.GetCultureInfo("fr").NativeName);

Upvotes: 4

Related Questions