Articles in this section
Category / Section

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

1 min read

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: www.syncfusion.com/downloads/support/directtrac/213571/ze/COLORP~1-303420562

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied