New to Telerik UI for WPF? Download free 30-day trial

Localization

The built-in localization mechanism in Silverlight and WPF (which is available since Q2 2011) allows you to localize any string resource used by the standard RadTimeBar control. Once translated you might use your resources in both Silverlight and WPF projects without changing anything.

Localization using Resource Manager

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 schedule control into English and German. For that purpose you will have to add two new resource files to your project:

  • RadTimeBarResources.resx - this resource file will store the English(default) resources for the ScheduleView control. Set the AccessModifier property to Public.

  • RadTimeBarResources.de.resx - this resource file will store the German resources for the TimeBar 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 text for the Day, Week, Month and Quarter navigation strings. For that purpose you need to create four resource strings in each one of the resource files and translate them to the appropriate language.

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 the Day is Day, for the Week is Week, for Month is Month and for the Quarter is Quarter.

The snapshot below shows the content of the RadTimeBarResources.de.resx file. The Value column will contain the translation for the appropriate language:

WPF RadTimeBar Localization Resources

The last step is to instantiate the LocalizationManager class and set its ResourceManager to the resources that have been just created.

Example 1: Setting ResourceManager

LocalizationManager.Manager = new LocalizationManager() 
{ 
  ResourceManager = RadTimeBarResource.ResourceManager 
}; 
LocalizationManager.Manager = New LocalizationManager() 
LocalizationManager.Manager.ResourceManager = ScheduleViewResources.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 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

Example 2: Adding supported cultures

<SupportedCultures>en;de</SupportedCultures> 

To see the RadTimeBar localized in German for example you should set the CurrentCulture and CurrentUICulture in App.xaml.cs/ App.xaml.vb like this:

Example 3: Setting the application's culture

CultureInfo culture = new CultureInfo("de"); 
System.Threading.Thread.CurrentThread.CurrentCulture = culture; 
System.Threading.Thread.CurrentThread.CurrentUICulture = culture; 
Dim culture As New CultureInfo("de") 
System.Threading.Thread.CurrentThread.CurrentCulture = culture 
System.Threading.Thread.CurrentThread.CurrentUICulture = culture 

Here is how the localized RadTimeBar will look like:

WPF RadTimeBar Localized

Localization Using Custom Localization Manager

The other way to localize your RadTimeBar 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 for German language:

Example 4: Creating custom LocalizationManager

public class CustomLocalizationManager : LocalizationManager 
{ 
    public override string GetStringOverride(string key) 
    { 
        switch (key) 
        { 
            case "Day": 
                return "Tag"; 
            case "Week": 
                return "Woche"; 
            case "Month": 
                return "Monat"; 
            case "Quarter": 
                return "Quartal"; 
        } 
        return base.GetStringOverride(key); 
    } 
} 
Friend Class CustomLocalizationManager Inherits LocalizationManager 
Public Overrides Function GetStringOverride(ByVal key As String) As String 
   Select Case key 
          Case "Day" 
               Return "Tag" 
          Case "Week" 
               Return "Woche" 
          Case "Month" 
               Return "Monat" 
          Case "Quarter" 
               Return "Quartal" 
    End Select 
Return MyBase.GetStringOverride(key) 
End Function 
End Class 

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.

Example 5: Setting the localization manager

LocalizationManager.Manager = new CustomLocalizationManager(); 
LocalizationManager.Manager = New CustomLocalizationManager() 

Note that you have to set the localization manager before the creation of the UI, otherwise some parts might remain not-localized.

Using Built-In Resources

RadTimeBar provides you with built-in resources for several cultures: Spanish, German, Italian, Turkish, Dutch.

To change the default culture, you should set the CurrentCulture and the CurrentUICulture of the CurrentThread. Note that this must happen in the code-behind of your Application (App.xaml.cs/ App.xaml.vb) file, right before the UI initialization. The next code-snippet shows you how to change the CurrentCulture to Dutch.

Example 6: Setting the current culture to Dutch

public App() 
{ 
  System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de"); 
  System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de"); 
  this.Startup += this.Application_Startup; 
  this.Exit += this.Application_Exit; 
  this.UnhandledException += this.Application_UnhandledException; 
  InitializeComponent(); 
} 
Public Sub New() 
   System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("de") 
   System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("de") 
   Me.Startup += Me.Application_Startup 
   Me.Exit += Me.Application_Exit 
   Me.UnhandledException += Me.Application_UnhandledException 
   InitializeComponent() 
End Sub 

RadTimeBar Resource Keys

The following Resource Keys are available:

  • Century
  • DecadeEnding
  • Quarter
  • QuarterShort
  • Week
  • WeekShort
In this article