Marc Gravell a pensé très fort :
> Oops - one minor bug; you don't need to override GetStandardValues,
> since this is meant to return the *typed* values (i.e. true/false, not
[quoted text clipped - 4 lines]
>
> Marc
Thanks a lot, it work very well ...
Just 2 questions :
public MyBooleanConverter()
{
trueVal = "vrai";
falseVal = "faux";
}
Is it in this place that I need to localize trueval and falseval in
function of culture ?
and in :
public override string DisplayName
{
get
{
// TODO: localize the display name
return "Cultured " + base.DisplayName;
}
}
Is it for the CategoryAttribute ?
I have tried to modify base.DisplayName but it is read-only.
Marc Gravell - 14 Mar 2008 21:49 GMT
> Is it in this place that I need to localize trueval and falseval in
> function of culture ?
Actually, no. The "right" place depends on the app. In the more
complex case, if you need to support multiple cultures *at the same
time* then the correct approach would be to use the culture passed
into ConvertTo/ConvertFrom. However, if you only need to support a
single culture (typical for a windows client), then I would use some
static fields:
(this example uses resx file)
// public ctor (required to work)
public MyBooleanConverter() { }
// private static true/false values
private static readonly string trueVal, falseVal;
static MyBooleanConverter()
{
trueVal =
WindowsFormsApplication1.Properties.Resources.TrueText;
falseVal =
WindowsFormsApplication1.Properties.Resources.FalseText;
}
> Is it for the CategoryAttribute ?
The one I posted (DisplayName) controls the name that appears for the
property. Category is done slightly differently:
(this example just shows simple case - but you can generalise using
Properties.Resources.ResourceManager.GetString(whatever))
class MyCategoryAttribute : CategoryAttribute
{
public MyCategoryAttribute(string category) : base(category) { }
protected override string GetLocalizedString(string value)
{
return "Translated";
}
}
If you return null from GetLocalizedString() then it uses the original
text as a default. If you return an empty string ("") it dispays
"Misc".
J-L - 17 Mar 2008 11:42 GMT
thanks a lot more ...
Yes, ma soft need to change of culture if the user want it.
An option for that is in a settings panel , and the user restart the
application to get new language in interface.