Skip to content
perpetualKid edited this page Apr 7, 2021 · 4 revisions

GetText.NET.Extractor

GetText.NET.Extractor helps to extract literal string values from C# source code, similar and mostly compatible with xgettext from GNU gettext tools.

There are a number of improvement and simplifications in GetText.NET.Extractor to streamline and align the usage in typical .NET environments.

The extractor parses C# source code files to extract literal strings and export those into PO Templates. Translators would use tools like PoEdit and use the exported PO Template as master PO file to provide PO translation files, one per language. These translation files will be distributed together with the software which is using GetText.NET (or other gettext compatible translation engine) to provide runtime translation support.

While parsing C# source code, the extractor is looking for instances of ICatalog API calls to GetString, GetParticularString, GetPluralString and GetParticularPluralString to extract literal strings

Console.WriteLine(catalog.GetString("Hello, World!")); //will translate "Hello, World!" using loaded translations

In combination with GetText.Net.WindowsForms, also WinForms Controls Text-properties such as Button.Text or Control.HeaderText can be translated. The Extractor will automatically export all literal string assignments from .Text/HeaderText/ToolTipText properties, which are typically saved in the (Form1).Designer.cs files.

Form1.Designer.cs

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
    this.someButton.Text = "Hello World";
    ...
}
Clone this wiki locally