Lugha.Import.Resx 0.3.0

dotnet add package Lugha.Import.Resx --version 0.3.0
                    
NuGet\Install-Package Lugha.Import.Resx -Version 0.3.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="Lugha.Import.Resx" Version="0.3.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lugha.Import.Resx" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Lugha.Import.Resx">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 Lugha.Import.Resx --version 0.3.0
                    
#r "nuget: Lugha.Import.Resx, 0.3.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 Lugha.Import.Resx@0.3.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=Lugha.Import.Resx&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Lugha.Import.Resx&version=0.3.0
                    
Install as a Cake Tool

Lugha.Import.Resx

Roslyn incremental source generator that converts .resx and .resw resource files into typed Lugha text scopes at compile time.

dotnet add package Lugha.Import.Resx

You also need the core Lugha package for the runtime types referenced by generated code:

dotnet add package Lugha

How it works

The generator filters AdditionalFiles for .resx and .resw extensions and emits two kinds of output:

  1. Contracts - ITextScope interfaces generated from the reference file. A file without a language segment in its name (e.g. Strings.resx) is treated as the reference.
  2. Implementations - sealed locale classes generated from each language-tagged file (e.g. Strings.es-ES.resx), implementing the contract interfaces.

Language tags are extracted from the filename convention Name.lang.resx. Tags must start with two or more alphabetic characters and may include region subtags (e.g. en-GB, zh-Hans).

All parsing is delegated to ResxParser and code emission to CodeEmitter from the Lugha.Import library. The emitter resolves CLDR rule types via LanguageRules.Resolve() from Lugha.Common.

Usage

Add .resx/.resw files as AdditionalFiles in the consuming project:

<ItemGroup>
  <AdditionalFiles Include="Resources\Strings.resx" />
  <AdditionalFiles Include="Resources\Strings.*.resx" />
</ItemGroup>

Example input

A reference file (Resources/Strings.resx):

<root>
  <data name="Connection_Discovering" xml:space="preserve">
    <value>Discovering</value>
  </data>
  <data name="Connection_Connected" xml:space="preserve">
    <value>Connected to {0}</value>
    <comment>{0} = host</comment>
  </data>
</root>

A locale file (Resources/Strings.es-ES.resx):

<root>
  <data name="Connection_Discovering" xml:space="preserve">
    <value>Descubriendo</value>
  </data>
  <data name="Connection_Connected" xml:space="preserve">
    <value>Conectado a {0}</value>
    <comment>{0} = host</comment>
  </data>
</root>

Generated output

The generator converts underscores to dots for scope grouping. Connection_Discovering becomes the Discovering member on IConnectionText:

public interface IConnectionText : ITextScope
{
    string Discovering { get; }
    string Connected(string host);
}
public sealed class EsEsConnectionText : IConnectionText
{
    public string Discovering => "Descubriendo";
    public string Connected(string host) => $"Conectado a {host}";
}

Format holes ({0}) are converted to named parameters. Use <comment> elements to provide parameter names: {0} = host or {0}: host. Without a comment, parameters are named arg0, arg1, etc.

MSBuild properties

Property Default Description
LughaNamespace Lugha.Generated Root namespace for all generated types.
LughaDefaultLanguage en Language tag assumed for the reference file (used for CLDR rule resolution).

The package ships a .targets file that declares CompilerVisibleProperty for both properties automatically — NuGet consumers need only set the properties in their .csproj:

<PropertyGroup>
  <LughaNamespace>MyApp.Translations</LughaNamespace>
  <LughaDefaultLanguage>en-US</LughaDefaultLanguage>
</PropertyGroup>

NuGet package layout

The package places only Lugha.Import.Resx.dll in analyzers/dotnet/cs/. Runtime dependencies (Lugha.Import, Lugha.Common) flow as NuGet package references so the Roslyn compiler host resolves them transitively.

Build

Targets netstandard2.0 with Microsoft.CodeAnalysis.CSharp 5.0.0. Implements IIncrementalGenerator for optimal IDE performance.

dotnet build import/lugha-import-resx

Licence

Apache License 2.0

There are no supported framework assets in this 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
0.3.0 113 3/21/2026
0.2.2 106 3/6/2026
0.2.1 100 3/6/2026
0.2.0 100 3/6/2026
0.1.0 106 3/5/2026