下面的示例演示了如何把 XtraGrid 控件和 XtraEditors 库 的用户界面本地化为德语。 要执行此操作,需要创建有本地化资源字符串的 DevExpress.XtraGrid.Localization.GridLocalizer 和 Localizer 类的子类。
C# | 复制代码 |
---|
public class GermanGridLocalizer : GridLocalizer {
public override string Language { get { return "Deutsch"; }}
public override string GetLocalizedString(GridStringId id) {
string ret = "";
switch(id) {
case GridStringId.MenuColumnSortAscending : return "Aufsteigend sortieren";
case GridStringId.MenuColumnSortDescending : return "Absteigend sortieren";
case GridStringId.MenuColumnGroup : return "Gruppieren fur dieses Feld";
case GridStringId.MenuColumnUnGroup : return "Gruppierung aufheben";
case GridStringId.MenuColumnColumnCustomization :
return "Laufzeit benutzerdefinierte Spalte";
case GridStringId.MenuColumnBestFit : return "Optimale Breite";
case GridStringId.MenuColumnFilter : return "Kann gruppieren";
case GridStringId.MenuColumnClearFilter : return "Filter aufheben";
case GridStringId.MenuColumnBestFitAllColumns : return "Optimale Breite (alle Spalten)";
default:
ret = "";
break;
}
return ret;
}
}
public class GermanEditorsLocalizer : Localizer {
public override string Language { get { return "Deutsch"; }}
public override string GetLocalizedString(StringId id) {
switch(id) {
case StringId.NavigatorTextStringFormat: return "Zeile {0} von {1}";
case StringId.PictureEditMenuCut: return "Ausschneiden";
case StringId.PictureEditMenuCopy: return "Kopieren";
case StringId.PictureEditMenuPaste: return "Einfugen";
case StringId.PictureEditMenuDelete: return "Loschen";
case StringId.PictureEditMenuLoad: return "Laden";
case StringId.PictureEditMenuSave: return "Speichern";
}
return "";
}
}
|
Visual Basic | 复制代码 |
---|
Public Class GermanGridLocalizer
Inherits GridLocalizer
Public Overrides ReadOnly Property Language() As String
Get
Return "Deutsch"
End Get
End Property
Public Overrides Function GetLocalizedString(ByVal id As GridStringId) As String
Dim ret As String = ""
Select Case id
' ...
Case GridStringId.MenuColumnSortAscending : Return "Aufsteigend sortieren"
Case GridStringId.MenuColumnSortDescending : Return "Absteigend sortieren"
Case GridStringId.MenuColumnGroup : Return "Gruppieren fur dieses Feld"
Case GridStringId.MenuColumnUnGroup : Return "Gruppierung aufheben"
Case GridStringId.MenuColumnColumnCustomization : _
Return "Laufzeit benutzerdefinierte Spalte"
Case GridStringId.MenuColumnBestFit : Return "Optimale Breite"
Case GridStringId.MenuColumnFilter : Return "Kann gruppieren"
Case GridStringId.MenuColumnClearFilter : Return "Filter aufheben"
Case GridStringId.MenuColumnBestFitAllColumns : Return "Optimale Breite (alle Spalten)"
' ...
Case Else
ret = ""
End Select
Return ret
End Function
End Class
Public Class GermanEditorsLocalizer
Inherits Localizer
Public Overrides ReadOnly Property Language() As String
Get
Return "Deutsch"
End Get
End Property
Public Overrides Function GetLocalizedString(ByVal id As StringId) As String
Select Case id
' ...
Case StringId.NavigatorTextStringFormat : Return "Zeile {0} von {1}"
Case StringId.PictureEditMenuCut : Return "Ausschneiden"
Case StringId.PictureEditMenuCopy : Return "Kopieren"
Case StringId.PictureEditMenuPaste : Return "Einfugen"
Case StringId.PictureEditMenuDelete : Return "Loschen"
Case StringId.PictureEditMenuLoad : Return "Laden"
Case StringId.PictureEditMenuSave : Return "Speichern"
' ...
End Select
Return ""
End Function
End Class
|
然后,这些本地化提供程序被实例化,并被指派到它们祖先的 Active 属性。
C# | 复制代码 |
---|
private void Form1_Load(object sender, System.EventArgs e) {
GridLocalizer.Active = new GermanGridLocalizer();
Localizer.Active = new GermanEditorsLocalizer();
}
|
Visual Basic | 复制代码 |
---|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
GridLocalizer.Active = New GermanGridLocalizer()
Localizer.Active = New GermanEditorsLocalizer()
End Sub
|
运行时刻网格控件界面的本地化结果如下所示: