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
<PackageReference Include="Lugha.Import.Gettext" Version="0.3.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Lugha.Import.Gettext" Version="0.3.0" />
<PackageReference Include="Lugha.Import.Gettext"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Lugha.Import.Gettext --version 0.3.0
#r "nuget: Lugha.Import.Gettext, 0.3.0"
#:package Lugha.Import.Gettext@0.3.0
#addin nuget:?package=Lugha.Import.Gettext&version=0.3.0
#tool nuget:?package=Lugha.Import.Gettext&version=0.3.0
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:
- Contracts -
ITextScopeinterfaces generated from the reference locale. A.potfile is used as the reference; if none exists, the first.pofile serves as the reference. - Implementations - sealed locale classes generated from each
.pofile, 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
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Lugha.Import (>= 0.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.