There is any way to convert a boolean value to a localized string. I have tried:
var x = true;
var culture = new CultureInfo("en-US")
x.ToString(culture) // returns True
culture = new CultureInfo("pt-BR")
x.ToString(culture) // returns True, expected Verdadeiro
Or should I start typing the switch now to end before 2020?
Well, start typing because it's documented behaviour :)
Boolean.ToString(IFormatProvider)
Remarks
The provider parameter is reserved. It does not participate in the execution of this method. This means that the Boolean.ToString(IFormatProvider) method, unlike most methods with a provider parameter, does not reflect culture-specific settings.
As @Michal pointed out, this is the documented behavior.
If your system supports many languages, you must have some sort of i18 support. Use that to convert a boolean value to string. You can add an extension method like so:
public string ToLocalizedString(this bool b)
{
return ...i18n version of true or false...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With