Localizing a WinForms Application with Built-in WPF User Controls

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

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

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

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

I did not understand how to combine two emerging DLLs (WPF and WinForms) into a single satellite assembly.

+1
source share
3 answers

Blech ... The WPF team must have left something desired with their localization solution. Well, for what it's worth, here's what I did (to be honest, I really borrowed this idea from Jecho Jekov on CodeProject):

( ) Localization MarkupExtension. Jecho LocExtension, i18nExtension - , , , Loc. , , - . , , Properties/Resources.resx.

, , - xaml:

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

resx UserControl/Window, WinForms, MarkupExtension, .

, , , . , , , , / . , Window/Control .

+3

dustyburwell, , WPF, WinForms, usercontrol InitializeComponent() WinForms, .

  • WinForms.
  • ElementHost (elementHost1).
  • WPF UserControl Host1 (userControl1).
  • . :
    public Form1()
    {
        InitializeComponent();

        WpfLocalization.LocalizationScope.SetCulture(userControl1, System.Threading.Thread.CurrentThread.CurrentCulture);
        WpfLocalization.LocalizationScope.SetUICulture(userControl1, System.Threading.Thread.CurrentThread.CurrentCulture);
        WpfLocalization.LocalizationManager.UpdateValues();
    }

, CurrentCulture , WPF, WinForms.

0

- AL.exe ( ), .resources, .resources LocBaml ( WinForms).

:

  • ( WinForms.resource dll).
  • XAML.resource locBaml
  • Use AL.exe to link both sets of .resource files to the new hybrid satellite dll and replace the original from step 1. To restore the project, steps 2 and 3 are required to re-combine the xaml resources, so you probably want to automate this by adding it as build step or goal.

Usage example

Al.exe /out:MyApp.resources.dll /culture:es-ES /embed:MyApp.Form1.es-ES.resources /embed:MyAppWpf.g.es-ES.resources

Additional Information (Hybrid Application Localization) http://msdn.microsoft.com/en-us/library/ms754231.aspx

0
source

All Articles