Localize UI Elements(本地化UI元素)
This lesson explains how to localize an XAF application. It describes how to translate UI elements into German and create a multi-language application.
本课介绍如何本地化XAF应用程序。它描述了如何将UI元素翻译成德语并创建多语言应用程序。
Note
For more information on localization, review the following topics:
有关本地化的更多信息,请查看以下主题:
- How to: Localize an XAF .NET Application
- Localization Basics
Step-by-Step Instructions(分步说明)
1.Add the following packages to the MySolution.Blazor.Server and MySolution.Win projects:
将以下包添加到MySolutions. Blazor.Server并MySolution.Win项目:
The packages are available only for the following languages: German (de), Spanish (es), and Japanese (ja). For other languages, use the Localization Service to download satellite assemblies. See the Localize Standard XAF Modules and DevExpress Controls Used in an Application topic for more information on how to use this service to localize XAF modules.
这些软件包仅适用于以下语言:德语(de)、西班牙语(es)和日语(ja)。对于其他语言,请使用本地化服务下载附属程序集。有关如何使用此服务本地化XAF模块的更多信息,请参阅应用程序主题中使用的本地化标准XAF模块和DevExpress控件。
2.In the MySolution.Blazor.Server project, open the appsettings.json file. Add the German language to the DevExpress:ExpressApp:Languages section and enable the runtime language switcher. You should always use the fully qualified language name that includes the country code (for example, de-DE instead of de):
在MySolutions. Blazor.Server项目中,打开appset.json文件。将德语添加到DevExpress:ExpressApp:语言部分并启用运行时语言切换器。您应该始终使用包含国家代码的完全限定语言名称(例如,de-DE而不是de):
appsettings.json {// ..."DevExpress": {"ExpressApp": {"Languages": "en-US;de-DE","ShowLanguageSwitcher": true, // ...}}
}
See the Current Culture in XAF ASP.NET Core Blazor Applications help section for more information on how an XAF ASP.NET Core Blazor application determines the default language.
有关XAF ASP.NETCore Blazor应用程序如何确定默认语言的更多信息,请参阅XAF ASP.NETCore Blazor应用程序中的当前区域性帮助部分。
3.Open the Model.DesignedDiffs.xafml file in the Model Editor. Focus the MySolution node and click Languages Manager… in the Language combo box on the Model Editor Toolbar.
在模型编辑器中打开Model. DesignedDiffs.xafml文件。聚焦MySolution节点,然后在模型编辑器工具栏的语言组合框中单击语言管理器…。
4.Add the target language in the invoked dialog and click OK.
在调用的对话框中添加目标语言,然后单击确定。
Save the model changes but don’t restart Visual Studio as the Languages Manager suggests. When you restart Visual Studio, the Model Editor loads the localized property value from the assemblies that you added previously and they become available at design time. For the purposes of this tutorial, these values aren’t necessary.
保存模型更改,但不要按照语言管理器的建议重新启动Visual Studio。重新启动Visual Studio时,模型编辑器会从您之前添加的程序集加载本地化属性值,这些值在设计时可用。出于本教程的目的,这些值不是必需的。
5.In the Solution Explorer, right-click the Model.DesignedDiffs.Localization.de-DE.xafml file and open its Properties window. Make sure that the Build Action field is set to Embedded resource.
在解决方案资源管理器中,右键单击Model.DesignedDiffs.Localization.de-DE. xafml文件并打开其属性窗口。确保构建操作字段设置为嵌入式资源。
6.Open the Model.DesignedDiffs.xafml file in the Model Editor. Select the newly added language in the Language combo box.
在模型编辑器中打开Model. DesignedDiffs.xafml文件。在语言组合框中选择新添加的语言。
7.The localization packages translate standard strings/messages used in XAF. You also need to translate the strings that are unique to your current application (such as object or property names). To do that, locate properties denoted by the “globe” glyph in all the nodes and child nodes and assign a German translation to them. For the purposes of this tutorial, translate the Employees navigation item to Angestellte:
本地化包翻译XAF中使用的标准字符串/消息。您还需要翻译当前应用程序独有的字符串(例如对象或属性名称)。为此,请在所有节点和子节点中找到由“全局”字形表示的属性,并为它们分配德语翻译。出于本教程的目的,将员工导航项翻译为Angestellte:
Tip
Instead of going through each node to find strings that require translation one by one, use the Localization Tool to streamline your localization process.
不要通过每个节点逐个查找需要翻译的字符串,而是使用本地化工具来简化您的本地化过程。
8.In the MySolution.Win project, open the Model.xafml file in the Model Editor and navigate to the MySolution node. Set the PreferredLanguage property to de-De to display the localized strings in the UI when you run the Windows Forms application.
在MySolution.Win项目中,在模型编辑器中打开Model. xafml文件并导航到MySolution节点。将PreferredLanguage属性设置为de-De以在运行Windows窗体应用程序时在UI中显示本地化字符串。
9.Run the application.
运行应用程序。
In ASP.NET Core Blazor, you can switch the language in the application settings menu. To access the settings menu, click the gear icon in the upper right corner:
在ASP.NETCore Blazor中,您可以在应用程序设置菜单中切换语言。要访问设置菜单,请单击右上角的齿轮图标:
10.The application should display the German translation of the Employees navigation item.
应用程序应显示员工导航项的德语翻译。
ASP.NET Core Blazor
Windows Forms
Next Lesson(下一课)
Assign a Standard Image
分配标准图像