Skip to main content
A newer version of this page is available. .

Localizing ASP.NET Controls via Localizer Objects

  • 6 minutes to read

Each DevExpress component or library has a specific Localizer class that provides localized strings (see the table below). For example, in the Data Grid control, this is the ASPxGridViewLocalizer class.

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 assemblies. Thus, localization via resources is the preferable solution.

Localization Process

The localization process via custom localizers is as follows.

  • Create a descendant of a corresponding Localizer class and override its GetLocalizedString method, which should return strings for specific string resource identifiers.
  • Define the Activate method, which creates an instance of your custom localizer with a localizer provider, and sets this provider as an 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();
    }
    

The following table lists Localizer classes and Resource String enumerations for DevExpress ASP.NET controls.

Product

Localizer Class

Resource String Enumeration

Namespace

Reporting

ASPxReportsLocalizer

ASPxReportsStringId

DevExpress.XtraReports.Web.Localization

Chart Control

ChartLocalizer

ChartStringId

DevExpress.XtraCharts.Localization

Grid View, Card View, Vertical Grid

ASPxGridViewLocalizer

ASPxGridViewStringId

DevExpress.Web.Localization

Spreadsheet

ASPxSpreadsheetLocalizer

ASPxSpreadsheetStringId

DevExpress.Web.ASPxSpreadsheet.Localization

Rich Text Editor

ASPxRichEditLocalizer

ASPxRichEditStringId

DevExpress.Web.ASPxRichEdit.Localization

Data and Image Navigation

Docking and Popups,

Site Navigation and Layout,

File Management,

Multi-Use Site Controls

ASPxperienceLocalizer

ASPxperienceStringId

DevExpress.Web.Localization

Scheduler

ASPxSchedulerLocalizer

ASPxSchedulerStringId

DevExpress.Web.ASPxScheduler.Localization

HTML Editor

ASPxHtmlEditorLocalizer

ASPxHtmlEditorStringId

DevExpress.Web.ASPxHtmlEditor.Localization

Pivot Grid

PivotGridLocalizer

PivotGridStringId

DevExpress.XtraPivotGrid.Localization

Tree List

ASPxTreeListLocalizer

ASPxTreeListStringId

DevExpress.Web.ASPxTreeList.Localization

Gauges

GaugesCoreLocalizer

GaugesCoreStringId

DevExpress.XtraGauges.Core.Localization

Data Editors

ASPxEditorsLocalizer

ASPxEditorsStringId

DevExpress.Web.Localization

Spell Checker

ASPxSpellCheckerLocalizer

ASPxSpellCheckerStringId

DevExpress.Web.ASPxSpellChecker.Localization

Example

The following example demonstrates how to localize the ASPxGridView control via a custom localizer. For another localization approach, refer to Localizing ASP.NET Controls via Satellite Resource Assemblies.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CustomLocalizer._Default" %>

<%@ Register Assembly="DevExpress.Web.v15.2, Version=15.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web" TagPrefix="dxe" %>

<%@ Register Assembly="DevExpress.Web.v15.2, Version=15.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web" TagPrefix="dxwgv" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>How to use a custom ASPxGridView localizer</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <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:GridViewCommandColumn>
                <dxwgv:GridViewDataTextColumn FieldName="ID" VisibleIndex="1" Width="150px">
                </dxwgv:GridViewDataTextColumn>
            </Columns>
            <Settings ShowFilterBar="Visible" ShowFilterRow="True" ShowGroupPanel="True" />
        </dxwgv:ASPxGridView>
    </div>
    </form>
</body>
</html>