Beskar.CodeGeneration.LanguageGenerator 1.1.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Beskar.CodeGeneration.LanguageGenerator --version 1.1.4
                    
NuGet\Install-Package Beskar.CodeGeneration.LanguageGenerator -Version 1.1.4
                    
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="Beskar.CodeGeneration.LanguageGenerator" Version="1.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Beskar.CodeGeneration.LanguageGenerator" Version="1.1.4" />
                    
Directory.Packages.props
<PackageReference Include="Beskar.CodeGeneration.LanguageGenerator" />
                    
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 Beskar.CodeGeneration.LanguageGenerator --version 1.1.4
                    
#r "nuget: Beskar.CodeGeneration.LanguageGenerator, 1.1.4"
                    
#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 Beskar.CodeGeneration.LanguageGenerator@1.1.4
                    
#: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=Beskar.CodeGeneration.LanguageGenerator&version=1.1.4
                    
Install as a Cake Addin
#tool nuget:?package=Beskar.CodeGeneration.LanguageGenerator&version=1.1.4
                    
Install as a Cake Tool

Beskar.CodeGeneration.LanguageGenerator

A high-performance C# Source Generator for .NET 10 that transforms simple enumerations into a robust, type-safe translation infrastructure. It automatically generates translation keys and a fluent TranslationFacade to streamline localization in your applications.

Key Features

  • 🚀 Zero-Reflection: All keys and mapping logic are generated at compile-time for maximum performance.
  • 🏗️ Fluent Facade: Provides a strongly-typed API (translation.Group.Key) instead of error-prone magic strings.
  • 📦 Multiple Providers: Use the built-in JsonTranslationProvider or implement your own for Databases or Third-party APIs.
  • 🔍 Culture Detection: Support for multiple prioritized language detectors (e.g., SystemCultureDetector).
  • 🛠️ Default Values: Define fallback translations directly in your code using attributes.

Installation

The generator is part of the Beskar.CodeGeneration suite. Ensure your project targets .NET 10 or higher to leverage the latest C# features.

Quick Start

1. Define your Translation Groups

Decorate your enums with [TranslationGroup] and members with [TranslationKey].

[TranslationGroup]
public enum TestGroup
{
   [TranslationKey]
   Test = 1,
   
   [TranslationKey(defaultValue: "Default Greeting")]
   WelcomeMessage = 2,
}

[TranslationGroup(GroupName = "Identity")]
public enum RegisterGroup
{
   [TranslationKey(keyName: "Title")]
   Header = 1,
   
   [TranslationKey]
   Description = 2,
}

2. Configure Dependency Injection

Register the necessary services to enable the translation engine.

var services = new ServiceCollection()
   .AddSingleton<ILanguageDetector, SystemCultureDetector>()
   .AddSingleton<ITranslationProvider, JsonTranslationProvider>()
   .AddSingleton<TranslationFacade>();
   
var provider = services.BuildServiceProvider();

// Initialize the Json Provider (Example)
var jsonProvider = (JsonTranslationProvider)provider.GetRequiredService<ITranslationProvider>();
jsonProvider.Initialize("Translations"); // Path to your .json files
await jsonProvider.PopulateCache(CancellationToken.None);

var translation = provider.GetRequiredService<TranslationFacade>();

3. Usage

Access your translations with full IntelliSense support.

// Accessing generated properties via the Facade
string welcome = translation.TestGroup.WelcomeMessage;
string desc = translation.Identity.Description;

// Accessing raw generated constant keys
string rawKey = LangKey.TestGroup.WelcomeMessage;

Generated Artifacts

In the background, the generator creates partial classes to handle the heavy lifting:

  • LangKey: A static class containing const string definitions for all translation keys, an AllKeys collection, and a GetDefaultValue lookup based on your attributes.
  • TranslationFacade: A sealed class that wraps the ITranslationProvider to provide the fluent access layer. It uses the new C# field keyword for efficient lazy loading of group facades.

Advanced Configuration

Custom Providers

You can create custom providers by inheriting from TranslationBaseProvider. This allows you to fetch translations from a database, a CMS, or an external API.

public class SqlTranslationProvider : TranslationBaseProvider
{
   public override async ValueTask PopulateCache(CancellationToken ct) 
   {
      // Custom logic to load translations from SQL
      // AddToCache("en", data);
   }
}
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 (1)

Showing the top 1 NuGet packages that depend on Beskar.CodeGeneration.LanguageGenerator:

Package Downloads
Beskar.Experiments

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1 95 4/29/2026
1.2.0 101 4/26/2026
1.1.9 88 4/25/2026
1.1.8 89 4/8/2026
1.1.7 89 4/7/2026
1.1.6 105 4/5/2026
1.1.5 91 4/5/2026
1.1.4 98 4/4/2026
1.1.3 91 4/4/2026
1.1.2 98 4/2/2026
1.1.1 104 4/2/2026