Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of locales in .Net

Tags:

c#

.net

locale

I would like to give user option to select text file locale.

Is there some class in .net that keeps list of available locales?

Now, I am planning to make my own list class from MSDN page: Language Identifier Constants and Strings, but it would be nicer if there is something already in .net.

Here is MSDN article on CultureInfo.GetCultures method that Jeremy wrote in his answer. There are also code examples.

like image 490
zendar Avatar asked Feb 14 '10 09:02

zendar


2 Answers

You'd want like a 'for each locale loop'.

    Dim info As CultureInfo
    For Each info In CultureInfo.GetCultures(CultureTypes.AllCultures)

        ListBox1.Items.Add(info.EnglishName)
    Next

Takes like half a second to dump a list of locales into the Listbox1

Then you can reference 'info' in various ways such as:

    info.NumberFormat
    info.DateTimeFormat

Get todays date in that locales date:

        If Not info.IsNeutralCulture Then
            Dim dateNow As DateTime = DateTime.Now
            ListBox1.Items.Add(dateNow.ToString("d", info.DateTimeFormat).ToString)
        End If
like image 65
Jeremy Child Avatar answered Oct 23 '22 23:10

Jeremy Child


check out everything around the System.Globalization.CultureInfo class. you'll probably find there what you are looking for

like image 43
Joachim Kerschbaumer Avatar answered Oct 23 '22 21:10

Joachim Kerschbaumer