4

I've read a bit about the gettext. I believe it's a nice tool.

I've seen it's possible to use it with PHP projects.

I wonder if it is possible to use gettext also in with C#?

mikus
  • 3,042
  • 1
  • 30
  • 40
Jordi
  • 20,868
  • 39
  • 149
  • 333
  • 3
    A quick search reveals http://gnuwin32.sourceforge.net/packages/gettext.htm also http://stackoverflow.com/questions/18985482/how-to-install-gnu-gettext-on-windows-7 – teynon Nov 27 '15 at 14:04

1 Answers1

-1

There is a C# version as well and it can be used with both .resource and .dll files. Sample use with a 'singleton' type of approach:

Define a static holding the ResourceManager instance:

public static GettextResourceManager MyResourceManager =
  new GettextResourceManager("domain-name");

All classes containing internationalized strings then contain

private static String _(String s) { return Util.MyResourceManager.GetString(s); }

and this lets you use it like this, quite clean:

Console.WriteLine(_("Operation completed."));

Note that it needs some exception handling etc. and also introduces a lot of code duplication, which you can sort in different ways.

You can find all the usage details and context in the manual itself:

https://www.gnu.org/software/gettext/manual/html_node/C_0023.html#C_0023

mikus
  • 3,042
  • 1
  • 30
  • 40
  • 3
    instead of just sharing a link, i think it would be much better if some example was shown here. The link might not exist in future for others. – AvikB Jan 21 '17 at 08:30
  • 1
    Somewhere in that page you can read: "But beware: as of this writing (January 2004), the monoresgen converter is quite buggy." – Eric May 08 '20 at 05:37
  • @AvikB well, there is a full description, so if it's you negging the answer, it's uncool – mikus Jun 04 '23 at 19:17