Localization in DataGrid (SfDataGrid)

12 Jan 20243 minutes to read

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

Localize at Sample Level

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.SfDataGrid.WinForms.resx here.

Added default resource file of winforms datagrid shown in solution explorer

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.SfDataGrid.WinForms.<culture name>.resx. For example, have to give name as Syncfusion.SfDataGrid.WinForms.de-DE.resx for German culture.

Adding new resource file through Add New Item wizard

5) The culture name that indicates the name of language and country.
6) Now, select Add option to add the resource file in Resources folder.

Added resource file shown in solution explorer

7) Add the Name/Value pair in Resource Designer of Syncfusion.SfDataGrid.WinForms.de-DE.resx file and change its corresponding value to corresponding culture.

Modifying the resources based on culture for localizing winforms datagrid

8) Now, set the CurrentCulture of the Application before the InitializeComponent method and Run the sample.

public Form1()
{
    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");
    InitializeComponent();
}
Public Sub New()
	System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("de-DE")
	System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("de-DE")
	InitializeComponent()
End Sub

Winforms datagrid localized with modified resources

To localize the Select All string in the CheckListBox of the FilterControl, include the resource file of SfListView to the sample using the previously specified steps, like in SfDataGrid.

The default resource file of SfListView can be download from here. Refer to the localization section in SfListView.

Filter control of winforms datagrid localized with modified resources

Editing Default Resource File

The default resource file can be edited by adding it to Resources folder of the application where SfDataGrid reads the static texts from here. The default resource file can be download from here.

Added default resource file of winforms datagrid shown in solution explorer

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

Modifying default resource file of winforms datagrid

Now run the sample,

Winforms datagrid shown with modified resources

Localize Resource File with Different Assembly or 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 it can be set to the SfDataGrid by using SR.SetResources method.

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

    // Set the Custom assembly and namespace for the localization.
    SR.SetResources(typeof(CustomSfDataGrid).Assembly, "SfDataGridExt");
    InitializeComponent();
}
public Form1()
{
    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");

    // Set the Custom assembly and namespace for the localization.
    SR.SetResources(typeof(CustomSfDataGrid).Assembly, "SfDataGridExt");
    InitializeComponent();
}