0

The question is, how can I translate system validation/binding errors to other languages? The details are as follow: I got this wpf application, which will be multilingual, and, for instance, has a grid bind to a collection of items, and one of the columns, DataLancamentoEdicao in the example below, is a bound to a DateTime:

<DataGridTextColumn Header="Data" Binding="{Binding SomeDateTime, ValidatesOnDataErrors=True, Mode=TwoWay, StringFormat=d}" />

And the class is

public class SomeClass: INotifyPropertyChanged 
{ 
   public DateTime SomeDateTime {get {/*...*/}; set {/*...*/}}
}

If the users enters a valid date all is ok, but if the user enter, by mistake some garbage like "blablabla" the wpf reports, as expected, "Value 'blablabla' could not be converted", in some cases it reports String was not recognized as a valid DateTime. This DateTime is an example since there are others binding with decimals, integers that also suffer the same issue.

Text Message

These are obviously good for an english person, but I need them to be translated to Portuguese as well as other languages available to the user on the login screen.

I've already set the culture of the thread and the language of the wpf as followed

        Thread.CurrentThread.CurrentCulture = UserChoosenCulture;
        Thread.CurrentThread.CurrentUICulture = UserChoosenCulture;
        FrameworkElement.LanguageProperty.OverrideMetadata(
            typeof(FrameworkElement),
            new FrameworkPropertyMetadata(System.Windows.Markup.XmlLanguage.GetLanguage(UserChoosenCulture.IetfLanguageTag)));

How can I translate these strings? Are there some resources that I can override to achieve this goal?

Thank you.

saamorim
  • 3,855
  • 17
  • 22

1 Answers1

0

<OPINION>Foremost, you should not rely on exceptions as error reports to the end-user. Exceptions are for yourself as a programmer.</OPINION>

A guaranteed method would be to write your own converter or validationRule (however much control you want to have), catch the exceptions yourself, and output your own translated messages.

Validation shouldn't throw an exception. I'm not sure how you have this reaching the user. I just get a red border when I implement validation.

EDIT: From what I've read, it appears that they can be translated. My concerns are whether you have that language pack installed. etc.

Lee Louviere
  • 5,162
  • 30
  • 54
  • That seems over killing and prone to errors. Rewriting what Microsoft did just for the sake of messaging translation. Certainly Microsoft doesn't have specific versions of the converter for each language and I believe it should have some kind of satellite assemblies or resource string management, just can't find the right solution. – saamorim Jul 10 '13 at 17:41
  • @saamorim You missed my point. Exceptions are for diagnostics. They are not for end-user display errors. Besides, how useful is "Couldn't convert value" as opposed to "Not a valid date." Besides, what if you wanted to have a valid date range? You implement your own validate. If you just want a red ring with no indication to the user for why, you use the default validation. Not to mention, I have no idea how your validation exceptions are bubbling up to the user. They don't show for me (other than the output window while debugging). – Lee Louviere Jul 10 '13 at 17:44
  • @saamorim Also, you don't have specific versions of the converter/validator for each language. You "outsource" your translation to external resources. There are a number of ways to handle dynamic translation using XMLs, Resource Dictionaries, etc. – Lee Louviere Jul 10 '13 at 17:48
  • thx. I expect using specific validation when they have in fact specific behaviors. This is not the case, they have the expected behavior just a different message. About your second message, that is exactly my point. How did Microsoft externalized their messages in this case? – saamorim Jul 10 '13 at 17:58
  • @saamorim They are supposed to be translated. Are you sure you have the language pack installed? I'm just of the opinion that exceptions aren't end user friendly. I talked with my colleague and he disagrees. I still hold my opinion, but there are cases that make sense ("File Not Found", etc.) – Lee Louviere Jul 10 '13 at 18:34
  • Although not completely satisfied the language pack did in fact solved my issue. Thanks for the point. – saamorim Jul 11 '13 at 18:31