aspnet-12048-localization-localizer-objects.md
DevExpress controls and libraries have Localizer classes (see the table below) that provide resource strings for UI elements and allow you to override these strings at runtime.
To localize a control or library via a localizer object, follow the steps below.
Create a descendant of the corresponding Localizer class and override its GetLocalizedString(T) method, which should return strings for specific string resource identifiers.
Define the Activate method, which creates an instance of your custom localizer and a localizer provider. Set this provider as the active provider for the localizer.
Call the Activate method in the Application_Start event handler within the Global.asax file.
Note
If you localize your application via satellite resource assemblies or global resources, use the Resource Localizer class (see the table below) for runtime localization. This class provides the same functionality as the Localizer class, but contains localized resource string values.
Important
Not all strings can be translated via Localizer classes. Some components contain form resources (e.g., the XtraReports Search dialog), and the only way to translate them is to create satellite resource assemblies.
The table below lists the following classes related to localization functionality:
|
Product
|
Localizer Class
|
Resource Localizer Class
|
Resource String Enumeration
| | --- | --- | --- | --- | |
|
|
|
| |
|
|
|
ChartStringId
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
GaugesCoreStringId
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
ASPxRichEditResourcesLocalizer
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
ASPxSpreadsheetResourcesLocalizer
|
| |
|
|
|
| |
|
|
|
|
The following example demonstrates how to localize the ASPxGridView control via a custom localizer.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-use-a-custom-aspxgridview-localizer-e1315
<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" KeyFieldName="ID"
OnRowDeleting="ASPxGridView1_RowDeleting" OnRowInserting="ASPxGridView1_RowInserting"
OnRowUpdating="ASPxGridView1_RowUpdating" Width="420px">
<Columns>
<dxwgv:GridViewCommandColumn ShowEditButton="true" ShowClearFilterButton="true"
ShowNewButtonInHeader="true" ShowDeleteButton="true" VisibleIndex="0" />
<dxwgv:GridViewDataTextColumn FieldName="ID" VisibleIndex="1" Width="150px" />
</Columns>
<Settings ShowFilterBar="Visible" ShowFilterRow="True" ShowGroupPanel="True" />
</dxwgv:ASPxGridView>
using DevExpress.Utils.Localization.Internal;
using DevExpress.Web.Localization;
namespace CustomLocalizer {
public class MyGridLocalizer : ASPxGridViewLocalizer {
public static void Activate() {
MyGridLocalizer localizer = new MyGridLocalizer();
DefaultActiveLocalizerProvider<ASPxGridViewStringId> provider =
new DefaultActiveLocalizerProvider<ASPxGridViewStringId>(localizer);
MyGridLocalizer.SetActiveLocalizerProvider(provider);
}
public override string GetLocalizedString(ASPxGridViewStringId id) {
if (id == ASPxGridViewStringId.GroupPanel)
return "Testing: group panel caption";
string result = base.GetLocalizedString(id);
return string.Format("grid:{0}", result);
}
}
public class MyEditorsLocalizer : ASPxEditorsLocalizer {
public static void Activate() {
MyEditorsLocalizer localizer = new MyEditorsLocalizer();
DefaultActiveLocalizerProvider<ASPxEditorsStringId> provider =
new DefaultActiveLocalizerProvider<ASPxEditorsStringId>(localizer);
MyEditorsLocalizer.SetActiveLocalizerProvider(provider);
}
public override string GetLocalizedString(ASPxEditorsStringId id) {
string result = base.GetLocalizedString(id);
return string.Format("editors:{0}", result);
}
}
public class MyWebLocalizer : ASPxperienceLocalizer {
public static void Activate() {
MyWebLocalizer localizer = new MyWebLocalizer();
DefaultActiveLocalizerProvider<ASPxperienceStringId> provider =
new DefaultActiveLocalizerProvider<ASPxperienceStringId>(localizer);
MyWebLocalizer.SetActiveLocalizerProvider(provider);
}
public override string GetLocalizedString(ASPxperienceStringId id) {
string result = base.GetLocalizedString(id);
return string.Format("web:{0}", result);
}
}
}
Imports DevExpress.Web.Localization
Imports DevExpress.Utils.Localization.Internal
Namespace CustomLocalizer
Public Class MyGridLocalizer
Inherits ASPxGridViewLocalizer
Public Shared Sub Activate()
Dim localizer As New MyGridLocalizer()
Dim provider As DefaultActiveLocalizerProvider(Of ASPxGridViewStringId) = _
New DefaultActiveLocalizerProvider(Of ASPxGridViewStringId)(localizer)
MyGridLocalizer.SetActiveLocalizerProvider(provider)
End Sub
Public Overrides Function GetLocalizedString(ByVal id As ASPxGridViewStringId) As String
If id = ASPxGridViewStringId.GroupPanel Then
Return "Testing: group panel caption"
End If
Dim result As String = MyBase.GetLocalizedString(id)
Return String.Format("grid:{0}", result)
End Function
End Class
Public Class MyEditorsLocalizer
Inherits ASPxEditorsLocalizer
Public Shared Sub Activate()
Dim localizer As New MyEditorsLocalizer()
Dim provider As DefaultActiveLocalizerProvider(Of ASPxEditorsStringId) = _
New DefaultActiveLocalizerProvider(Of ASPxEditorsStringId)(localizer)
MyEditorsLocalizer.SetActiveLocalizerProvider(provider)
End Sub
Public Overrides Function GetLocalizedString(ByVal id As ASPxEditorsStringId) As String
Dim result As String = MyBase.GetLocalizedString(id)
Return String.Format("editors:{0}", result)
End Function
End Class
Public Class MyWebLocalizer
Inherits ASPxperienceLocalizer
Public Shared Sub Activate()
Dim localizer As New MyWebLocalizer()
Dim provider As DefaultActiveLocalizerProvider(Of ASPxperienceStringId) = _
New DefaultActiveLocalizerProvider(Of ASPxperienceStringId)(localizer)
MyWebLocalizer.SetActiveLocalizerProvider(provider)
End Sub
Public Overrides Function GetLocalizedString(ByVal id As ASPxperienceStringId) As String
Dim result As String = MyBase.GetLocalizedString(id)
Return String.Format("web:{0}", result)
End Function
End Class
End Namespace