List the defined locales in C#

locales


This example is fairly straightforward. When the form loads, the following event handler lists the defined locales.

private void Form1_Load(object sender, EventArgs e)
{
    // Make the ListBox use tabs.
    lstLocales.UseTabStops = true;
    lstLocales.UseCustomTabOffsets = true;

    // Define the tabs.
    ListBox.IntegerCollection offsets =
        lstLocales.CustomTabOffsets;
    offsets.Add(100);

    // Add the locale information.
    foreach (CultureInfo info in
        CultureInfo.GetCultures(CultureTypes.AllCultures))
    {
        lstLocales.Items.Add(
            info.EnglishName + '\t' +
            info.NativeName);
    }

    // Display the number of locales.
    lblNumLocales.Text = lstLocales.Items.Count.ToString() +
        " locales";
}

The code prepares the ListBox to use tab stops. It then loops through the CultureInfo objects returned by CultureInfo.GetCultures(CultureTypes.AllCultures). For each CultureInfo object, the program adds the object’s English and native names separated by a tab to the ListBox. It finishes by displaying the number of locales.


Download Example   Follow me on Twitter   RSS feed




This entry was posted in internationalization, system and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *