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 255 11/13/2023
2.3.0.1 129 10/9/2023
2.3.0 97 10/9/2023
2.2.0 440 8/8/2022
2.1.8 393 6/28/2022
2.1.7 406 5/20/2022
2.1.6 475 1/28/2022
2.1.5 416 1/28/2022
2.1.4 404 1/28/2022
2.1.3 417 1/28/2022
2.1.0 433 1/28/2022
2.0.6.1 380 3/22/2022
2.0.5.1 846 9/26/2019
2.0.3 1,500 9/9/2019
2.0.2.5 839 8/14/2019
2.0.2.4 527 8/14/2019
2.0.2.3 498 8/14/2019
2.0.2.2 498 8/14/2019
2.0.2 518 8/14/2019
2.0.0 717 6/4/2019
1.0.0.21 645 4/28/2019
1.0.0.20 541 4/29/2019
1.0.0.19 536 4/29/2019
1.0.0.18 835 8/31/2018
1.0.0.15 706 8/29/2018
1.0.0.13 740 8/29/2018
1.0.0.11 797 8/7/2018
1.0.0.10 743 8/3/2018