0

I have an Xamarin.Forms app that supports both English and French. How do I show the Calender (Month, Day of the Week text) for the DatePicker in French locale? Imgur

I've tried Xamarin.Forms

    public void SetLocale(CultureInfo ci)
    {
        Thread.CurrentThread.CurrentCulture = ci;
        Thread.CurrentThread.CurrentUICulture = ci;
        Console.WriteLine("CurrentCulture set: " + ci.Name);
    }

I've tried changing the context before creating the datepicker dialog in my DatePicker custom renderer

        var config = new Android.Content.Res.Configuration { Locale = Locale.CanadaFrench };
        Context.Resources.UpdateConfiguration(config, Context.Resources.DisplayMetrics);

        _dialog = new DatePickerDialog(Context, (o, e) =>
        {
            view.Date = e.Date;
            ((IElementController)view).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false);
        }, year, month, day);

I also tried this in my DatePicker custom renderer protected override void

OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.DatePicker> e)
        {
            base.OnElementChanged(e);
            this.Control.TextLocale = Locale.CanadaFrench;
        }

None of these did anything to change the locale.

I also found this post that seems have done changing the calendar view to a different locale Set Android DatePicker title language But it wasn't clear how it was accomplished.

Dylan Liu
  • 123
  • 1
  • 7
  • generally the user changes locale via the device's settings, not on an app-by-app basis – Jason Apr 24 '19 at 17:10

2 Answers2

1

It turns out you have to add French as a language in the settings in order to show stuff in French.

Settings->General Management -> Language and Input->LanguageLanguage Settings

And you just need these two lines in your DatePicker android Custom renderers to make the calendar French

this.Control.TextLocale = locale;
Resources.Configuration.SetLocale(locale);

If you title still remains in English, reference this post Set Android DatePicker title language

Dylan Liu
  • 123
  • 1
  • 7
0
Locale locale = new Locale("fr"); 
Control.TextLocale = locale; 
Android.Content.Res.Configuration config = new Android.Content.Res.Configuration(); 
config.Locale = locale;
Locale.SetDefault(Locale.Category.Format, locale);
Resources.Configuration.SetLocale(locale);
Resources.Configuration.Locale = locale;
patrick.elmquist
  • 2,113
  • 2
  • 21
  • 35