We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to dynamically switch between more than one languages through localization?

Platform: WPF |
Control: General |
Published Date: September 25, 2018 |
Last Revised Date: January 29, 2020
Tags: localization

Steps to switch between more than one language dynamically through localization

1. Must include all the resource keywords necessary for the required assembly (For e.g. Syncfusion.Shared.WPF) in the localized resource file and include resource file for all the required languages.

2. While switching between one language to another, controls must be refreshed. To refresh the control, you should apply the resources for that controls by creating ResourceDictionary through code.

In the below code we have override the Office2016Colorful style of ColorPickerPalette control and applied the resource dynamically in Button click event

Example

C#

ResourceDictionary rd = new ResourceDictionary();
private void French_Click(object sender, RoutedEventArgs e)
{
    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR");
    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR");
    ApplyResourceDictionary();
} 
public void ApplyResourceDictionary()
{
    colorPickerPalette.UpdateLayout();
    // To refresh the control dynamically
    rd.Source = new Uri("pack://application:,,,/Office2016Colorful_Overriden.xaml", UriKind.RelativeOrAbsolute);
    this.Resources.MergedDictionaries.Add(rd);
}

VB

Private rd As New ResourceDictionary()
Private Sub French_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("fr-FR")
    System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("fr-FR")
    ApplyResourceDictionary()
End Sub
Public Sub ApplyResourceDictionary()
    colorPickerPalette.UpdateLayout()
    ' To refresh the control dynamically
    rd.Source = New Uri("pack://application:,,,/Office2016Colorful_Overriden.xaml", UriKind.RelativeOrAbsolute)
    Me.Resources.MergedDictionaries.Add(rd)
End Sub

Sample: http://www.syncfusion.com/downloads/support/directtrac/213571/ze/COLORP~1-303420562

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile