RadControls for Silverlight

The built-in localization mechanism in Silverlight and WPF allows you to localize any string resource used by the standard RadRibbonBar control. Once translated you might use your resources in both Silverlight and WPF projects without changing anything.

LocalizationManager

The Telerik.Windows.Controls.LocalizationManager allows you to easily localize any of the Telerik controls.

To apply custom localization to your controls just instantiate your custom LocalizationManager and set it to the static property LocalizationManager.Manager, before the creation of the UI.

CopyC#
LocalizationManager.Manager = new CustomLocalizationManager();
CopyVB.NET
LocalizationManager.Manager = New CustomLocalizationManager()
Note
Note that you have to set the localization manager before the creation of the UI, otherwise some parts might remain not-localized.

Resource Keys

RadRibbonBar is a complex user interface control and its strings for localization are numerous. In order to be able to distinguish these resources, a unique identifier, called resource key, is assigned to each localizable string.

On the picture below you can see some of the resource keys and the strings they are associated with. A complete list of the RadRibbonBar resource keys can be found here.

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 ribbon bar into English, German and Dutch. For that purpose you will have to add three new resource files to your project:

  • RibbonBarResources.resx - this resource file will store the English(default) resources for the ribbon bar control. Set the AccessModifier property to Public.
  • RibbonBarResources.de.resx - this resource file will store the German resources for the ribbon bar control. Set the AccessModifier property to No code generation.
  • RibbonBarResources.nl.resx - this resource file will store the Dutch resources for the ribbon bar control. Set the AccessModifier property to No code generation.

Now, having the needed files, it's time to illustrate the idea and localize for example the 'Minimize the Ribbon', 'Customize Quick Access Tool bar' and 'Show below the Ribbon' strings. For that purpose you need to create three resource strings in each one of the three resource files and translate them to the appropriate language.

Note
Note that the name of the resource string should be the same as the resource key for the string you are localizing i.e. the resource key for 'Minimize the Ribbon' is RibbonBarQATMinimize, for 'Customize QuickAccessToolbar' is RibbonBarQATCustomize and for 'Show below the Ribbon' is RibbonBarQATShowBelow.

The snapshot below shows the content of the RibbonBarResources.de.resx file. The resource name of the other two files should be the same. Only 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.

CopyC#
LocalizationManager.Manager = new LocalizationManager()
{
    ResourceManager = RibbonBarResources.ResourceManager
};
CopyVB.NET
LocalizationManager.Manager = New LocalizationManager()
LocalizationManager.Manager.ResourceManager = RibbonBarResources.ResourceManager
Note

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 Dutch languages, you can store the localized strings in Resources.resx and Resources.nl.resx files. For the Resources.resx file you can set ResXFileCodeGenerator to Internal or Public and for others to No code generation. Then, open the project file in a text-mode and insert the code below into the <PropertyGroup> section. In this way you notify the framework about the supported cultures.

CopyXML
<SupportedCultures>en;nl</SupportedCultures>

Here is how the localized RadRibbonBar looks like:

Localization Using Custom Localization Manager

The other way to localize your RadRibbonBar control 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:

CopyC#
public class CustomLocalizationManager : LocalizationManager
{
    public override string GetStringOverride( string key )
    {
        switch( key )
        {
            case "RibbonBarQATMinimize":
                return "Minimieren der Multifunktionsleiste";
            case "RibbonBarQATCustomize":
                return "Anpassen Sie die Symbolleiste";
            case "RibbonBarQATShowBelow":
                return "Zeigen unten die Multifunktionsleiste";
        }
        return base.GetStringOverride( key );
    }
}
CopyVB.NET
Public Class CustomLocalizationManager
    Inherits LocalizationManager
    Public Overloads Overrides Function GetStringOverride(ByVal key As String) As String
        Select Case key
            Case "RibbonBarQATMinimize"
                Return "Minimieren der Multifunktionsleiste"
            Case "RibbonBarQATCustomize":
                Return "Anpassen Sie die Symbolleiste"
            Case "RibbonBarQATShowBelow"
                Return "Zeigen unten die Multifunktionsleiste"
        End Select

        Return MyBase.GetStringOverride(key)
    End Function
End Class

Of course, if you don't want to hard-code your translation inside the source code, you can always use resource files:

CopyC#
public override string GetStringOverride( string key )
{
    switch( key )
    {
        //----------------------
        case "RibbonBarQATMinimize":
            return RibbonBarResources.RibbonBarQATMinimize;
        //----------------------
    }
    return base.GetStringOverride( key );
}
CopyVB.NET
Public Overloads Overrides Function GetStringOverride(ByVal key As String) As String
    Select Case key
        '----------------------
        Case "RibbonBarQATMinimize"
            Return RibbonBarResources.RibbonBarQATMinimize
        '----------------------
    End Select
    Return MyBase.GetStringOverride(key)
End Function

RadRibbonBar Resource Keys

The following Resource Keys are available:

  • RibbonBarGalleryButtonMore
  • RibbonBarGalleryButtonUpDown
  • RibbonBarQATCustomize
  • RibbonBarQATMinimize
  • RibbonBarQATShowAbove
  • RibbonBarQATShowBelow
  • RibbonBarWindowTitleDivider

See Also