dotgnu-pnet
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pnet-developers] RFC: GNU gettext support for C#


From: Bruno Haible
Subject: Re: [Pnet-developers] RFC: GNU gettext support for C#
Date: Tue, 30 Dec 2003 15:46:08 +0100
User-agent: KMail/1.5

Hi Gopal,

> quite another thing to have to compile it to a .dll to
> use it. I didnt understand which is supported as of now ?. Both ?

Yes, both are supported, through different 'msgfmt' options. The .resources
approach integrates better with the Microsoft .NET world, the .dll approach
integrates better with the free software world.

> Hmm... and how exactly does the gettext shorthand work
> for C# ?

In class-based languages like C# or Java, I typically use this:
- A unique class, say 'Util' or 'Context' contains:

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

- All other classes contain:

    private static GettextResourceManager res = Util.MyResourceManager;

  Then the calls look like this:

    Console.WriteLine(res.GetString("Completed."));

If you want a shortcut, you would define it in each class:

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

  Then the calls look like this:

    Console.WriteLine(_("Completed."));

> Is there some hack to make that work everywhere ?

Not that I know of. A little bit of idiom is needed to activate
the shortcut. In C you write

    #include "gettext.h"
    #define _(s) gettext (s)

whereas in C# you write

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

Also, if all the classes of a package inherit from a common superclass
also contained in that package, one can put these two lines into the
common superclass, with 'protected' instead of 'private'.

Bruno



reply via email to

[Prev in Thread] Current Thread [Next in Thread]