Lugha.Import.Gettext 0.3.0

dotnet add package Lugha.Import.Gettext --version 0.3.0
                    
NuGet\Install-Package Lugha.Import.Gettext -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.Gettext" 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.Gettext" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Lugha.Import.Gettext">
  <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.Gettext --version 0.3.0
                    
#r "nuget: Lugha.Import.Gettext, 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.Gettext@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.Gettext&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Lugha.Import.Gettext&version=0.3.0
                    
Install as a Cake Tool

Lugha.Import.Gettext

Roslyn incremental source generator that converts GNU Gettext .po and .pot files into typed Lugha text scopes at compile time.

dotnet add package Lugha.Import.Gettext

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 .po and .pot extensions and emits two kinds of output:

  1. Contracts - ITextScope interfaces generated from the reference locale. A .pot file is used as the reference; if none exists, the first .po file serves as the reference.
  2. Implementations - sealed locale classes generated from each .po file, implementing the contract interfaces.

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

Usage

Add .po/.pot files as AdditionalFiles in the consuming project:

<ItemGroup>
  <AdditionalFiles Include="Translations\*.pot" />
  <AdditionalFiles Include="Translations\*.po" />
</ItemGroup>

Example input

A reference template (Translations/messages.pot):

msgctxt "Connection"
msgid "Discovering"
msgstr ""

msgctxt "Connection"
msgid "Connected to {host}"
msgstr ""

A locale file (Translations/es-ES.po):

msgctxt "Connection"
msgid "Discovering"
msgstr "Descubriendo"

msgctxt "Connection"
msgid "Connected to {host}"
msgstr "Conectado a {host}"

Generated output

The generator emits an ITextScope interface from the template:

public interface IConnectionText : ITextScope
{
    string Discovering { get; }
    string Connected(string host);
}

And a sealed implementation from each .po file:

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

Parameters named count are typed as int and generate Plural.Select calls. All others are string.

MSBuild properties

Property Default Description
LughaNamespace Lugha.Generated Root namespace for all generated types.

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

<PropertyGroup>
  <LughaNamespace>MyApp.Translations</LughaNamespace>
</PropertyGroup>

NuGet package layout

The package places only Lugha.Import.Gettext.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-gettext

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 112 3/21/2026
0.2.2 111 3/6/2026
0.2.1 105 3/6/2026
0.2.0 100 3/6/2026
0.1.0 111 3/5/2026