LocalizationResourceManager.Maui icon indicating copy to clipboard operation
LocalizationResourceManager.Maui copied to clipboard

SetTranslate extension method

Open stephenquan opened this issue 1 year ago • 0 comments

Introduce new SetTranslate extension method so that we can use Translate from C# code-behind.

bindable.SetTranslate(targetProperty, text, args...)

Examples:

// count as constant arguments
if (count == 0)
    CounterBtn.SetTranslate(Button.TextProperty, "ClickMe");
else if (count == 1)
    CounterBtn.SetTranslate(Button.TextProperty, "ClickedOneTime", count);
else
    CounterBtn.SetTranslate(Button.TextProperty, "ClickedManyTimes", count);

// count as a binding
CounterBtn.SetTranslate(Button.TextProperty, "ClickedManyTimes", new Binding(nameof(Count), source: this));

// string resource as a binding, where ClickText can be "ClickedMe", "ClickedOneTime" or "ClickedManyTimes"
CounterBtn.SetTranslate(Button.TextProperty, new Binding(nameof(ClickText), source: this), new Binding(nameof(Count), source: this));

stephenquan avatar Oct 21 '24 11:10 stephenquan