Localize UI Elements 汉化界面(本地化)
In this lesson, you will learn the basics of localizing visible UI elements. By default, the application uses the invariant language (English). You will translate your application into German, and create a multi-language application. To illustrate different localization scenarios, the lesson is divided into two sections. They should be performed in order. You will translate several captions for training purposes. To learn how to fully localize an XAF application, first review the Localization section, then follow the How to: Localize an XAF Application topic.
在本课中,您将学习本地化可见 UI 元素的基础知识。默认情况下,应用程序使用固定语言(英语)。您将将应用程序翻译成德语,并创建多语言应用程序。为了说明不同的本地化方案,本课程分为两个部分。它们应按顺序执行。您将翻译几个标题以用于培训目的。要了解如何完全本地化 XAF 应用程序,请先查看本地化部分,然后按照"如何:本地化 XAF 应用程序"主题进行操作。
Note 注意
Before proceeding, take a moment to review the Place an Action in a Different Location lesson.
在继续之前,请花点时间复习"将操作置于不同位置"课程。
Translate Your Application into an Additional Language
将应用程序转换为其他语言
Follow the steps below to study the basic concepts of translating your application.
-
Invoke the Model Editor for the MySolution.Module project. Find the Model Editor's toolbar. If it is hidden, check the View | Toolbars | XAF Model Editor menu item. In the toolbar's Language combo box (located on the Model Editor's toolbar), select de. If it is not there, click the Language Manager... item. In the invoked dialog, click the Add button and select de (German - Deutsch).
请按照以下步骤学习翻译应用程序的基本概念。
- 调用 MySolution.模块项目的模型编辑器。查找模型编辑器的工具栏。如果隐藏,请检查视图 |工具栏 |XAF 模型编辑器菜单项。在工具栏的语言组合框中(位于模型编辑器的工具栏上),选择 de。如果不存在,请单击语言管理器...项目。在调用的对话框中,单击"添加"按钮并选择 de(德语 - 德语)。
- After adding the language, you should restart Visual Studio.
-
Select the newly added language in the Language combo box.
-
添加语言后,应重新启动 Visual Studio。
-
在"语言组合"框中选择新添加的语言。
-
To fully localize your application, you should look through all the nodes and their child nodes to set German values for the properties denoted by the "globe" glyph. The Localization Tool simplifies this task. For training purposes, translate a few values to see how this affects your application. Esentially, the Caption properties can be localized.
-
要完全本地化应用程序,应查看所有节点及其子节点,以设置由"globe" 字形表示的属性的德语值。本地化工具简化了此任务。出于培训目的,请转换几个值,以查看这对应用程序有何影响。从经验上讲,标题属性可以本地化。
Note 注意
The How to: Localize an XAF Application topic explains how to localize an XAF application.
"如何:本地化 XAF 应用程序"主题说明如何本地化 XAF 应用程序。
- In the Model Editor invoked for a WinForms project and/or an ASP.NET application project, navigate to the Application node. In the PreferredLanguage property's dropdown list, select "de". If you need to use the German language in both the WinForms and ASP.NET applications, you can specify the PreferredLanguage property value in the Model Editor invoked for the application module.
- 在为 WinForms 项目和/或ASP.NET应用程序项目调用的模型编辑器中,导航到应用程序节点。在"首选语言"属性的下拉列表中,选择"de"。。如果需要在 WinForms 和ASP.NET应用程序中使用德语,则可以在为应用程序模块调用的模型编辑器中指定首选语言属性值。
- Run the WinForms or ASP.NET application. Check to see that the properties that you translated via the Model Editor are displayed in German.
- 运行 WinForms 或ASP.NET应用程序。检查您通过模型编辑器翻译的属性是否以德语显示。
Make a User-Language Application
创建用户语言应用程序
Perform the steps below if your application needs to be in the user's language (the user's operating system language or the language passed by the user's Internet browser).
如果应用程序需要使用用户的语言(用户的操作系统语言或用户的 Internet 浏览器传递的语言),请执行以下步骤。
- Translate your application into the required languages. For this purpose, invoke the Model Editor, set the required language in the Model Editor's Language toolbar item and translate all localizable property values (as detailed in the previous section). Do this for each required language.
- In the Model Editor invoked for the WinForms and/or ASP.NET application project, navigate to the Application node. In the PreferredLanguage property's dropdown list, select the (User language) item.
- Alternatively, you can specify the PreferredLanguage property value in the Model Editor invoked for the application module. In this instance, the user language will be used in both the WinForms and ASP.NET applications.
- 将应用程序翻译成所需的语言。为此,调用模型编辑器,在模型编辑器的语言工具栏项中设置所需的语言,并翻译所有可本地化的属性值(如上一节所述)。对每种必需的语言执行此操作。
- 在为 WinForms 和/或 ASP.NET应用程序项目调用的模型编辑器中,导航到应用程序节点。在"首选语言"属性的下拉列表中,选择(用户语言)项。
- 或者,您可以在为应用程序模块调用的模型编辑器中指定"首选语言"属性值。在这种情况下,用户语言将在 WinForms 和ASP.NET应用程序中使用。
-
Run the WinForms or ASP.NET application. Check to see if the language corresponds to your system's current language.
If you did not localize the application to your system's current language, the default language (English) will be used.
- 运行 WinForms 或ASP.NET应用程序。检查该语言是否与系统的当前语言相对应。
如果未将应用程序本地化为系统的当前语言,将使用默认语言(英语)。
You can see a sample application localized into German in the Main Demo. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/
您可以在主演示中看到本地化为德语的示例应用程序。主演示应用程序安装在%PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/
.
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端