How to implement localization of a Wpf application using the MVVM template?

I am working on a wpf application using the Devexpress Tool and following the MVVM pattern.

I applied localization on it using the Locbaml Tool and it works fine, but only for presentation.

In this application, I install Grid Row Vlidation errors, as well as Popping some MessageBoxes from the View Model, but LocBaml does not look useful for converting these error messages and messages to other languages. How can i do this?

+4
source share
5 answers

LocBaml only extracts material from baml, which is a compiled form of your xaml files. Everything that is not defined in xaml (for example, lines defined in the code) will never be visible. The only way I know is to define all the strings you might want to localize as string resources in xaml. They can be easily referenced from code, so it's not as bad as it seems. Strings that are fully dynamically generated will not be localizable, but with some work you can build them from fragments defined in your xaml resources.

+1
source

It is wrong to have message boxes directly from the ViewModel. Instead, you should raise events and view the view in the user interface. Otherwise, you could not unit test ViewModel and one of the main goals of the MVVM template.

0
source

If you use .resx files to manage translations, you can simply force them to generate code (using the access modifier: public in the list box on the .resx screen), and then force the virtual machine to send messages directly to the view.

Thus, the basic functionality of the resource files generated by the code will return the translated version of the desired text.

0
source

http://blogs.microsoft.co.il/blogs/tomershamam/archive/2007/10/30/wpf-localization-on-the-fly-language-selection.aspx check this. You can send localized text from a virtual machine by calling the translation method from the code. for instance

LanguageDictionary.Current.Translate ("resourceKey", "value Name")

0
source

You can take a look at some software that I wrote for this:

http://tap-source.com/?p=232

Hope this helps.

0
source

All Articles