Localizer Objects

  • 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.

    using DevExpress.Web.Localization;
    using DevExpress.Utils.Localization.Internal;
    ...
    
    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) {...}
    }
    
  • Call the Activate method in the Application_Start event handler within the Global.asax file.

    protected void Application_Start(object sender, EventArgs e) {
         MyEditorsLocalizer.Activate();
    }
    
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.

View Example

<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);
        }
    }
}