How to Localize
The LocalizationManager class represents a singleton class that manages application string resources and supports two ways to change the localization in the current assembly:
- Using StringLoader - with highest priority
- Using resource map
For a complete list of all localizable keys, see the Localization Keys topic for each control.
Localization Using StringLoader
The following example demonstrates how to create and use a StringLoader. Let's say you want to change the value of the key "Drag a column header here to group" on the RadDataGrid to "Telerik Group":
- First you need to create a class that inherits from the IStringResourceLoader interface and implement the GetString() method that accepts the key you want to change and return the value you want to set.
You will need to add the following namespace : Telerik.Core
Example 1: Implement IStringResourceLoader
public class TelerikStringLoader : IStringResourceLoader
{
public string GetString(string key)
{
switch (key)
{
case "DragToGroup":
return "Custom String Here";
default:
return null;
}
}
}
Example 2: Set StringLoader Property
public App()
{
LocalizationManager.Instance.StringLoader = new TelerikStringLoader();
}
Here you can see the changed result:
Localize using Resource Files
The following example demonstrates how to create a resource file and change the DragToGroup key of RadDataGrid control to "Telerik Drag to Group". Here are the required steps:
- Create a new resource file:
- Open the file you just created and you will see a table with three columns: Name, Value and Comment.
- "Name" is the field where you have to put the key you want to change.
- "Value" is the field where you have to set the value you want.
- The "Comment" field is for comments which are not required.
- Set the value of the "DragToGroup" key to "Telerik Drag to Group" and save the file:
- Finally, you have to assign your resource file to the resource map of the application in the code behind.
Example 3: Load Custom Resource File
public App()
{
this.InitializeComponent();
LocalizationManager.Instance.UserResourceMap = LocalizationManager.Instance.ResourceManager.MainResourceMap.GetSubtree("MyResources");
}