多语言管理服务Demo
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-05-29 10:20:15 +00:00
SiriusInspection.Localization 添加图例 2026-05-29 18:19:27 +08:00
.gitignore 初版提交 2026-04-24 14:35:07 +08:00
LICENSE Initial commit 2025-06-05 01:37:44 +00:00
README.md 更新 'README.md' 2026-05-29 10:20:15 +00:00

SiriusInspection.Localization

多语言管理示例程序

1.运行效果

英文
English

中文
Chinese

2.运行环境

.Net 10.0/WPF/MVVM

3.调用方法

1.安装ResxManager扩展

Chinese

2.添加项目引用

Chinese

3.在项目中添加资源文件后,使用ResXManager扩展管理字典

Chinese

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 ---- ----