WP7: How to Localize you DatePicker


  1. Create your DatePicker application described in this article or your own application.
  2. Insert in MainPage.xaml.cs
    using System.Globalization;
    using System.Threading;
    
  3. Windows Phone supports the display languages you may find here
  4. Next code fragment do all you need (of course you must choose "Culture code" you need):
    public MainPage()
    {
        CultureInfo newCulture = new CultureInfo("en-GB");
        Thread.CurrentThread.CurrentCulture = newCulture;
        Thread.CurrentThread.CurrentUICulture = newCulture;
    
        ...
    }
    
  5. But if your language not supported by windows phone?
    public MainPage()
    {
        CultureInfo newCulture = new CultureInfo("en-GB");
    
        //change format of DatePicker to you own format
        newCulture.DateTimeFormat.ShortDatePattern = "d/MMM/yyyy";
    
        //set day names
        newCulture.DateTimeFormat.DayNames = new string[] { "first day", 
                                                            "second day", 
                                                            "third day", 
                                                            "4 day", 
                                                            "5 day", 
                                                            "6 day", 
                                                            "7 day" };
    
        //set month names
        newCulture.DateTimeFormat.MonthNames = new string[] {"1 month", 
                                                             "2 month", 
                                                             "3 month", 
                                                             "4 month", 
                                                             "5 month", 
                                                             "6 month", 
                                                             "7 month", 
                                                             "8 month", 
                                                             "9 month", 
                                                             "10 month", 
                                                             "11 month", 
                                                             "12 month", 
                                                             ""};
    
        Thread.CurrentThread.CurrentCulture = newCulture;
        Thread.CurrentThread.CurrentUICulture = newCulture;
    
        ...
    }
    
  6. Enjoy

1 comment: