Open D-Bullock opened 6 years ago
You mean like
<TextBlock Text="{wpf:GettextPlural 'Singular msgId', PluralMsgId = 'Plural msgId', N={Binding SomeNumericValue}}"/>
I didn't make that yet. If you do, please include an example in the example project, and if you are up for it some unit tests as well.
I think this is a great idea!
I have started on this, but don't have the ability to bind to the N parameter. Do you know how to accept a binding?
I can get <TextBlock Text="{wpf:GettextPlural '1 Example', '2 Examples', 1}" />
to work but not
<TextBlock Text="{wpf:GettextPlural '1 Example', '2 Examples', N={Binding PluralExampleCount}}"/>
I've pushed an initial version to my fork
Everyone I find seems to be saying to use a IValueConverter instead of a MarkupExtension. Can you currently bind to the params property?
Actually, one probably can't. The Binding markup extension probably just works in the visual tree and only on FrameworkElements having a DataContext. I think we might be out of luck here as we don't have a DataContext.
What we could do was to make Count an attached property:
<TextBlock Text="{wpf:GettextPlural '{0} Example', PluralMsgId='{0} Examples'}"
wpf:PluralGettext.N="{Binding PluralExampleCount}" />
Assuming the attached property N
is used as the first params.
But on another note: One cannot do everything in XAML, so if we can't find an elegant solution there is no harm in
<TextBlock Text="{Binding TranslatedText, ElementName=UserControl}"/>
...
public string TranslatedText =>
Translation.PluralGettext(
ViewModel?.PluralExampleCount,
"{0} example",
"{0} examples",
ViewModel?.PluralExampleCount)
In particular in WPF, C# is the domain specific code for stuff that has conditions and flow.
That which will work is
<TextBlock Text="{Binding PluralExampleCount,
Converter={wpf:GettextPlural {}{0} Example, PluralMsgId={}{0} Examples}}"/>
Hi,
Is there currently any support for gettext plural in xaml? I read through the source code and it doesn't seem to be mentioned in the existing extension. Before I go off and code it up, does it already exist and I just missed it?