Localization
This tutorial describes the localization support implemented in the RadDiagram elements
Localization Using ResourceManager
You can base your localization on the standard resource files provided by the .NET framework. For that purpose you will have to create a separate .ResX file for each one of the languages that your application will support.
Imagine that you want to translate your diagramming implementation into English and German. For that purpose you will have to add two new resource files to your project:
DiagramResources.resx - this resource file will store the English(default) resources for the grid control. Set the AccessModifier property to Public.
DiagramResources.de.resx - this resource file will store the German resources for the grid control. Set the AccessModifier property to No code generation.
Now, having the needed files, it's time to illustrate the idea and localize only the text for the group panel. For that purpose you need to create a single resource string in each one of the three resource files and translate it to the appropriate language.
Note that the name of the resource string should be the same as the resource key for the string that you are localizing. The resource key for the diagram rotation thumb tooltip is Diagram_Rotate.
For a full list of ResourceKeys, check out the LocalizationStrings section of this article.
The snapshot below shows the content of the DiagramResources.de.resx file. The resource name of the other file should be the same. The Value column will contain the translation for the appropriate language.
The last step is to instantiate the LocalizationManager class and set its ResourceManager to the resources that have been just created (you can do this in the default constructor of the Application class).
LocalizationManager.Manager = new LocalizationManager()
{
ResourceManager = DiagramResources.ResourceManager
};
LocalizationManager.Manager = New LocalizationManager()
LocalizationManager.Manager.ResourceManager = DiagramResources.ResourceManager
If you rely on culture settings to load the right resources automatically, you have to write some code inside your application's project file. For example, if you have to support English and German languages, you can store the localized strings in Resources.resx and Resources.de.resx files. For the Resources.resx file you can set ResXFileCodeGenerator to Internal or Public and for the others - to No code generation. Then, open the project file in a text-mode and insert the code below into the
section. In this way you notify the framework about the supported cultures.
<SupportedCultures>en;de</SupportedCultures>
Localization Using Custom Localization Manager
The other way to localize your RadDiagram is to create a class that derives from the LocalizationManager object and to override its method GetStringOverride(). The logic is pretty simple, you just have to create a switch statement and return the correct translation for each resource key, as it is shown below:
public class CustomLocalizationManager : LocalizationManager
{
public override string GetStringOverride(string key)
{
switch (key)
{
case "Diagram_Rotate":
return "Rotate";
case "Auto_fit":
return "Auto Fit";
//SettingsPane parts localization strings
case "SettingsPane_SizeTab":
return "Size";
case "SettingsPane_HomeTab":
return "Home";
case "SettingsPane_Copy":
return "Copy";
case "SettingsPane_Cut":
return "Cut";
case "SettingsPane_Paste":
return "Paste";
case "SettingsPane_Delete":
return "Delete";
}
return base.GetStringOverride(key);
}
}
Public Class CustomLocalizationManager
Inherits LocalizationManager
Public Overrides Function GetStringOverride(key As String) As String
Select Case key
Case "Diagram_Rotate"
Return "Rotate"
Case "Auto_fit"
Return "Auto Fit"
'SettingsPane parts localization strings
Case "SettingsPane_SizeTab"
Return "Size"
Case "SettingsPane_HomeTab"
Return "Home"
Case "SettingsPane_Copy"
Return "Copy"
Case "SettingsPane_Cut"
Return "Cut"
Case "SettingsPane_Paste"
Return "Paste"
Case "SettingsPane_Delete"
Return "Delete"
End Select
Return MyBase.GetStringOverride(key)
End Function
End Class
Of course, if you don't want to hard-code your translation inside your source code, you can always use resource files:
public override string GetStringOverride(string key)
{
switch (key)
{
//----------------------
case "Diagram_Rotate":
return DiagramResources.Diagram_Rotate;
//----------------------
}
return base.GetStringOverride(key);
}
Public Overrides Function GetStringOverride(key As String) As String
Select Case key
'----------------------'
Case "Diagram_Rotate"
Return DiagramResources.Diagram_Rotate
'----------------------'
End Select
Return MyBase.GetStringOverride(key)
End Function
Diagram Localization Strings
In the following snapshots you can find a list of all Diagram localization strings: