学习023-09 How to: Localize a WinForms Template(如何:本地化WinForms模板)

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.
您可以使用《本地化基础》主题中描述的标准方法来本地化这些项。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汤姆•猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值