Syeda
Syeda

Reputation: 1205

How should I Implement Localization on Wpf Application using MVVM pattern?

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

I have applied Localization on it using Locbaml Tool and it is working perfectly fine but just for the View.

In this app i am setting Grid Row Vlidation errors and also Popping some MessageBoxes from View Model but LocBaml is not looking helpful for converting these error messages and message boxes message in other languages. How can I accomplish this?

Upvotes: 4

Views: 1244

Answers (5)

The Angry Programmer
The Angry Programmer

Reputation: 131

You can take a look at some software I wrote to do this:

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

Hope this helps.

Upvotes: 0

phoff
phoff

Reputation: 183

LocBaml only extracts stuff from baml, which is the compiled form of your xaml files. Anything not defined in xaml (eg, strings defined in code-behind) will never be seen by it. The only way around this that I'm aware of is to define all the strings you might want to localize as string resources in xaml. These can easily be referenced from code-behind, so it's not as bad as it sounds. Strings that are entirely dynamically generated won't be localizable, but with some work you can construct them from snippets defined in your xaml resources.

Upvotes: 1

Rajesh R. Naik
Rajesh R. Naik

Reputation: 203

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 VM by calling the translate method from the code. For example

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

Upvotes: 0

Rafael Costa
Rafael Costa

Reputation: 298

If you are using .resx files to manage you translations, you can simply make them generate code (with Access Modifier: Public in the combo box at the .resx screen) and then make the VM send the messages directly to the view.

That way the underlying functionality of code-generated resource files will return the translated version of the desired text.

Upvotes: 0

Ignacio Soler Garcia
Ignacio Soler Garcia

Reputation: 21855

It's wrong to have messageboxes directly from the ViewModel. Instead you should raise events and let the view do the UI. Otherwise you couldn't unit test the ViewModel, and that's one of the main goals of the MVVM pattern.

Upvotes: 0

Related Questions