Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localizing MVVM based WPF applications

What would be a good aproach to localize a MVVM based WPF allication that can change its language at runtime? Of course I could create a string property in the ViewModel for each and every string that is displayed somewhere in the View but that seems rather tedious to me. Is there a common approach/best practice for this?

like image 310
bitbonk Avatar asked Aug 25 '09 12:08

bitbonk


2 Answers

Here's an excellent article about WPF localization. It deals with the Microsoft-supported localization technique, and a few alternative ones

I wouldn't recommend the "official" solution for localization... it's really a pain to use, it modifies you XAML (adds x:Uid attributes to every element that can be localized), and there are no good tools from MS to make it an easy solution. Good old resx localization is much easier to use, and integrates quite well with WPF with just a few tricks (namely, markup extensions and/or attached properties). Also, you can easily change the interface language at runtime thanks to the binding system.

like image 61
Thomas Levesque Avatar answered Sep 25 '22 18:09

Thomas Levesque


WPF has a lot of support for localization. Perhaps you can leverage that? Unfortunately I think that changing the user interface language at run-time is somewhat difficult and you probably need to come up with your own scheme.

Also, as the view-model is UI agnostic I don't think storing user interface strings in the view-model is a good solution. These belong to the view.

like image 20
Martin Liversage Avatar answered Sep 25 '22 18:09

Martin Liversage