Localizing WPF Controls via Localizer Objects

  • 5 minutes to read

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

NOTE

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

Use custom localizers to provide translated strings for localization as follows.

  • Create a descendant of a corresponding Localizer class and override either the GetLocalizedString method (which returns strings for specific string resource identifiers) or PopulateStringTable method (which adds strings for specified resource identifiers).
  • To use this localizer, assign an instance of this class to the static Active property of the localizer class you inherited from.

The following table lists Localizer classes and Resource String enumerations for DevExpress WPF products.

Product

Localizer Class

Resource String Enumeration

Namespace

Data Grid

GridControlLocalizer

GridControlStringId / GridControlRuntimeStringId

DevExpress.Xpf.Grid

PropertyGrid

DevExpress.Xpf.PropertyGrid.PropertyGridControlLocalizer

DevExpress.Xpf.PropertyGrid.PropertyGridControlStringID

DevExpress.Xpf.PropertyGrid

Gantt

DevExpress.Xpf.Gantt.Localization.GanttControlLocalizer

DevExpress.Xpf.Gantt.Localization.GanttControlStringId

DevExpress.Xpf.Gantt.Localization

Docking

DevExpress.Xpf.Docking.Base.DockingLocalizer

DevExpress.Xpf.Docking.Base.DockingStringId

DevExpress.Xpf.Docking.Base

Diagram

DiagramControlLocalizer

DevExpress.Diagram.Core.Localization.DiagramControlStringId

DevExpress.Xpf.Diagram

Toolbar-Menu / Ribbon

BarsLocalizer

DevExpress.Xpf.Bars.BarsStringId

DevExpress.Xpf.Bars

Chart

ChartLocalizer

ChartStringId

DevExpress.Xpf.Charts.Localization

Pivot Grid

PivotGridLocalizer

PivotGridStringId

DevExpress.XtraPivotGrid.Localization

Scheduler

DevExpress.Xpf.Scheduling.Common.SchedulerLocalizer

DevExpress.Xpf.Scheduling.Common.SchedulerStringId

DevExpress.Xpf.Scheduling.Common

Rich Text Editor

DevExpress.Xpf.RichEdit.Localization.XpfRichEditLocalizer

DevExpress.Xpf.RichEdit.RichEditControl.StringId

DevExpress.Xpf.RichEdit.Localization

DevExpress.Xpf.RichEdit

Spreadsheet

DevExpress.Xpf.Spreadsheet.Localization.XpfSpreadsheetLocalizer

DevExpress.Xpf.Spreadsheet.SpreadsheetControlStringId

DevExpress.Xpf.Spreadsheet.Localization

DevExpress.Xpf.Spreadsheet

Gauge Controls

GaugeLocalizer

DevExpress.Xpf.Gauges.Localization.GaugeStringId

DevExpress.Xpf.Gauges.Localization

Dock Windows

DockingLocalizer

DevExpress.Xpf.Docking.Base.DockingStringId

DevExpress.Xpf.Docking.Base

Printing-Exporting

PrintingLocalizer

PrintingStringId

DevExpress.Xpf.Printing

Report Designer

ReportDesignerLocalizer

ReportDesignerStringId

DevExpress.Xpf.Reports.UserDesigner.Localization

Data Editors

EditorLocalizer

EditorStringId

DevExpress.Xpf.Editors

Navigation Bar

NavBarLocalizer

NavBarStringId

DevExpress.Xpf.NavBar

PDF Viewer

PdfViewerLocalizer

PdfViewerStringId

DevExpress.Xpf.PdfViewer

SpellChecker

SpellCheckerLocalizer

DevExpress.XtraSpellChecker.Localization.SpellCheckerStringId

DevExpress.XtraSpellChecker.Localization

Example

The following example demonstrates how to localize the DXGrid control via a custom localizer. For other localization approaches, refer to Localizing WPF Controls via Satellite Resource Assemblies.

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
using DevExpress.Xpf.Grid;

namespace DXGrid_Localization {

    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
            grid.ItemsSource = TaskList.GetData();
        }
        static Window1() {
            GridControlLocalizer.Active = new CustomDXGridLocalizer();
        }

    }

    // Used for populating GridControl with data
    public class TaskList {
        public static List<Task> GetData() {
            List<Task> data = new List<Task>();
            data.Add(new Task() { TaskName = "Complete Project A", StartDate = new DateTime(2009, 7, 1), EndDate = new DateTime(2009, 7, 10) });
            data.Add(new Task() { TaskName = "Test Website", StartDate = new DateTime(2009, 7, 10), EndDate = new DateTime(2009, 7, 12) });
            data.Add(new Task() { TaskName = "Publish Docs", StartDate = new DateTime(2009, 7, 4), EndDate = new DateTime(2009, 7, 6) });
            return data;
        }
    }

    // Used for populating GridControl with data
    public class Task {
        public string TaskName { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
    }

    public class CustomDXGridLocalizer : GridControlLocalizer {
        protected override void PopulateStringTable() {
            base.PopulateStringTable();
            // Changes the caption of the menu item used to invoke the Total Summary Editor.
            AddString(GridControlStringId.MenuFooterCustomize, "Customize Totals");
            // Changes the Total Summary Editor's default caption.
            AddString(GridControlStringId.TotalSummaryEditorFormCaption, "Totals Editor");
            // Changes the default caption of the tab page that lists total summary items.
            AddString(GridControlStringId.SummaryEditorFormItemsTabCaption, "Summary Items");
        }
    }
}