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.

4

1 回答 1

0

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

一个有保证的方法是编写您自己的转换器或验证规则(无论您想拥有多少控制权),自己捕获异常,并输出您自己的翻译消息。

验证不应该抛出异常。我不确定您是如何将其传达给用户的。当我实施验证时,我只是得到一个红色边框。

编辑:从我读过的内容来看,它们似乎可以翻译。我担心的是您是否安装了该语言包。等等

于 2013-07-10T17:28:07.523 回答