企业级仪表盘 DevExpress Dashboard 可以在运行时以编程的形式指定本地化资源的值,这个方法适用于在设计时不知道资源值的情况。今天为大家介绍如何本地化Windows Forms UI。
本地化应用程序的步骤如下:
1、创建localizer class的子类
Dashboard Suite WinForms UI中有两个特定的localizer对象类型:
- DashboardWinLocalizer -提供默认的语言字符串值(en);
- DashboardWinResLocalizer - 在本地化资源使用Satellite resource assemblies时提供本地化语言字符串值。
- 本地化跨平台字符串,也可 DashboardLocalizer 和 DashboardsResLocalizer 两个类。
2、接下来覆盖GetLocalizedString方法。这个方法会调用每个本地化字符串并返回字符串的值。默认情况下,它返回的值包含在 DashboardWinStringId (in the DashboardWinLocalizer class) 或 DashboardStringId (in the DashboardLocalizer class) 类中。覆盖GetLocalizedString方法后可以返回自定义的字符串值。
3、最后,为class部署一个实例,让它变成静态的Active属性。注意:不是所有的字符串都可以通过Localizer classes进行转换。Dashboard包含表单资源(如Create Data Source wizard),唯一能转换它们的方式就是创建Satellite assemblies。
下面这段代码展示了如何将Dashboard Designer的界面本地化为Spanish:
public class SpanishDashboardWinLocalizer : DashboardWinLocalizer { public override string Language { get { return "Español"; }} public override string GetLocalizedString(DashboardWinStringId id) { string ret = ""; switch(id) { // ... case DashboardWinStringId.CommandNewDashboardCaption : return "Nuevo"; case DashboardWinStringId.CommandOpenDashboardCaption : return "Abrir"; case DashboardWinStringId.CommandSaveDashboardCaption : return "Guardar"; case DashboardWinStringId.CommandSaveAsDashboardCaption : return "Guardar como"; case DashboardWinStringId.CommandUndoCaption : return "Deshacer"; case DashboardWinStringId.CommandRedoCaption : return "Rehacer"; case DashboardWinStringId.CommandNewDataSourceCaption : return "Nueva Fuente de Datos"; case DashboardWinStringId.CommandEditDataSourceCaption : return "Editar"; case DashboardWinStringId.CommandDeleteDataSourceCaption : return "Eliminar"; // ... default: ret = ""; break; } return ret; } } public class SpanishDashboardCoreLocalizer : DashboardLocalizer { public override string Language { get { return "Español"; }} public override string GetLocalizedString(DashboardStringId id) { string ret = ""; switch(id) { // ... case DashboardStringId.DateTimeGroupIntervalYear : return "Año"; case DashboardStringId.SummaryTypeSum : return "Suma"; case DashboardStringId.DescriptionItemArgument : return "Argumento"; case DashboardStringId.DescriptionArguments : return "Argumentos"; case DashboardStringId.DescriptionItemValue : return "Valor"; case DashboardStringId.DescriptionValues : return "Valores"; // ... default: ret = ""; break; } return ret; } }
之后,这些localizers会被实例化,给它们的父类部署Active属性:
private void Form1_Load(object sender, System.EventArgs e) { DashboardWinLocalizer.Active = new SpanishDashboardWinLocalizer(); DashboardLocalizer.Active = new SpanishDashboardCoreLocalizer(); }
最终结果:
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/590.html