
Creating a new project, I had to use either * .resx for WinForms, or I2Localization for Unity, or other solutions for localizing applications. All these solutions are similar in that you have to invent a key-localization, insert it into the code and into the dictionary. At first, everything is fine, but over time, this process begins to annoy. However, looking at the key in the code is not always clear what I mean.
About the situation when you need to add localization to a large project where it did not exist at all, I will not even say how difficult it is.
')
I do not know why, but it turns out that there is a ready-made solution like gnu / gettext for a long time. Asking their friends and colleagues (those who work with .NET), most have not even heard of it. Therefore, I decided to share with this handy tool.
The principle is simple. You write the code with strings in English, run a utility that scans the source and provides you with the ability to translate. No need to invent any keys. The text in English is the key.
Let's get started
1) Install the NGettext package via Nu-get:
PM> Install-Package NGettext
NGettext is a GNU / Gettext cross-platform implementation for .NET.
2) Add an additional file to your project that simplifies the syntax a bit:
https://github.com/neris/NGettext/blob/master/doc/examples/T.csWe also add a directory to the project where translations will be stored:
MyProj \ Loc \ ru-RU \ LC_Messages
In my case it turns out this picture:

3) Add paths to the T.cs file:
static T() { var localesDir = Path.Combine(Directory.GetCurrentDirectory(), "Loc"); _Catalog = new Catalog("Test", localesDir, new CultureInfo("ru-RU")); }
Simplified. For example, only Russian. (It is possible to read dictionaries from the assembly itself)
4) We write our code using localization. Instead of βtextβ we write T ._ (βtextβ)
namespace TestCode { static class Program { public static void Main(string[] args) { Console.WriteLine(T._("Hello, World!")); Console.WriteLine(T._("Cat")); Console.ReadKey(); } } }
5) Now we need to translate all our text. Download
PoEdit . Create a translation file:
File β New β folder LC_MESSAGES β Test.po

Specify the folder in which our sources are located. Their program will scan:

You must also specify a keyword that poEdit will search for translation:

Add the translation we need and save.

Add translation files to the project. Make them copy always:
(It is possible to build them into the assembly itself)

Is done. Run:

Setup is ready. Then everything is simple. Write the code - edit the translation
You can also find ready-made libraries for localizing interfaces:
β
WPFβ
Additional information on using NGettextβ
GNU / Gettext Information