How To Localize The Labels In .NET MAUI Charts Sfcartesianchart
How-to-localize-the-labels-in-.NET-MAUI-Charts-SfCartesianChart This sample demonstrates how to localize the labels in the chart.Localization is the process of translating the application resources into different language for the specific cultures. The SfCartesianChart can be localized by adding resource file.
To localize the Chart based on CurrentUICulture using resource files, follow the below steps.
Step 1 : Right-click on the Resources folder, select Add and then NewItem.
Step 2 : In Add New Item, select the Resource File option and name the filename as {project name}.{culture name}.resx. For example, give the name as SfCartesianChart.it-IT.resx for Italian culture, The culture name indicates the name of the language and country.
Step 3 : Now, select Add option to add the resource file in Resources folder.
Step 4 : Add the Name/Value pair in Resource Designer of SfCartesianChart.it-IT.resx file and change its corresponding value to corresponding culture.
Step 5 : Now you need to set the CurrentUICulture to the application, the application culture can be changed by setting CurrentUICulture in App.xaml.cs file.
using Syncfusion.Maui.Charts;
using System.Globalization;
using System.Resources;
namespace LocalizeLabels
{
public partial class App : Application
{
public App()
{
InitializeComponent();
CultureInfo.CurrentUICulture = new CultureInfo("it-IT");
var ResXPath = "LocalizeLabels.Resources.SfCartesianChart";
SfCartesianChartResources.ResourceManager = new ResourceManager(ResXPath, Application.Current.GetType().Assembly);
MainPage = new AppShell();
}
}
}
The required resx files with Build Action as EmbeddedResource (File name should contain culture code) into the Resources folder.
By adhering to these instructions, you will obtain the output as specified below.
Conclusion
I hope you enjoyed learning about how to localize the label in the .NET MAUI Chart (SfCartesianChart).
This sample demonstrates how to localize the labels in the chart.Localization is the process of translating the application resources into different language for the specific cultures. The SfCartesianChart can be localized by adding resource file.