Why not all countries are presented in CultureInfo.GetCultures()?

前端 未结 3 751
南方客
南方客 2020-12-20 12:39

I am using this standard code for populating list of countries:

static void Main(string[] args)
{
    List cultureList = new List();

    CultureInfo[] cultu         


        
相关标签:
3条回答
  • 2020-12-20 13:11

    I would use CultureTypes.SpecificCultures but it does not answer your question.

    Why there is only subset of world's countries? Well, there are so many of them. Somebody would have to maintain them and it does cost money. I think that's why Microsoft decided to support only the most "popular" ones.

    BTW. You may create your own CultureInfo. Also, I haven't tried, but you can create RegionInfo instance by passing its ISO code in constructor. I am not sure what will happen if there is no matching CultureInfo, though.

    0 讨论(0)
  • 2020-12-20 13:31

    The answer is: By design

    CultureInfo.GetCultures is not designed to be a complete and definitive list of all the cultures in the world. It's only designed to get you the cultures that can be found on the computer.

    CultureInfo documentation says:

    Remember that the culture names and identifiers represent only a subset of cultures that can be found on a particular computer. Windows versions or service packs can change the available cultures. Applications add custom cultures using the CultureAndRegionInfoBuilder class. Users add their own custom cultures using the Microsoft Locale Builder tool. Microsoft Locale Builder is written in managed code using the CultureAndRegionInfoBuilder class.


    Notes

    Links on the MSDN that may be usefull:

    • Predefined RegionInfo list: http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo(VS.80).aspx
    • How to create custom Cultures: http://msdn.microsoft.com/en-us/library/ms172469(VS.80).aspx

    And by the way, you can shorten your code with a simple LINQ 'command':

    var regionInfos = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
      .Select(c => new RegionInfo(c.LCID))
      .Distinct()
      .ToList();
    
    0 讨论(0)
  • 2020-12-20 13:33

    You are not getting all cultures:

    CultureTypes.AllCultures & ~CultureTypes.NeutralCultures
    
    0 讨论(0)
提交回复
热议问题