How to: Localize a WinForms Template(如何:本地化WinForms模板)
This topic demonstrates how to localize a WinForms Template using the Model Editor. You can customize custom and built-in WinForms templates. Both of these cases are considered in this topic.
本主题演示如何使用模型编辑器本地化WinForms模板。您可以自定义自定义和内置的WinForms模板。本主题会考虑这两种情况。
Localize a Built-In WinForms Template(本地化内置WinForms模板)
To do the translation manually, either directly in the Model Editor or using the Localization Tool, the culture-specific resources should be exported to the Application Model.
要手动翻译(无论是直接在模型编辑器中还是使用本地化工具),应将特定于区域性的资源导出到应用模型。
-
Invoke the Application Designer.
调用应用程序设计器。 -
In the Properties window, press the ellipsis button of the ResourcesExportedToModel property (see XafApplication.ResourcesExportedToModel). In the invoked dialog, check the templates you want to localize. Submit the selection by pressing the OK button.
在“属性”窗口中,按下ResourcesExportedToModel属性的省略号按钮(参见XafApplication.ResourcesExportedToModel)。在弹出的对话框中,勾选您要本地化的模板。按下“确定”按钮提交选择。
- Invoke the Model Editor for the current application project. In the Localization node, you will find child nodes corresponding to the selected resources. Localize them, as with any other XAF string.
为当前应用程序项目调用模型编辑器。在Localization节点中,您会找到与所选资源对应的子节点。像本地化其他任何XAF字符串一样本地化它们。
As an alternative, you can add localizable resources in the Module Designer. To do this, use the module’s ModuleBase.ResourcesExportedToModel property.
或者,您可以在模块设计器中添加可本地化资源。为此,请使用模块的ModuleBase.ResourcesExportedToModel属性。
Localize a Custom WinForms Template(本地化自定义WinForms模板)
It is assumed that you have created a custom template, as described in the How to: Create a Custom WinForms Ribbon Template topic. However, a similar approach is applicable to any other custom WinForms Template (e.g., created in accordance with the How to: Create a Custom WinForms Standard Template ).
假设您已经按照《如何:创建自定义WinForms功能区模板》主题中的描述创建了自定义模板。不过,类似的方法也适用于其他任何自定义WinForms模板(例如,按照《如何:创建自定义WinForms标准模板》创建的模板)。
Follow the steps below to make localization items related to your custom template available in the Application Model.
按照以下步骤使与您的自定义模板相关的本地化项在应用模型中可用。
- Inherit the FrameTemplateLocalizer<T> class. Pass your custom template type (e.g., DetailRibbonForm1) as the generic parameter.
继承FrameTemplateLocalizer<T>类。将您的自定义模板类型(例如,DetailRibbonForm1)作为泛型参数传递。
C#
using DevExpress.ExpressApp.Win.Templates;
// ...
public class MyTemplateLocalizer : FrameTemplateLocalizer<DetailRibbonForm1> { }
- In the WinApplication descendant’s constructor, add the MyTemplateLocalizer to the XafApplication.ResourcesExportedToModel list.
在WinApplication派生类的构造函数中,将MyTemplateLocalizer添加到XafApplication.ResourcesExportedToModel列表中。
C#
public partial class MySolutionWindowsFormsApplication : WinApplication {
public MySolutionWindowsFormsApplication () {
InitializeComponent();
this.ResourcesExportedToModel.Add(typeof(MyTemplateLocalizer));
}
// ...
}
- In the code-behind file of your custom template (e.g., DetailRibbonForm1.Designer.cs), find the line where the resources private field is declared and initialized.
在您的自定义模板的代码隐藏文件中(例如,DetailRibbonForm1.Designer.cs),找到声明和初始化resources私有字段的行。
C#
System.ComponentModel.ComponentResourceManager resources =
new System.ComponentModel.ComponentResourceManager(typeof(DetailRibbonForm1));
- Replace the ComponentResourceManager type with XafComponentResourceManager.
将ComponentResourceManager类型替换为XafComponentResourceManager。
C#
DevExpress.ExpressApp.Win.Templates.XafComponentResourceManager resources =
new DevExpress.ExpressApp.Win.Templates.XafComponentResourceManager(typeof(DetailRibbonForm1));
- Rebuild the solution and run the Model Editor. Expand the Localization | FrameTemplates | DetailRibbonForm1 node. The localization items related to your custom templates are available here.
重建解决方案并运行模型编辑器。展开Localization | FrameTemplates | DetailRibbonForm1节点。与您的自定义模板相关的本地化项在此处可用。
You can localize these items using the standard approach described in the Localization Basics topic.
您可以使用《本地化基础》主题中描述的标准方法来本地化这些项。