Localizing WPF Controls via Localizer Objects
- 4 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 | |||
PropertyGrid | DevExpress.Xpf.PropertyGrid.PropertyGridControlLocalizer | DevExpress.Xpf.PropertyGrid.PropertyGridControlStringID | |
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 | DevExpress.Diagram.Core.Localization.DiagramControlStringId | ||
Toolbar-Menu / Ribbon | DevExpress.Xpf.Bars.BarsStringId | ||
Chart | |||
Pivot Grid | |||
Scheduler | DevExpress.Xpf.Scheduling.Common.SchedulerLocalizer | DevExpress.Xpf.Scheduling.Common.SchedulerStringId | |
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 | DevExpress.Xpf.Gauges.Localization.GaugeStringId | ||
Dock Windows | DevExpress.Xpf.Docking.Base.DockingStringId | ||
Printing-Exporting | |||
Report Designer | |||
Data Editors | |||
Navigation Bar | |||
PDF Viewer | |||
SpellChecker | DevExpress.XtraSpellChecker.Localization.SpellCheckerStringId | ||
DevExpress.Xpf.Controls.WizardLocalizer | DevExpress.Xpf.Controls.WizardLocalizerStringId |
Examples
Use GridControlLocalizer to Localize the Grid
This example uses the GridControlLocalizer to replace the following GridControl‘s strings:
- Customize… → Customize Totals
- Totals for ‘Column Name’ → Totals Editor
- Items → Summary Items
public partial class MainWindow : Window {
public MainWindow() {
// ...
}
static MainWindow() {
GridControlLocalizer.Active = new CustomDXGridLocalizer();
}
}
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");
}
}
Localize GridControl Strings at Runtime
This example shows how to change the default string displayed in the Group Panel at runtime.
<dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew">
<dxg:GridControl.View>
<dxg:TableView x:Name="view" AutoWidth="True"/>
</dxg:GridControl.View>
</dxg:GridControl>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBox x:Name="textBox" Width="200" KeyDown="textBox_KeyDown" Margin="3,3,3,3"/>
<Button Content="Apply" Click="button_Click" Margin="0,3,0,3"/>
</StackPanel>
void LocalizeGroupPanelText() {
var NewText = textBox.Text;
var localization = new GridRuntimeStringCollection();
localization.Add(new RuntimeStringIdInfo(GridControlRuntimeStringId.GridGroupPanelText, NewText));
view.RuntimeLocalizationStrings = localization;
}
void button_Click(object sender, RoutedEventArgs e) {
LocalizeGroupPanelText();
}
void textBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) {
if (e.Key == System.Windows.Input.Key.Enter) {
LocalizeGroupPanelText();
}
}