Localization in WinUI TreeGrid (SfTreeGrid)

1 Apr 2021 / 4 minutes to read

Localization is the process of translating the application resources into different language for the specific cultures. You can localize the treegrid 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 SfTreeGrid 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 TreeGrid

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

Localization in WinUI TreeGrid

Shows the localized in German for WinUI TreeGrid

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

5a) Add resource name in .resx file

Localize application text in WinUI TreeGrid

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

xmlns:grid="using:Syncfusion.UI.Xaml.Grids"
xmlns:treeGrid="using:Syncfusion.UI.Xaml.TreeGrid"
xmlns:coreconverter="using:Syncfusion.UI.Xaml.Core"

<Page.Resources>        
    <coreconverter:StringFormatConverter x:Key="stringFormatConverter" />
</Page.Resources>

<treeGrid:SfTreeGrid x:Name="sfTreeGrid"
                       AllowFiltering="True"
                       AutoGenerateColumns="False"
                       ChildPropertyName="Children"            
                       ItemsSource="{Binding Employees}">
    <treeGrid:SfTreeGrid.Columns>                
        <treeGrid:TreeGridTextColumn HeaderText="{grid:GridLocalizationResourceExtension ResourceName=FirstNameText}" MappingName="FirstName" />
        <treeGrid:TreeGridTextColumn HeaderText="{grid:GridLocalizationResourceExtension ResourceName=LastNameText}" MappingName="LastName" />
        <treeGrid:TreeGridTextColumn HeaderText="{grid:GridLocalizationResourceExtension ResourceName=EmployeeIDText}" MappingName="EmpID" TextAlignment="Right" />
        <treeGrid:TreeGridTextColumn
                                DisplayBinding="{Binding Path=DOJ, Converter={StaticResource stringFormatConverter}, ConverterParameter=\{0:dd/MM/yyyy\}}"
                                HeaderText="{grid:GridLocalizationResourceExtension ResourceName=DateofBirthText}"
                                MappingName="DOJ"
                                TextAlignment="Right"/>
        <treeGrid:TreeGridTextColumn MappingName="Salary" 
                                     DisplayBinding="{Binding Salary, Converter={StaticResource stringFormatConverter}, ConverterParameter='{}{0:C}'}"
									 HeaderText="{grid:GridLocalizationResourceExtension ResourceName=SalaryText}"
                                     TextAlignment="Right" />
    </treeGrid:SfTreeGrid.Columns>
</treeGrid:SfTreeGrid>

Shows the localized application text in German for WinUI TreeGrid

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.