Search code examples
c#.net.net-4.0globalizationculture

DateTime supported language for formatting?


DateTime let you format depending of the current culture. What are the culture supported by default?

The scenario I have in mind use this.Date.Value.ToString("MMMM") which will print "January" if the culture is set to english-us but will print "Janvier" if the culture is in french-ca. This formatting documentation can be found at MSDN website but doesn't give the scope of culture this one can translate.

I would like to know what languages are supported and if a language is not, what are my options?


Solution

  • You can use CultureInfo.GetCultures to get all supported cultures.

    CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
    string allTranslatedJanuaries = 
        string.Join(Environment.NewLine, cultures.Select(c =>
            String.Format("{0}: {1}", c.EnglishName, c.DateTimeFormat.GetMonthName(1))));
    

    Here's a demo: http://ideone.com/9CUjK

    On my server 352 cultures are installed, upon ideone only 112.