Arkheide.Essential.Culture.Avalonia 1.2.0

dotnet add package Arkheide.Essential.Culture.Avalonia --version 1.2.0
                    
NuGet\Install-Package Arkheide.Essential.Culture.Avalonia -Version 1.2.0
                    
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="Arkheide.Essential.Culture.Avalonia" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Arkheide.Essential.Culture.Avalonia" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Arkheide.Essential.Culture.Avalonia" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Arkheide.Essential.Culture.Avalonia --version 1.2.0
                    
#r "nuget: Arkheide.Essential.Culture.Avalonia, 1.2.0"
                    
#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.
#:package Arkheide.Essential.Culture.Avalonia@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Arkheide.Essential.Culture.Avalonia&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Arkheide.Essential.Culture.Avalonia&version=1.2.0
                    
Install as a Cake Tool

Essential.Culture

英文 | 简体中文

Essential.Culture is a JSON-based localization component for .NET.

It manages localization keys in a single Culture.json file, generates strongly typed keys through a Source Generator, and provides runtime culture switching for WPF, Avalonia, and WinUI 3.

Features

  • Culture.json is the conventional JSON file name and is detected automatically.
  • Source generation provides the CultureKey enum and a unified Localize XAML API for strongly typed keys and compile-time validation.
  • KeyBinding allows collection items or runtime state to select localization keys dynamically.
  • Localizer.Parse(...) and Localizer.TryParse(...) resolve localization keys and support format arguments.
  • Localizer.Current provides runtime culture management.

Quick start

Install the appropriate package from NuGet.

For WPF:

dotnet add package Arkheide.Essential.Culture.Wpf

For Avalonia:

dotnet add package Arkheide.Essential.Culture.Avalonia

For WinUI 3:

dotnet add package Arkheide.Essential.Culture.WinUI

For other project types:

dotnet add package Arkheide.Essential.Culture

The package automatically creates Culture.json with default content. You can then define your own keys and translations:

{
  "Greeting": {
    "en-US": "Hello, World!",
    "zh-CN": "你好,世界!"
  },
  "Welcome_User": {
    "en-US": "Hello, {0}!",
    "zh-CN": "你好,{0}!"
  }
}

Start using it

If IntelliSense does not show the generated types yet, build the project once.

WPF uses Localize, and format arguments can use bindings directly:

<Window xmlns:culture="clr-namespace:ArkheideSystem.Essential.Culture">
  <TextBlock Text="{culture:Localize Key=Greeting}" />
  <TextBlock Text="{culture:Localize Key=Welcome_User, Arg0={Binding UserName}}" />
  <TextBlock Text="{culture:Localize KeyBinding={Binding CurrentTextKey}}" />
</Window>

Avalonia uses the same API with different namespace syntax:

<Window xmlns:culture="using:ArkheideSystem.Essential.Culture">
  <TextBlock Text="{culture:Localize Key=Greeting}" />
  <TextBlock Text="{culture:Localize Key=Welcome_User, Arg0={Binding UserName}}" />
  <TextBlock Text="{culture:Localize KeyBinding={Binding CurrentTextKey}}" />
</Window>

Use the strongly typed Key= property so the editor can suggest keys from the generated CultureKey enum. When the key comes from the DataContext or runtime state, use KeyBinding=.

WinUI 3 exposes dynamic arguments through attached properties on the same Localize type:

<Window xmlns:culture="using:ArkheideSystem.Essential.Culture">
  <TextBlock Text="{culture:Localize Key=Greeting}" />
  <TextBlock Text="{culture:Localize Key=Welcome_User}"
             culture:Localize.Argument0="{x:Bind ViewModel.UserName, Mode=OneWay}" />
  <TextBlock Text="{culture:Localize}"
             culture:Localize.KeyBinding="{x:Bind ViewModel.CurrentTextKey, Mode=OneWay}" />
</Window>

Key and KeyBinding cannot be used together. Localize resolves the target text again whenever the static key, dynamic key, format arguments, or current culture changes. Applications do not need to subscribe to culture events themselves.

Source generation

The Generator automatically discovers Culture.json and copies it to the output directory during build and publish. By default, it generates the CultureKey enum, Key tokens, and the Localize static entry point used by UI projects:

namespace ArkheideSystem.Essential.Culture;

public enum CultureKey
{
    Greeting,
}

public static class Key
{
    public static string Greeting => "Key.Greeting";
}
using ArkheideSystem.Essential.Culture;
using GeneratedKey = global::ArkheideSystem.Essential.Culture.Key;

// Print the translated text
Console.WriteLine(Localizer.Parse(GeneratedKey.Greeting));

// Change the current culture
Localizer.Current.SetCulture("zh-CN");

// Print the translated text again without managing culture-change events
Console.WriteLine(Localizer.Parse(GeneratedKey.Greeting));

The default culture and fallback culture are both en-US.

To override the namespace of generated types, add the following project setting:

<PropertyGroup>
  <EssentialCultureNamespace>MyApplication.Localization</EssentialCultureNamespace>
</PropertyGroup>

Automatic creation never overwrites an existing Culture.json. After it is created, edit the file directly to add your own localization keys and translations. To disable automatic creation, add this project setting:

<PropertyGroup>
  <EssentialCultureAutoCreate>false</EssentialCultureAutoCreate>
</PropertyGroup>

Packages

Package Purpose
Arkheide.Essential.Culture Culture resolution and the static Localizer entry point
Arkheide.Essential.Culture.Generator Generates strongly typed keys from Culture.json; normally included transitively and does not need to be installed separately
Arkheide.Essential.Culture.Wpf Strongly typed WPF Localize XAML binding
Arkheide.Essential.Culture.Avalonia Strongly typed Avalonia Localize XAML binding
Arkheide.Essential.Culture.WinUI Strongly typed WinUI 3 Localize support and window refresh infrastructure
dotnet add package Arkheide.Essential.Culture
dotnet add package Arkheide.Essential.Culture.Wpf
dotnet add package Arkheide.Essential.Culture.Avalonia
dotnet add package Arkheide.Essential.Culture.WinUI

AI assistance

This library was developed with assistance from AI Agent (ChatGPT Codex). All forms of AI assistance are welcome for maintenance and development, but human review is required before submission.

Documentation and examples

License

Licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 103 8/27/2026
1.1.0 100 8/27/2026
1.0.0 104 8/19/2026