MultiLanguageForXAML 2.3.0.2

dotnet add package MultiLanguageForXAML --version 2.3.0.2                
NuGet\Install-Package MultiLanguageForXAML -Version 2.3.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MultiLanguageForXAML" Version="2.3.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MultiLanguageForXAML --version 2.3.0.2                
#r "nuget: MultiLanguageForXAML, 2.3.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MultiLanguageForXAML as a Cake Addin
#addin nuget:?package=MultiLanguageForXAML&version=2.3.0.2

// Install MultiLanguageForXAML as a Cake Tool
#tool nuget:?package=MultiLanguageForXAML&version=2.3.0.2                

MultiLanguageForXAML

针对 WPF 的多语言支持库

Nuget

效果预览

  • WPF

steup

用法

  • 定义语言文件
//Languages/zh.json 编译时拷贝到目录
    {
    "txt": "一",
    "format":"你好 {0} !",
    "world":"世界"
    }

//Languages/en.json 编译时拷贝到目录
    {
    "txt": "one",
    "format":"hello {0} !",
    "world":"world"
    }

  • 初始化
//WPF
//怀疑用Environment.CurrentDirectory开机启动时目录会出错,待验证
string appDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string path = Path.Combine(appDir, "Res\\Languages");
LanService.Init(new JsonFileDB(path), true,"zh");
//嵌入模式
//LanService.Init(new EmbeddedJsonDB("Samples.WPF.EmbeddedConfig.Languages"), true, "en");
  • XAML

<Window
    ...
    xmlns:lan="clr-namespace:MultiLanguageForXAML;assembly=MultiLanguageForXAML">
    <StackPanel>
        <Button lan:Xaml.Key="txt" />
        <Button lan:Xaml.Key="format">
            <lan:Xaml.Parameters>
                <lan:FormatParameters>
                    <Run
                        lan:Xaml.Key="world"
                        FontStyle="Italic"
                        Foreground="Red" />
                </lan:FormatParameters>
            </lan:Xaml.Parameters>
        </Button>
    </StackPanel>
</Window/>

  • 切换语言
//WPF
LanService.UpdateCulture("en");
  • 自定义控件映射(可选)
Xaml.CustomMaps.Add(typeof(CustomTitleBar), CustomTitleBar.TitleProperty);

广而告之

应用推荐

全栈开发QQ群:191034956

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on MultiLanguageForXAML:

Package Downloads
JsonConfiger

根据JSON生成WPF/UWP配置界面

GiantappConfiger

懒人专用配置界面生成器,根据传入对象自动生成UI界面 giantapp.cn mscoder.cn

DotNetUtil.Common.Apps

Package Description

JsonConfiger.WPF

mscoder.cn

Common.Apps

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.0.2 370 11/13/2023
2.3.0.1 163 10/9/2023
2.3.0 132 10/9/2023
2.2.0 474 8/8/2022
2.1.8 424 6/28/2022
2.1.7 436 5/20/2022
2.1.6 503 1/28/2022
2.1.5 443 1/28/2022
2.1.4 432 1/28/2022
2.1.3 442 1/28/2022
2.1.0 465 1/28/2022
2.0.6.1 404 3/22/2022
2.0.5.1 876 9/26/2019
2.0.3 1,591 9/9/2019
2.0.2.5 902 8/14/2019
2.0.2.4 550 8/14/2019
2.0.2.3 521 8/14/2019
2.0.2.2 519 8/14/2019
2.0.2 542 8/14/2019
2.0.0 759 6/4/2019
1.0.0.21 671 4/28/2019
1.0.0.20 563 4/29/2019
1.0.0.19 561 4/29/2019
1.0.0.18 875 8/31/2018
1.0.0.15 737 8/29/2018
1.0.0.13 770 8/29/2018
1.0.0.11 826 8/7/2018
1.0.0.10 770 8/3/2018