Localizing DevExpress .NET Products

Localization is the process of translating an application's resources into localized versions for a specific culture or locale. This allows you to build translated versions of your applications in order to provide a complete native language interface to end users. This article guides you through the entire process of localizing Developer Express .NET products.


What should be localized?

All Developer Express .NET products have localizable resources that represent various dialog boxes, captions for buttons, menu items, confirmation and error messages, etc. All these resource strings can easily be translated into various languages or replaced by their equivalents. This can be done in one of two ways:

s.gif
tri2.gif
creating satellite resource assemblies;
s.gif
tri2.gif
using a "Localizer" object.

Creating satellite resource assemblies is the standard approach used when creating multi-language applications. Localizing via a "Localizer" is the feature provided by Developer Express which is useful in the following cases:

s.gif
tri2.gif
You are developing an application for a single culture and you want to translate the resources into the appropriate language or you just wish to change the default resources (for English (United States) culture) to their equivalents.
s.gif
tri2.gif
You don't want to use the available satellite assemblies and you don't have the source code to create your own localized assemblies.

The image below shows some editors from the XtraEditors Library localized into English and German.


Creating Satellite Resource Assemblies

This approach to localizing Developer Express .NET products implies creating new satellite assemblies which contain the localized resources translated into the appropriate target languages. This is the more common approach when developing world-ready applications.

Some of our customers have translated our resources into other languages. They've been kind enough to share these translated resources with the community, so you can freely download them here. The download includes resources translated to the following languages:

s.gif
tri2.gif
Chinese, Czech, Danish, Dutch, French, German, Italian, Japanese, Norwegian, Portuguese, Russian, Slovenian, Spanish, Vietnamese.

 

For other languages you can manually translate the resource strings provided that you have purchased the version of the component which ships with its source code. For detailed information on how to manually translate the resources and use satellite assemblies see the Localization document in the XtraEditors help file and the Localizing Applications document in MSDN Library.

Using a Localizer

This is another way of localizing Developer Express .NET products which allows resources to be localized on the fly.

What Is a Localizer?

A Localizer is a class that provides the means to localize the control's interface elements. Each Developer Express .NET control has its own localizer class, they are listed in the table below:

Control
Class
XtraBars
DevExpress.XtraBars.Localization.BarLocalizer
XtraCharts
DevExpress.XtraCharts.Localization.ChartLocalizer
XtraEditors Library
DevExpress.XtraEditors.Controls.Localizer
XtraGrid
DevExpress.XtraGrid.Localization.GridLocalizer
XtraLayout
DevExpress.XtraLayout.Localization.LayoutLocalizer
XtraNavBar
DevExpress.XtraNavBar.NavBarLocalizer
XtraPivotGrid
DevExpress.XtraPivotGrid.Localization.PivotGridLocalizer
XtraPrinting Library
DevExpress.XtraPrinting.Localization.PreviewLocalizer
XtraReports
DevExpress.XtraReports.Localization.ReportLocalizer
XtraScheduler
DevExpress.XtraScheduler.Localization.SchedulerLocalizer
XtraTreeList
DevExpress.XtraTreeList.Localization.TreeListLocalizer
XtraVerticalGrid
DevExpress.XtraVerticalGrid.Localization.VGridLocalizer

The process of localizing is rather simple. First you should create a descendant of the appropriate localizer and override its GetLocalizedString method in order to translate or modify the control's resource strings. After the localizer descendant has been created, you must instantiate it and assign it to the static Active property of the localizer class you derived it from.

Examples

The following example demonstrates how to localize the XtraGrid's and XtraEditors Library's UI into German. To do this, descendants of the DevExpress.XtraGrid.Localization.GridLocalizer and DevExpress.XtraEditors.Controls.Localizer classes with localized resource strings are created.

