How to localize the labels in .NET MAUI Charts (SfCartesianChart)?
Localization is the process of translating the application resources into different languages for specific cultures. The SfCartesianChart can be localized by adding resource file in .NET MAUI Charts.
To localize the Chart based on CurrentUICulture using resource files, follow these steps:
Step 1: Right-click on the Resources folder, select Add, 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 the Add option to add the resource file in the Resources folder.
Step 4: Add the Name/Value pair in the Resource Designer of the SfCartesianChart.it-IT.resx file and change its corresponding value to the corresponding culture.
Step 5: Now, 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 follows.
For better understanding, we attached the GitHub Project for your future reference.
Conclusion
I hope you enjoyed learning how to localize the label in the .NET MAUI Chart (SfCartesianChart).
Refer to our .NET MAUI Chart’s feature tour page to learn about its other groundbreaking feature representations. You can also explore our .NET MAUI Chart documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI from the License and Downloads page. If you are new to Syncfusion, try our 30-day free trial to check out our .NET MAUI Chart and other .NET MAUI components.
Please let us know in the following comments section if you have any queries or require clarifications. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!