Customising Pluralisation in Caliburn.Micro
20 Jan 2017 by Nigel SampsonCaliburn.Micro uses pluralisation in it’s conventions. It’s what turns an x:Name
of Products
into bindings of the Products
and SelectedProduct
properties.
To be more accurate Caliburn.Micro uses Singularisation, and it’s implementation is rather naive that certainly don’t cope with the variety the english language provides, let alone other languages.
It’s current implementation is:
public static Func<string, string> Singularize = original =>
{
return original.EndsWith("ies")
? original.TrimEnd('s').TrimEnd('e').TrimEnd('i') + "y"
: original.TrimEnd('s');
};
There are however some fanstasic libraries out there to deal with manipulating language in this way, and Caliburn.Micro can be updated to use them. I’m talking in particular about the library Humanizer.
Having the following in our application configure code switches the framework to use Humanizer for it’s conventions and be able to deal with all the property names it couldn’t deal with before.
ConventionManager.Singularize = original => original.Singularize(inputIsKnownToBePlural: false);