ContractedBlock.gif ExpandedBlockStart.gif C#
ExpandedBlockStart.gifContractedBlock.gifpublic class GermanGridLocalizer : GridLocalizer dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif   
public override string Language dot.gifget dot.gifreturn "Deutsch"; }}
ExpandedSubBlockStart.gifContractedSubBlock.gif   
public override string GetLocalizedString(GridStringId id) dot.gif{
InBlock.gif      
string ret = "";
ExpandedSubBlockStart.gifContractedSubBlock.gif      
switch(id) dot.gif{
InBlock.gif         
// dot.gif
InBlock.gif
         case GridStringId.MenuColumnSortAscending : return "Aufsteigend sortieren"
InBlock.gif         
case GridStringId.MenuColumnSortDescending : return "Absteigend sortieren"
InBlock.gif         
case GridStringId.MenuColumnGroup : return "Gruppieren fur dieses Feld"
InBlock.gif         
case GridStringId.MenuColumnUnGroup : return "Gruppierung aufheben"
InBlock.gif         
case GridStringId.MenuColumnColumnCustomization : return "Laufzeit benutzerdefinierte Spalte"
InBlock.gif         
case GridStringId.MenuColumnBestFit : return "Optimale Breite"
InBlock.gif         
case GridStringId.MenuColumnFilter : return "Kann gruppieren"
InBlock.gif         
case GridStringId.MenuColumnClearFilter : return "Filter aufheben"
InBlock.gif         
case GridStringId.MenuColumnBestFitAllColumns : return "Optimale Breite (alle Spalten)";
InBlock.gif         
// dot.gif
InBlock.gif
         default:
InBlock.gif            ret 
= "";
InBlock.gif            
break;
ExpandedSubBlockEnd.gif      }

InBlock.gif      
return ret;
ExpandedSubBlockEnd.gif   }

ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
public class GermanEditorsLocalizer : Localizer dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif   
public override string Language dot.gifget dot.gifreturn "Deutsch"; }}
ExpandedSubBlockStart.gifContractedSubBlock.gif   
public override string GetLocalizedString(StringId id) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif      
switch(id) dot.gif{
InBlock.gif         
// dot.gif
InBlock.gif
         case StringId.NavigatorTextStringFormat: return "Zeile {0} von {1}";
InBlock.gif         
case StringId.PictureEditMenuCut: return "Ausschneiden";
InBlock.gif         
case StringId.PictureEditMenuCopy: return "Kopieren";
InBlock.gif         
case StringId.PictureEditMenuPaste: return "Einfugen";
InBlock.gif         
case StringId.PictureEditMenuDelete: return "Loschen";
InBlock.gif         
case StringId.PictureEditMenuLoad: return "Laden";
InBlock.gif         
case StringId.PictureEditMenuSave: return "Speichern";
InBlock.gif         
// dot.gif
ExpandedSubBlockEnd.gif
      }

InBlock.gif      
return "";
ExpandedSubBlockEnd.gif   }

ExpandedBlockEnd.gif}

None.gif
None.gif




ContractedBlock.gif ExpandedBlockStart.gif VB
ExpandedBlockStart.gifContractedBlock.gifPublic Class GermanGridLocalizerClass GermanGridLocalizer
InBlock.gif   
Inherits GridLocalizer
ExpandedSubBlockStart.gifContractedSubBlock.gif   
Public Overrides ReadOnly Property Language()Property Language() As String
InBlock.gif      
Get
InBlock.gif         
Return "Deutsch"
InBlock.gif      
End Get
ExpandedSubBlockEnd.gif   
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif   
Public Overrides Function GetLocalizedString()Function GetLocalizedString(ByVal id As GridStringId) As String
InBlock.gif      
Dim ret As String = ""
InBlock.gif      
Select Case id
InBlock.gif         
' dot.gif
InBlock.gif
         Case GridStringId.MenuColumnSortAscending : Return "Aufsteigend sortieren"
InBlock.gif         
Case GridStringId.MenuColumnSortDescending : Return "Absteigend sortieren"
InBlock.gif         
Case GridStringId.MenuColumnGroup : Return "Gruppieren fur dieses Feld"
InBlock.gif         
Case GridStringId.MenuColumnUnGroup : Return "Gruppierung aufheben"
InBlock.gif         
Case GridStringId.MenuColumnColumnCustomization : Return "Laufzeit benutzerdefinierte Spalte"
InBlock.gif         
Case GridStringId.MenuColumnBestFit : Return "Optimale Breite"
InBlock.gif         
Case GridStringId.MenuColumnFilter : Return "Kann gruppieren"
InBlock.gif         
Case GridStringId.MenuColumnClearFilter : Return "Filter aufheben"
InBlock.gif         
Case GridStringId.MenuColumnBestFitAllColumns : Return "Optimale Breite (alle Spalten)"
InBlock.gif         
' dot.gif
InBlock.gif
         Case Else
InBlock.gif            ret 
= ""
InBlock.gif      
End Select
InBlock.gif      
Return ret
ExpandedSubBlockEnd.gif   
End Function

ExpandedBlockEnd.gif
End Class

None.gif
ExpandedBlockStart.gifContractedBlock.gif
Public Class GermanEditorsLocalizerClass GermanEditorsLocalizer
InBlock.gif   
Inherits Localizer
ExpandedSubBlockStart.gifContractedSubBlock.gif   
Public Overrides ReadOnly Property Language()Property Language() As String
InBlock.gif      
Get
InBlock.gif         
Return "Deutsch"
InBlock.gif      
End Get
ExpandedSubBlockEnd.gif   
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif   
Public Overrides Function GetLocalizedString()Function GetLocalizedString(ByVal id As StringId) As String
InBlock.gif      
Select Case id
InBlock.gif         
' dot.gif
InBlock.gif
         Case StringId.NavigatorTextStringFormat : Return "Zeile {0} von {1}"
InBlock.gif         
Case StringId.PictureEditMenuCut : Return "Ausschneiden"
InBlock.gif         
Case StringId.PictureEditMenuCopy : Return "Kopieren"
InBlock.gif         
Case StringId.PictureEditMenuPaste : Return "Einfugen"
InBlock.gif         
Case StringId.PictureEditMenuDelete : Return "Loschen"
InBlock.gif         
Case StringId.PictureEditMenuLoad : Return "Laden"
InBlock.gif         
Case StringId.PictureEditMenuSave : Return "Speichern"
InBlock.gif         
' dot.gif
InBlock.gif
      End Select
