Localization in .NET MAUI Time Picker (SfTimePicker)
4 Oct 20231 minute to read
Localization is the process of translating the application resources into different language for the specific cultures. The SfTimePicker
can be localized by adding resource
file. In SfTimePicker
, provides the support to localize the below strings
Hour
Minute
Second
Meridiem
OK
Cancel
Setting CurrentUICulture to the application
Application culture can be changed by setting CurrentUICulture.
in App.xaml.cs
file.
using Syncfusion.Maui.Picker;
using System.Globalization;
using System.Resources;
namespace TimePicker;
public partial class App : Application
{
public App()
{
InitializeComponent();
CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");
//// ResXPath => Full path of the resx file; For example : //SfPickerResources.ResourceManager = new ResourceManager
// ("TimePicker.Resources.SfTimePicker", Application.Current.GetType().Assembly);
SfPickerResources.ResourceManager = new ResourceManager("ResxPath", Application.Current.GetType().Assembly);
MainPage = new MainPage();
}
}
NOTE
The required
resx
files withBuild Action
asEmbeddedResource
(File name should contain culture code) into theResources
folder.
Localize application level
To localize the TimePicker
based on CurrentUICulture
using resource
files, follow the below steps.
-
Create new folder, named as
Resources
in the application. -
Right-click on the
Resources
folder, selectAdd
and thenNewItem.
-
In Add New Item wizard, select the Resource File option and name the filename as
SfTimePicker.<culture name>.resx.
For example, give the name asSfTimePicker.fr-FR.resx
for French culture. -
The culture name indicates the name of the language and country.
-
Now, select
Add
option to add the resource file in Resources folder. -
Add the Name/Value pair in Resource Designer of
SfTimePicker.fr-FR.resx
file and change its corresponding value to corresponding culture.