Dosaic.Extensions.Localization.Generator 1.2.41

dotnet add package Dosaic.Extensions.Localization.Generator --version 1.2.41
                    
NuGet\Install-Package Dosaic.Extensions.Localization.Generator -Version 1.2.41
                    
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="Dosaic.Extensions.Localization.Generator" Version="1.2.41" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dosaic.Extensions.Localization.Generator" Version="1.2.41" />
                    
Directory.Packages.props
<PackageReference Include="Dosaic.Extensions.Localization.Generator" />
                    
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 Dosaic.Extensions.Localization.Generator --version 1.2.41
                    
#r "nuget: Dosaic.Extensions.Localization.Generator, 1.2.41"
                    
#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 Dosaic.Extensions.Localization.Generator@1.2.41
                    
#: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=Dosaic.Extensions.Localization.Generator&version=1.2.41
                    
Install as a Cake Addin
#tool nuget:?package=Dosaic.Extensions.Localization.Generator&version=1.2.41
                    
Install as a Cake Tool

Dosaic.Extensions.Localization.Generator

Dosaic.Extensions.Localization.Generator is a Roslyn IIncrementalGenerator that runs at compile time to discover all types and members annotated with [LocalizedName] and emit a static EntityLabels lookup class into the consuming project. It can also write per-culture JSON translation files to disk during the build.

Installation

dotnet add package Dosaic.Extensions.Localization.Abstractions
dotnet add package Dosaic.Extensions.Localization.Generator

Or as PackageReference entries in your .csproj:

<PackageReference Include="Dosaic.Extensions.Localization.Abstractions" Version="" />
<PackageReference Include="Dosaic.Extensions.Localization.Generator" Version=""
                  OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

Features

  • Incremental generation — uses IIncrementalGenerator; only reruns when annotated nodes change
  • Multiple targets — handles [LocalizedName] on classes, enums, enum members, properties, and fields
  • Locale-typed API — all culture parameters use Locale.En / Locale.De instead of magic strings
  • Configurable default cultureEntityLabels.DefaultCulture can be set at runtime; defaults to Locale.En
  • Fallback — returns the member or type name when no translation is registered for the requested culture
  • JSON export — writes a translation JSON file per culture when MSBuild properties are configured

Generated output

Given:

[LocalizedName(en: "Order", de: "Bestellung")]
public class Order
{
    [LocalizedName(en: "Order Number", de: "Bestellnummer")]
    public string OrderNumber { get; set; }
}

[LocalizedName(en: "Order Status", de: "Bestellstatus")]
public enum OrderStatus
{
    [LocalizedName(en: "Active", de: "Aktiv")]
    Active
}

The generator emits EntityLabels.g.cs:

// <auto-generated/>
namespace Dosaic.Extensions.Localization
{
    public static partial class EntityLabels
    {
        // Labels keyed by "TypeName" (type-level) or "TypeName.MemberName" (member-level)
        private static readonly Dictionary<string, Dictionary<string, string>> Labels = ...;

        public static Locale DefaultCulture = Locale.En;

        // Raw key lookup
        public static string Get(string key);
        public static string Get(string key, Locale culture);

        // Type-level (class / enum)
        public static string Get<T>();
        public static string Get<T>(Locale culture);

        // Enum member by value
        public static string Get(System.Enum value);
        public static string Get(System.Enum value, Locale culture);

        // Property / field by expression
        public static string Get<T>(Expression<Func<T, object>> memberSelector);
        public static string Get<T>(Expression<Func<T, object>> memberSelector, Locale culture);
    }
}

Key format

Target Key
[LocalizedName] on class Order "Order"
[LocalizedName] on enum OrderStatus "OrderStatus"
[LocalizedName] on OrderStatus.Active "OrderStatus.Active"
[LocalizedName] on Order.OrderNumber "Order.OrderNumber"

JSON export

The generator can write translation files to disk on every build. Declare the output paths as MSBuild properties and expose them to the generator via CompilerVisibleProperty:

<PropertyGroup>
  <LocalizationJsonDeOutputPath>$(MSBuildProjectDirectory)\localization.de.json</LocalizationJsonDeOutputPath>
  <LocalizationJsonEnOutputPath>$(MSBuildProjectDirectory)\localization.en.json</LocalizationJsonEnOutputPath>
</PropertyGroup>

<ItemGroup>
  <CompilerVisibleProperty Include="LocalizationJsonDeOutputPath" />
  <CompilerVisibleProperty Include="LocalizationJsonEnOutputPath" />
</ItemGroup>

Either property can be omitted to skip that culture. The file is written on every compilation that touches an annotated node.

Output format

Entries are grouped by type name. Type-level labels use the "$" key within their group; member labels use the member name.

{
  "Order": {
    "$": "Bestellung",
    "OrderNumber": "Bestellnummer"
  },
  "OrderStatus": {
    "$": "Bestellstatus",
    "Active": "Aktiv",
    "Cancelled": "Storniert"
  }
}

How it works

  1. Attribute discoveryForAttributeWithMetadataName matches [Dosaic.Extensions.Localization.LocalizedNameAttribute] on PropertyDeclarationSyntax, FieldDeclarationSyntax, EnumMemberDeclarationSyntax, ClassDeclarationSyntax, RecordDeclarationSyntax, StructDeclarationSyntax, and EnumDeclarationSyntax
  2. Symbol extractionIPropertySymbol and IFieldSymbol produce member-level entries keyed "TypeName.MemberName"; INamedTypeSymbol produces type-level entries keyed "TypeName"
  3. Source emissionRegisterSourceOutput collects all results and emits EntityLabels.g.cs into the compilation
  4. JSON writing — reads LocalizationJsonDeOutputPath / LocalizationJsonEnOutputPath from AnalyzerConfigOptionsProvider.GlobalOptions and writes grouped JSON files to disk if paths are set
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

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.41 96 9/7/2026
1.2.40 109 8/27/2026
1.2.40-alpha.1 58 8/27/2026
1.2.39 102 8/25/2026
1.2.38 118 7/30/2026
1.2.37 123 7/14/2026
1.2.36 128 7/10/2026
1.2.35 160 6/19/2026
1.2.34 124 6/10/2026
1.2.33 125 6/2/2026