Pregunta

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.

¿Fue útil?

Solución

<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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top