![]() |
VOOZH | about |
dotnet add package Antelcat.I18N.Avalonia --version 1.1.2
NuGet\Install-Package Antelcat.I18N.Avalonia -Version 1.1.2
<PackageReference Include="Antelcat.I18N.Avalonia" Version="1.1.2" />
<PackageVersion Include="Antelcat.I18N.Avalonia" Version="1.1.2" />Directory.Packages.props
<PackageReference Include="Antelcat.I18N.Avalonia" />Project file
paket add Antelcat.I18N.Avalonia --version 1.1.2
#r "nuget: Antelcat.I18N.Avalonia, 1.1.2"
#:package Antelcat.I18N.Avalonia@1.1.2
#addin nuget:?package=Antelcat.I18N.Avalonia&version=1.1.2Install as a Cake Addin
#tool nuget:?package=Antelcat.I18N.Avalonia&version=1.1.2Install as a Cake Tool
<div align="center">
<h1>
Antelcat.{I18N}
</h1>
给.NET应用程序提供响应式的多语言支持。
</div>
<p align="center"> <img alt="dotnet-version" src="https://img.shields.io/badge/WPF-%3E%3D4.0-2C896A.svg"/> <img alt="dotnet-version" src="https://img.shields.io/badge/Avalonia-%3E%3D11.0-AE42F8.svg"/> <img alt="csharp-version" src="https://img.shields.io/badge/C%23->=9.0-3BA93F.svg"/> <img alt="nuget" src="https://img.shields.io/badge/Nuget-v1.0.1-blue.svg"/> </p>
🇬🇧
<div float="right"> <img src="docs/demo.zh.png" width="45%"/> <img src="docs/demo.en.png" width="45%"/> </div>
当你在项目中使用.resx文件作为语言文件时,你可以使用Antelcat.I18N.Attributes.ResourceKeysOfAttribute来自动生成资源键:
using Antelcat.I18N.Attributes;
namespace MyProject
//Auto generated class should be partial
[ResourceKeysOf(typeof(My.Resource.Designer.Type))]
public partial class LangKeys
{
}
然后在你的.xaml文件中使用x:Static来为你的控件提供资源键
如果你已经在你的.resx文件中有
<data name="Language" xml:space="preserve">
<value>语言</value>
</data>
你可以像这样使用:
<TextBolck Text="{x:Static myProject:LangKeys.Language}"/>
然后你可以使用这个键来绑定语言源
<TextBlock Text="{I18N {x:Static myProject:LangKeys.Language}}"/>
当你想要改变语言时,只需要调用
using System.Windows;
I18NExtension.Culture = new CultureInfo("language code");
你可以看到文本在语言之间变化。
有时你的源文本并不是在你的应用程序中定义的,而是从其他来源(如网络)接收到的,你可以使用I18N直接绑定文本。
如果你收到了一个像这样的json:
{
"message": "This is a message"
}
并且你已经在.resx中将他翻译成了另一种语言
<data name="This is a message" xml:space="preserve">
<value>这是一条消息</value>
</data>
你肯定会设计一个ViewModel并且将他设置到属性Message中,你可以像这样绑定:
<TextBlock Text="{I18N {Binding Message}}"/>
每当Message属性被改变或者语言源被改变时,文本都会自动更新。
有些情况下,你需要将多个文本组合起来,或者对文本进行格式化,你可以使用I18N和LanguageBinding来实现。
如果你已经有了如下翻译的.resx文件:
<data name="Current_is" xml:space="preserve">
<value>当前的 {0} 是 {1}</value>
</data>
<data name="Language" xml:space="preserve">
<value>语言</value>
</data>
<data name="Chinese" xml:space="preserve">
<value>中文</value>
</data>
并且在.xaml中
<TextBlock>
<TextBlock.Text>
<I18N Key="{x:Static myProject:LangKeys.Current_is}">
<LanguageBinding Key="{x:Static myProject:LangKeys.Language}"/>
<Binding Path="Language"/>
</I18N>
</TextBlock.Text>
</TextBlock>
此时 I18N.Key 是字符串的模板,其中的 LanguageBinding 和 Binding 会提供模板的参数,他们会被按顺序格式化成最终的文本。同时保持整体的响应性。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 1 NuGet packages that depend on Antelcat.I18N.Avalonia:
| Package | Downloads |
|---|---|
|
Shinya.Avalonia.Localization
Shinya.Framework |
Showing the top 1 popular GitHub repositories that depend on Antelcat.I18N.Avalonia:
| Repository | Stars |
|---|---|
|
Milkitic/KeyASIO.Net
An ASIO/WASAPI Exclusive middleware for osu! players. Exploring the limits of low-latency audio.
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 2.0.0-preview-2 | 180 | 5/12/2026 | |
| 2.0.0-preview-1 | 946 | 1/19/2026 | |
| 1.1.2 | 2,222 | 4/14/2025 | |
| 1.1.1 | 341 | 4/14/2025 | |
| 1.1.0 | 411 | 3/1/2025 | |
| 1.0.3 | 1,855 | 5/19/2024 | |
| 1.0.2 | 310 | 4/26/2024 | 1.0.2 is deprecated because it has critical bugs. |
| 1.0.1 | 360 | 12/31/2023 | |
| 1.0.0 | 361 | 12/2/2023 | 1.0.0 is deprecated because it has critical bugs. |
hook avalonia window lifetime & supress key not found