dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

Add ConverterCulture property on Binding to allow overriding of culture settings #5696

Open jfversluis opened 2 years ago

jfversluis commented 2 years ago

Description

This proposal was originally done for Forms.

This new functionality would add the ConverterCulture property for bindings, which allows the consumer to override the locale for a binding. This functionality is also available in WPF.

Public API Changes

Added properties:

public class Binding
{
    // Default value would be `CurrentCulture` ideally or go to en-US.
    // The latter is what WPF does, although I'm not sure why, `CurrentCulture` makes more sense in my mind
    [System.ComponentModel.TypeConverter(typeof(CultureInfoIetfLanguageTagConverter))]
    public System.Globalization.CultureInfo ConverterCulture { get; set; }

    // Add an additional constructor to take the `ConverterCulture` parameter or create an overload for it

    // Existing Binding code here
}

I think we need to add our own type converter class because the one in WPF/WinUI lives in System.Windows which won't be ideal?

// TypeConverter to make sure we can convert values like en-US and nl-NL
// to a `CultureInfo` object through XAML.
// E.g.: <Label Text="{Binding MyText, ConverterCulture='nl-NL'} />"
public class CultureInfoIetfLanguageTagConverter
{
    // Code to transform string into `CultureInfo`
}

Intended Use-Case

I don't have a concrete example in mind. The proposal on the Forms repo has been upvoted a couple of times, I guess it can be useful in multi-language, multi-locale scenarios where you want to override something.

ghost commented 2 years ago

We've moved this issue to the Future milestone. This means that it is not going to be worked on for the coming release. We will reassess the issue following the current release and consider this item at that time.

jfversluis commented 2 years ago

@StephaneDelcroix curious for your thoughts on this? Useful or not?

StephaneDelcroix commented 2 years ago

@StephaneDelcroix curious for your thoughts on this? Useful or not?

useful, and not very hard