문제

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...
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top