问题
I've opened mscorlib in ILSpy and I see in resources folder:
Name, Value
[Format_InvalidString, Input string was not in a correct format.]
Is there any way to localize this string?
(Context: silverlight app throws this message whenever incorrect number is entered and it would be much easier to just change this than to write converter and apply it in hundreds of places).
回答1:
Silverlight is localized with satellite assemblies. You can see those in your Silverlight install location. On my machine, I've got Silverlight 5 installed in C:\Program Files (x86)\Microsoft Silverlight\5.1.20125.0 Adjust the version number if necessary on yours.
Note the many subdirectories with 2 letter names, "ar" is the one for Arabic for example. Look in that directory, note the mscorlib.resources.dll file there. That's the satellite assembly that contains the localized strings, including the exception message strings. Arabic strings in that specific directory.
And will automatically be displayed on a machine whose user has selected Arabic as his preferred language. You don't have to help.
回答2:
The only solution that works is this:
public partial class MyEntity
{
public string MyField_string
{
get
{
return MyField.ToString();
}
set
{
decimal res = 0;
var b = Decimal.TryParse(value, out res);
if (!b)
throw new ArgumentException("Localized message");
else
this.MyField = Math.Round(res, 2);
}
}
partial void OnMyFieldChanged()
{
RaisePropertyChanged("MyField_string");
}
}
And then bind to MyField_string
instead of MyField
.
来源:https://stackoverflow.com/questions/16416658/localize-mscorlib-dll-resources