Localization in WPF DataGrid (SfDataGrid)

7 Sep 20232 minutes to read

Localization is the process of translating the application resources into different language for the specific cultures. You can localize the SfDataGrid by adding resource file. Application culture can be changed by setting CurrentUICulture before InitializeComponent() method.

Below application culture changed to German.

public MainWindow()
{
    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");

    InitializeComponent();
}

To localize the SfDataGrid based on CurrentUICulture using resource files, follow the below steps.

1.Create new folder and named as Resources in your application.
2.Add the default resource file of SfDataGrid into Resources folder. You can download the Syncfusion.SfGrid.WPF.resx here.

Displaying Default Resource File of WPF DataGrid into Resources Folder

3.Right-click on the Resources folder, select Add and then NewItem.

4.In Add New Item wizard, select the Resource File option and name the filename as Syncfusion.SfGrid.WPF.<culture name>.resx. For example, you have to give name as Syncfusion.SfGrid.WPF.de.resx for German culture.

5.The culture name that indicates the name of language and country.

Changing name of New Resource File for WPF DataGrid

6.Now, select Add option to add the resource file in Resources folder.

Displaying Resource File with German Language for WPF DataGrid

7.Add the Name/Value pair in Resource Designer of Syncfusion.SfGrid.WPF.de.resx file and change its corresponding value to corresponding culture.

Displaying Added Resource File Name and Value pair in WPF DataGrid

Displaying Localized File in German for WPF DataGrid

You can get the sample from here

Localize when the resource file present in different assembly or different namespace?

By default, SfDataGrid try to read the resource file from executing assembly and its default namespace by using Assembly.GetExecuteAssembly method. When the resource file is located at different assembly or namespace, then you can let SfDataGrid know by using GridResourceWrapper.SetResources method.

public MainWindow()
{
    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");            
    Syncfusion.UI.Xaml.Grid.GridResourceWrapper.SetResources("Assembly_name", "namespace_name");
    InitializeComponent();
}

Editing default culture resource

You can edit default resource file by adding it to Resources folder of your application where SfDataGrid reads the static texts from here. You can download the default resource file from here.

Displaying Default Culture Resource File Editing for WPF DataGrid

Now, change the Name/Value pair in Resource Designer of Syncfusion.SfGrid.WPF.resx file.

Displaying Name and Value pair in Resource Designer for Default Culture in WPF DataGrid

WPF DataGrid displays Editing Default Culture Resource