How to realize dynamic switching between multiple languages in WPF?

How to realize dynamic switching between multiple languages in WPF?

After reading the previous article "C#Multi-Language Tool- ResX Manager", some netizens asked: This multi-language switch cannot be restarted and cannot be refreshed. Is there any solution?

最后更新 2/17/2021 9:28 AM
沙漠尽头的狼
预计阅读 2 分钟
分类
WPF
标签
.NET C# WPF internationalization multilingual

有网友看了上一篇文章《C# 多语言利器 - ResX Manager》后,提出疑问:

This multi-language switch cannot be restarted and cannot be refreshed. Is there any solution?

不重启多语言切换有方案吗?

In fact, there is. A domestic open source god provided a WPF extension library, which includes multi-language switching. Let's see the effect first:

动态多语言切换展示

For specific use, please continue to read:

1 Open source library enables dynamic switching between multiple languages

GitHub 地址:点击访问

WpfExtensions仓库详情

How to install?

You can search and install directly by NuGet:

NuGet搜索安装

2 How to use it?

2.1 Before initialization of the main project

Add resource file references

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

2.2 Initialization in the Prism module

如果使用Prism实现模块化,也需要在模块构造函数中引用模块的资源文件

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

Dynamic language switching

It is more flexible here. When switching languages, save the language identification in the configuration file. Just set the configured language when the program starts. When switching languages dynamically, the same code is used:

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

3 Multi-language reference items

Keep Exploring

延伸阅读

更多文章
同分类 / 同标签 1/26/2025

WPF internationalizes with custom XML files

This article describes in detail the methods of using custom XML files to achieve internationalization in WPF programs, including installing the necessary NuGet package, dynamically obtaining language lists, dynamically switching languages, using translation strings in code and xaml interfaces, etc. It also provides source code links to help developers easily internationalize WPF applications.

继续阅读