views:

836

answers:

1

The application I'm trying to localize is a WinForms application that has a few hosted WPF user controls (WPF user controls hosted in an ElementHost WinForms control).

I use resx files to localize the WinForms, which VS2008 manages quite well.

The problem starts when I try to use the LocBaml method to localize the WPF parts.

Here's what happens: When I build the solution, Visual Studio automatically generates satellite assemblies for me but only for the WinForms resources in the resx files. Then, when I use the LocBaml command-line tool, it generates satellite assemblies for me but only for the WPF resources in the xaml files.

I haven't figured out how to merge the two resulting DLLs (WPF & WinForms) into a single satellite assembly.

+2  A: 

Blech...The WPF team sure seemed to leave something to be desired with their localization solution. Well, for what it's worth, here's what I've been doing (to be fair, I've actually borrowed this idea from Jecho Jekov on CodeProject):

First, you'll need to create (or borrow) a Localization MarkupExtension class. Jecho calls his LocExtension, I called mine i18nExtension for no reason other than I felt it was a little more descriptive than Loc. What this markup extension will do is lookup a given resource key in your resource file. This is a really simple and easy class to code up if you want all of your resources located in the Properties/Resources.resx file.

What you end up with is something like this in your xaml:

<UserControl ... >
    ...
    <TextBox Text="{i18n HelloWorld}"/>
    ...
</UserControl>

If you want to have separate resx files for each UserControl/Window as the WinForms designer allows you to do, you'll have to get a little more creative in your MarkupExtension so that it can figure out its context.

Ultimately, you end up with one satellite assembly per culture, which is what it seems your after. The one caveat that comes to mind is that I'm not sure how this deals with on-the-fly culture/language changes. At the very least, the Window/Control will need to be reloaded.

dustyburwell