多语言管理服务Demo
- C# 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| SiriusInspection.Localization | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
SiriusInspection.Localization
多语言管理示例程序
1.运行效果
2.运行环境
.Net 10.0/WPF/MVVM
3.调用方法
1.安装ResxManager扩展
2.添加项目引用
3.在项目中添加资源文件后,使用ResXManager扩展管理字典
4.调用
- Step 1:应用程序入口调用
using CP.Localisation;
public partial class App : Application
{
public App() {
CultureManager.ChangeCulture("zh-CN");
}
}
- Step 2:在MainWinodwView.xaml文件添加如下声明
xmlns:loc="clr-namespace:CP.Localisation;assembly=SiriusInspection.Localization"
Language="{UICulture}"
loc:ResxExtension.DefaultResxName="CP.Properties.Resources"
- Step 3:前端调用
<TextBlock Text="{Resx 测试}" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
- Step 4:后端调用
[RelayCommand]
public void SendMsg() {
LogContent += $"[{DateTime.Now:HH:mm:ss}] {Resources.测试}!\n";
}
- Step 4:Converter实现及前后端调用方式
using CP.Localisation;
using CP.Properties;
public class StringTranslateConverter : IValueConverter
{
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string resourceKey)
{
return Resources.ResourceManager.GetString(resourceKey, CultureManager.UICulture) ?? $"{resourceKey}";
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
前端
<TextBlock Text="{Binding Name, Converter={StaticResource StringTranslateConverter}}"/>
后端
TextBlock textBlock = new TextBlock();
textBlock.Text = Resources.ResourceManager.GetString(name, CultureManager.UICulture) ?? name;
Binding binding = new Binding(".") { Converter = new StringTranslateConverter() };
4.遗留问题
| 序号 | 问题描述 | 解决措施 |
|---|---|---|
| 1 | ---- | ---- |




