使用嵌入式WPF用户控件本地化WinForms应用程序 [英] Localizing a WinForms Application with Embedded WPF User Controls

查看:225
本文介绍了使用嵌入式WPF用户控件本地化WinForms应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要本地化的应用程序是一个WinForms应用程序,该应用程序具有一些托管的WPF用户控件(在ElementHost WinForms控件中托管的WPF用户控件).

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).

我使用 resx 文件来本地化WinForms(VS2008)处理得很好.

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

当我尝试使用 LocBaml 方法时,问题就开始了本地化WPF部件.

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

这是发生了什么: 生成解决方案时,Visual Studio会自动为我生成附属程序集,但只会为resx文件中的WinForms资源生成. 然后,当我使用LocBaml命令行工具时,它会为我生成附属程序集,但只会为xaml文件中的WPF资源生成.

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.

我还没有弄清楚如何将两个生成的DLL(WPF和WinForms)合并到单个附属程序集中.

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

推荐答案

Blech ... WPF团队肯定会在其本地化解决方案中留下一些不足.好吧,对于它的价值而言,这就是我一直在做的(为公平起见,我实际上是从 Jecho Jekov 在CodeProject上):

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):

首先,您需要创建(或借用)Localization MarkupExtension类. Jecho称他为LocExtension,我叫我i18nExtension的原因无非就是我觉得它比Loc更具描述性.该标记扩展将执行的操作是在资源文件中查找给定的资源密钥.如果您希望所有资源都位于Properties/Resources.resx文件中,那么这是一个非常简单的编程类.

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.

您最终得到的是xaml中的类似内容:

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

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

如果要按照WinForms设计器的要求为每个UserControl/Window创建单独的resx文件,则必须在MarkupExtension中增加一些创意,以便它可以确定其上下文.

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.

这篇关于使用嵌入式WPF用户控件本地化WinForms应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