How to implement dynamic language switching in WPF?

How to implement dynamic language switching in WPF?

After reading the previous article 'C# Multi-language Tool - ResX Manager', a netizen asked: This multi-language switching cannot refresh without restarting, is there a solution?

Last updated 2/17/2021 9:28 AM
沙漠尽头的狼
2 min read
Category
WPF
Tags
.NET C# WPF Internationalization Multi-language

Some netizens who read the previous article "C# Multi-language Tool - ResX Manager" raised a question:

Is there a solution for multi-language switching without restarting, so that it can refresh?

Is there a solution for multi-language switching without restarting?

Actually, there is. A domestic open-source guru provided a WPF extension library that includes a multi-language switching implementation. Let's first see the effect:

Dynamic multi-language switching demo

For specific usage, please read on:

1 Open-source library for dynamic multi-language switching

GitHub link: Click here

WpfExtensions repository details

How to install?

Just search and install via NuGet:

NuGet search and install

2 How to use?

2.1 Before main project initialization

Add a reference to the resource file

I18nManager.Instance.Add(LQClass.AdminForWPF.I18nResources.UiResource.ResourceManager);

2.2 Initialization in Prism modules

If using Prism for modularization, also reference the module's resource file in the module constructor

I18nManager.Instance.Add(LQClass.ModuleOfLog.I18nResources.UiResource.ResourceManager);

Dynamic language switching

This is quite flexible. When switching languages, save the language identifier to the configuration file. Set the configured language when the program starts. The same code is used for dynamic language switching:

var culture = new System.Globalization.CultureInfo(language);
I18nManager.Instance.CurrentUICulture = culture;

3 Multi-language reference projects

Keep Exploring

Related Reading

More Articles
Same category / Same tag 1/26/2025

Implementing Internationalization in WPF Using Custom XML Files

This article details the method of implementing internationalization in WPF applications using custom XML files, including installing the necessary NuGet packages, dynamically retrieving the language list, dynamically switching languages, using translated strings in code and XAML interfaces, and provides a source code link to help developers easily achieve internationalization in WPF applications.

Continue Reading