Thursday, September 4, 2014

There's one specific culture whose parent culture is not neutral

using System;
using System.Globalization;
using System.Linq;

public class SamplesCultureInfo
{

   public static void Main()
   {

      // Prints the header.
    Console.WriteLine("  {0} {1, 80}","SPECIFIC CULTURE", "PARENT CULTURE");
    
    
    Action<CultureTypes, Func<CultureInfo, bool>> display = (c, exp) => 
    {
        foreach (CultureInfo ci in CultureInfo.GetCultures(c).Where(exp).OrderBy(x => x.TwoLetterISOLanguageName))
        {
            Console.Write("0x{0} {1} {2, -70}", ci.LCID.ToString("X4"), ci.Name, ci.EnglishName);
            Console.WriteLine("0x{0} {1} {2} : {3}", ci.Parent.LCID.ToString("X4"), ci.Parent.Name, ci.Parent.EnglishName, ci.Parent.IsNeutralCulture);     
        }
    };
    
    Action<CultureTypes> displayAll = c => display(c, x => true);
    
    // displayAll(CultureTypes.SpecificCultures);
    // displayAll(CultureTypes.NeutralCultures);
    
    //// Only one specific culture which parent culture is not neutral:
    // CultureInfo.GetCultures(CultureTypes.SpecificCultures).All(x => x.Parent.IsNeutralCulture).Dump();        
    // CultureInfo.GetCultures(CultureTypes.SpecificCultures).Count(x => !x.Parent.IsNeutralCulture).Dump();
    //// This is that culture:        
    display(CultureTypes.SpecificCultures, x => !x.Parent.IsNeutralCulture);
    
    
        
    
    // CultureInfo.GetCultures(CultureTypes.NeutralCultures).Count().Dump();

   }

}

Live codes:
https://dotnetfiddle.net/PCq4vR
https://dotnetfiddle.net/17Bkny

Output:
SPECIFIC CULTURE                                                                    PARENT CULTURE
0x0803 ca-ES-valencia Valencian (Spain)                                             0x0403 ca-ES Catalan (Catalan) : False


Interesting: http://stackoverflow.com/questions/8354352/how-can-i-get-the-region-and-culture-info-for-bahamas

No comments:

Post a Comment