We are about to start externalizing all the strings in our product, to prepare to translate it into French. Are there any FxCop rules that can find string literals and remind us to externalize them
Thanks,
Josh Yeager
We are about to start externalizing all the strings in our product, to prepare to translate it into French. Are there any FxCop rules that can find string literals and remind us to externalize them
Thanks,
Josh Yeager
FxCop Rules to catch non-externalized strings?
antonio97b
Josh, I had a closer look at CA1303 and it turns out it will only flag properties with the name "Text", "Caption", or "Message".
FxCop seems to do nothing special if you mark a property with LocalizableAttribute = true, unfortunately. For example:
private string text;
[Localizable(true)]
public String Something
{
set
{
text = value;
}
get
{
return "";
}
}
//...
obj.Something = "text";// no warning
But, this causes a warning:
string text;
public String Message
{
set
{
text = value;
}
get
{
return "";
}
}
// ...
obj.Message = "text"; // warning
David, Michael; should properties flagged with LocalizableAttribute = true raise a CA1303 in this case
MARL
Peter,
I thought that we did respect the LocalizableAttribute, however, after further investigation I found that we only respect it when it is applied to the actual parameter.
So in example in the above, FxCop would respect it if you changed it to the following:
public String Something
{
[param: Localizable(true)]
set
{
text = value;
}
get
{
return "";
}
}
This is obviously not ideal. As it turns out, this is one of the rules that will get rewritten after our new data flow analysis work has been finished, so I will add your example to our test cases.
sandPR
There are a couple of ways FxCop currently determines if a parameter is localizable.
- The name of the parameter or property. As you found, parameters named text, caption or message are automatically considered localizable as well as properties named Text, Caption and Message.
- It respects the LocalizableAttribute, so if a parameter is marked Localizable(true) then it considered localization, and vice versa.
In your property example above, the parameter name is value and the property name is Something so it is not considered localizable. The name of the backing store (in this case the field 'text') is not considered.
JayKay
Ray Price
public void SomethingElse(string somethingMore)
Alex Jimenez
j_jst
jwdenny
Thanks David. At least there's a way to get FxCop to do what was queried. I was viewing it as a property thing; not a parameter thing.
Method parameters seem to automatically be assumed to have Localizable(true) despite the documentation for LocalizableAttribute saying the default is false. e.g.:
string text;
string Something
{
set
{
text = value;
}
}
public void SomethingElse(string text)
{
//...
}
// ...
Something = "ha"; // no error/warning
SomethingElse("ha ha"); // CA1303 error