Localization in WinUI DataGrid (SfDataGrid)

1 Apr 2021 / 2 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 MainPage()
{
    CultureInfo.CurrentUICulture = new CultureInfo("de");

    InitializeComponent();
}

Creating .resw files

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

NOTE

You can get the default resource files of all Syncfusion WinUI libraries from GitHub.

1) Right click your project and add new folder named Resources.

2) Add another folder and name the folder name as culture name. For example, you have to give name as de for German culture. Find the supported culture codes from here

3) Add default resource files in the following structure.

Resw file in WinUI DataGrid

4) Now, you can define the key names from default resource files and assign value based on the culture.

Localization in WinUI DataGrid

Shows the localized in German for WinUI DataGrid

5) Also, localize application text in XAML using below steps

5a) Add resource name in .resx file

Localize application text in WinUI DataGrid

5b) Refer the mentioned resource name in XAML like below.

xmlns:grid="using:Syncfusion.UI.Xaml.Grids"
xmlns:dataGrid="using:Syncfusion.UI.Xaml.DataGrid"

<dataGrid:SfDataGrid x:Name="sfDataGrid"
                       AddNewRowPosition="Top"
                       AutoGenerateColumns="False"
                       ItemsSource="{Binding Orders}">
    <dataGrid:SfDataGrid.Columns>
        <dataGrid:GridTextColumn HeaderText="{grid:GridLocalizationResourceExtension ResourceName=OrderIDText}" MappingName="OrderID" TextAlignment="Right"/>
        <dataGrid:GridTextColumn HeaderText="{grid:GridLocalizationResourceExtension ResourceName=CustomerIDText}" MappingName="CustomerID" />
        <dataGrid:GridTextColumn HeaderText="{gGrid:GridLocalizationResourceExtension ResourceName=CustomerNameText}" MappingName="CustomerName" />
        <dataGrid:GridTextColumn HeaderText="{grid:GridLocalizationResourceExtension ResourceName=CountryText}" MappingName="Country" />
        <dataGrid:GridTextColumn HeaderText="{grid:GridLocalizationResourceExtension ResourceName=UnitPriceText}" MappingName="UnitPrice" TextAlignment="Right"/>
    </dataGrid:SfDataGrid.Columns>
</dataGrid:SfDataGrid>

Shows the localized application text in German for WinUI DataGrid

Editing default culture resource

You can change the default string of datagrid control by adding the default .resw files (from GitHub) to Resources folder of your application. Syncfusion WinUI controls reads the default string from the .resw files of application if its added.