LocalizationResourceManager.Maui
LocalizationResourceManager.Maui copied to clipboard
SetTranslate extension method
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));