LinePutScript.Localization.WPF 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package LinePutScript.Localization.WPF --version 1.0.3                
NuGet\Install-Package LinePutScript.Localization.WPF -Version 1.0.3                
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="LinePutScript.Localization.WPF" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LinePutScript.Localization.WPF --version 1.0.3                
#r "nuget: LinePutScript.Localization.WPF, 1.0.3"                
#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 LinePutScript.Localization.WPF as a Cake Addin
#addin nuget:?package=LinePutScript.Localization.WPF&version=1.0.3

// Install LinePutScript.Localization.WPF as a Cake Tool
#tool nuget:?package=LinePutScript.Localization.WPF&version=1.0.3                

LinePutScript.Localization.WPF

<img src="https://github.com/LorisYounger/LinePutScript.Localization.WPF/raw/main/Localization.png" alt="Localization" style="zoom:50%;" />

WPF本地化类库, 轻松让你的wpf应用程序支持多语言

  • 支持文本和数值 - 不同语言的控件位置大小
  • 支持翻译接口 - 用于网络翻译等
  • 支持自动生成所需翻译文档

如何使用

安装

  1. 通过Parckage Manager
Install-Package LinePutScript.Localization.WPF
  1. 通过nuget.org

    LinePutScript.Localization.WPF

在XAML中引用

xmlns:ll="clr-namespace:LinePutScript.Localization.WPF;assembly=LinePutScript.Localization.WPF"

开始翻译


<Label Grid.Row="0" Content="请选择当前语言" Padding="0" VerticalAlignment="Center" Margin="5,0,0,0" />
<Label Grid.Row="5" VerticalAlignment="Center" Padding="0" Margin="5,0,0,0">
    <Run>显示的内容是:</Run> <Run Text="{Binding Text,ElementName=txtInput}" />
</Label>
<Label Content="快捷翻译当前软件" Grid.ColumnSpan="1" FontSize="16" />


<Label Grid.Row="0" Content="{ll:Str 请选择当前语言}" Padding="0" VerticalAlignment="Center" Margin="5,0,0,0" />
<Label Grid.Row="5" Content="{ll:Str 显示的内容是\:{0}, ValueSource={Binding Text,ElementName=txtInput}}" VerticalAlignment="Center" Padding="0" Margin="5,0,0,0" />

<Label Content="{ll:Str 快捷翻译当前软件}" Grid.ColumnSpan="1" FontSize="{ll:Dbe smsize, DefValue=16}" />

简单来讲,就是在原先的基础上多加个 {ll:Str 原先的内容} 就可以了

并且修改是及时显示的, 并不会导致设计器无法查看最新的设计, 所见即所得

image-20230630130456413

支持的翻译类型

类型 描述 类型
Str 文本 String
Bool 布尔 Boolen
Dbe 浮点 Double
Int64 长数字 Long
Int 数字 Int32

添加翻译文档

// 本地化:
// 开启翻译存储, 储存所有未翻译的文本,可以在 LocalizeCore.StoreTranslationList 中查看所有未翻译过的文本
LocalizeCore.StoreTranslation = true;
// 加载所有的本地化语言, 通过 LocalizeCore.AddCulture
foreach (var path in new DirectoryInfo(Environment.CurrentDirectory).GetFiles("*.lps"))
    LocalizeCore.AddCulture(path.Name.Split('.')[0], new LPS_D(File.ReadAllText(path.FullName)));
// 加载当前用户使用的默认语言
LocalizeCore.LoadDefaultCulture();

获取未翻译过的文本

//在初始化之前先 开启翻译存储, 储存所有未翻译的文本
LocalizeCore.StoreTranslation = true;
//打开程序后在所有UI界面逛一遍,接着获取下面这个List里的文本即可
LocalizeCore.StoreTranslationList;
//或者通过下面这个方法获得制作好的LPS格式文件,可以直接储存
LocalizeCore.StoreTranslationListToLPS();

翻译接口

//翻译接口,实现这个方法以支持自定义翻译
LocalizeCore.TranslateFunc = (txt) => {
    //从网络获取翻译等等
    return txt;
}

快捷翻译

通过Demo项目 (可在Release中下载), 可以加载LPS文件进行快速翻译. 例如将翻译文本扔到网络翻译中,然后在复制粘贴回来

image-20230630134103494

详细了解: Demo

详细请参见DEMO文件

其他

附语言表 https://learn.microsoft.com/en-us/windows/win32/wmformat/language-strings

顺带一提, 语言采用的是向上兼容, 不用担心填写 zh-CN 还是 zh-Hans 还是 zh, 均会历遍到

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos 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 (1)

Showing the top 1 NuGet packages that depend on LinePutScript.Localization.WPF:

Package Downloads
VPet-Simulator.Core

虚拟桌宠模拟器 一个开源的桌宠软件, 可以内置到任何WPF应用程序

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on LinePutScript.Localization.WPF:

Repository Stars
LorisYounger/VPet
虚拟桌宠模拟器 一个开源的桌宠软件, 可以内置到任何WPF应用程序
Version Downloads Last updated
1.0.7 1,105 4/20/2024
1.0.6 3,524 7/3/2023
1.0.5 157 7/3/2023
1.0.4 140 7/3/2023
1.0.3 153 6/30/2023
1.0.2 160 6/30/2023
1.0.1 152 6/30/2023
1.0.0 162 6/30/2023

1.0.1: 支持StringFormart
1.0.2: 支持快捷调用
1.0.3: 双项绑定兼容