Back to Devexpress

Localizer Objects

aspnet-12048-localization-localizer-objects.md

latest15.6 KB
Original Source

Localizer Objects

  • Oct 29, 2020
  • 5 minutes to read

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.

Localization Process

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.

Localization Classes

The table below lists the following classes related to localization functionality:

  • Localizer Class allows you to access default (en) culture resource string values and override them at runtime.
  • Resource Localizer Class allows you to access localized resource string values and override them at runtime.
  • Resource String Enumeration contains strings that can be localized for the control or library.

|

Product

|

Localizer Class

|

Resource Localizer Class

|

Resource String Enumeration

| | --- | --- | --- | --- | |

Card View

|

ASPxGridViewLocalizer

|

ASPxGridViewResLocalizer

|

ASPxGridViewStringId

| |

Chart Control

|

ChartLocalizer

|

ChartResLocalizer

|

ChartStringId

| |

Data and Image Navigation

|

ASPxperienceLocalizer

|

ASPxperienceResLocalizer

|

ASPxperienceStringId

| |

Data Editors

|

ASPxEditorsLocalizer

|

ASPxEditorsResLocalizer

|

ASPxEditorsStringId

| |

Diagram

|

ASPxDiagramLocalizer

|

ASPxDiagramResourcesLocalizer

|

ASPxDiagramStringId

| |

Docking and Popups

|

ASPxperienceLocalizer

|

ASPxperienceResLocalizer

|

ASPxperienceStringId

| |

Gantt

|

ASPxGanttLocalizer

|

ASPxGanttResourcesLocalizer

|

ASPxGanttStringId

| |

Gauges

|

GaugesCoreLocalizer

|

GaugesCoreResXLocalizer

|

GaugesCoreStringId

| |

Grid View

|

ASPxGridViewLocalizer

|

ASPxGridViewResLocalizer

|

ASPxGridViewStringId

| |

File Management

|

ASPxperienceLocalizer

|

ASPxperienceResLocalizer

|

ASPxperienceStringId

| |

HTML Editor

|

ASPxHtmlEditorLocalizer

|

ASPxHtmlEditorResLocalizer

|

ASPxHtmlEditorStringId

| |

Multi-Use Site Controls

|

ASPxperienceLocalizer

|

ASPxperienceResLocalizer

|

ASPxperienceStringId

| |

Pivot Grid

|

PivotGridLocalizer

|

ASPxPivotGridResLocalizer

|

PivotGridStringId

| |

Reporting

|

ASPxReportsLocalizer

|

ASPxReportsResLocalizer

|

ASPxReportsStringId

| |

Rich Text Editor

|

ASPxRichEditLocalizer

|

ASPxRichEditResourcesLocalizer

|

ASPxRichEditStringId

| |

Scheduler

|

ASPxSchedulerLocalizer

|

ASPxSchedulerResLocalizer

|

ASPxSchedulerStringId

| |

Site Navigation and Layout

|

ASPxperienceLocalizer

|

ASPxperienceResLocalizer

|

ASPxperienceStringId

| |

Spell Checker

|

ASPxSpellCheckerLocalizer

|

ASPxSpellCheckerResLocalizer

|

ASPxSpellCheckerStringId

| |

Spreadsheet

|

ASPxSpreadsheetLocalizer

|

ASPxSpreadsheetResourcesLocalizer

|

ASPxSpreadsheetStringId

| |

Tree List

|

ASPxTreeListLocalizer

|

ASPxTreeListResLocalizer

|

ASPxTreeListStringId

| |

Vertical Grid

|

ASPxGridViewLocalizer

|

ASPxGridViewResLocalizer

|

ASPxGridViewStringId

|

Example

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

aspx
<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>
csharp
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);
        }
    }
}
vb
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