InBlock.gif      
Return ""
ExpandedSubBlockEnd.gif   
End Function

ExpandedBlockEnd.gif
End Class

None.gif
None.gif

Then these localizers are instantiated and assigned to their ancestors' Active property.

ContractedBlock.gif ExpandedBlockStart.gif C#
ExpandedBlockStart.gifContractedBlock.gifprivate void Form1_Load(object sender, System.EventArgs e) dot.gif{
InBlock.gif   GridLocalizer.Active 
= new GermanGridLocalizer();
InBlock.gif   Localizer.Active 
= new GermanEditorsLocalizer();
ExpandedBlockEnd.gif}

None.gif
None.gif


ContractedBlock.gif ExpandedBlockStart.gif VB
ExpandedBlockStart.gifContractedBlock.gifPrivate Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InBlock.gif   GridLocalizer.Active 
= New GermanGridLocalizer()
InBlock.gif   Localizer.Active 
= New GermanEditorsLocalizer()
ExpandedBlockEnd.gif
End Sub

None.gif
None.gif

 

The result of localizing the runtime grid interface is shown below:


As mentioned above the technique described in this section can also be used when it is necessary to replace the default resources (for English (Unites States) culture) with their equivalents. For example, you can change such strings as "equals", "less then", etc. which are used in the grid's Custom Filter Dialog to their numerical equivalents "=", "<" as shown below:


ContractedBlock.gif ExpandedBlockStart.gif C#
ExpandedBlockStart.gifContractedBlock.gifprivate void Form1_Load(object sender, System.EventArgs e) dot.gif{
InBlock.gif   GridLocalizer.Active 
= new MyGridLocalizer();
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
public class MyGridLocalizer : GridLocalizer dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif   
public override string GetLocalizedString(GridStringId id) dot.gif{
InBlock.gif      
string ret = "";
ExpandedSubBlockStart.gifContractedSubBlock.gif      
switch(id) dot.gif{
InBlock.gif         
// dot.gif
InBlock.gif
         case GridStringId.CustomFilterDialogConditionEQU : return "=";
InBlock.gif         
case GridStringId.CustomFilterDialogConditionNEQ : return "&lt;>";
InBlock.gif         
case GridStringId.CustomFilterDialogConditionGT : return "&gt;";
InBlock.gif         
case GridStringId.CustomFilterDialogConditionGTE : return "&gt;=";
InBlock.gif         
case GridStringId.CustomFilterDialogConditionLT : return "&lt;";
InBlock.gif         
case GridStringId.CustomFilterDialogConditionLTE : return "&lt;=";
InBlock.gif         
// dot.gif
InBlock.gif
         default:
InBlock.gif            ret 
= "";
InBlock.gif            
break;
ExpandedSubBlockEnd.gif      }

InBlock.gif      
return ret;
ExpandedSubBlockEnd.gif   }

ExpandedBlockEnd.gif}

None.gif
None.gif


ContractedBlock.gif ExpandedBlockStart.gif VB
ExpandedBlockStart.gifContractedBlock.gifPrivate Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InBlock.gif   GridLocalizer.Active 
= New MyGridLocalizer()
ExpandedBlockEnd.gif
End Sub

None.gif
ExpandedBlockStart.gifContractedBlock.gif
Public Class MyGridLocalizerClass MyGridLocalizer
InBlock.gif   
Inherits GridLocalizer
ExpandedSubBlockStart.gifContractedSubBlock.gif   
Public Overrides Function GetLocalizedString()Function GetLocalizedString(ByVal id As GridStringId) As String
InBlock.gif      
Dim ret As String = ""
InBlock.gif      
Select Case id
InBlock.gif         
' dot.gif
InBlock.gif
         Case GridStringId.CustomFilterDialogConditionEQU : Return "="
InBlock.gif         
Case GridStringId.CustomFilterDialogConditionNEQ : Return "&lt;>"
InBlock.gif         
Case GridStringId.CustomFilterDialogConditionGT : Return "&gt;"
InBlock.gif         
Case GridStringId.CustomFilterDialogConditionGTE : Return "&gt;="
InBlock.gif         
Case GridStringId.CustomFilterDialogConditionLT : Return "&lt;"
InBlock.gif         
Case GridStringId.CustomFilterDialogConditionLTE : Return "&lt;="
InBlock.gif         
' dot.gif
InBlock.gif
         Case Else
InBlock.gif            ret 
= ""
InBlock.gif      
End Select
InBlock.gif      
Return ret
ExpandedSubBlockEnd.gif   
End Function

ExpandedBlockEnd.gif
End Class

None.gif
None.gif


 

The result is shown below:





转载于:https://www.cnblogs.com/fosoyo/archive/2006/04/13/374738.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值