[Mono-dev] [PATCH] Bind d(n)gettext in Mono.Unix.Catalog

Jonathan Pryor jonpryor at vt.edu
Thu Dec 3 13:09:30 EST 2009


On Thu, 2009-12-03 at 13:22 +0100, Stephane Delcroix wrote:
> Here's a patch for Mono.Unix that P/Invoke d(n)gettext in addition to
> (n)gettext. It's quite useful for writing libraries requiring
> translations (think of Mono.Addins.Gui), esp. since GNU-gettext doesn't
> support multiple domains.

One problem: you're *removing*
Catalog.GetPluralString(string,string.int).  That's bad. :-)

Also, for your new GetPluralString() method, instead of using
MarshalStrings() (with an _ignore argument) +
UnixMarshal.StringToHeap(), combine the two so that MarshalStrings()
isn't getting an _ignore argument.

That aside, it looks good, though I do wonder if the overloading here is
a good idea.

Basically, we'll wind up with this:

        public class Catalog {
                public static string GetPluralString (string s, string p, int n);
                public static string GetPluralString (string domain, string s, string p, int n);
                
                public static string GetString (string s);
                public static string GetString (string domain, string
                s);
                // ...
        }

Generally, when overloading a method the first arguments should have the
same meaning, and "optional" arguments should be last.  Thus:

        public class Catalog { 
                public static string GetPluralString (string s, string p, int n);
                public static string GetPluralString (string s, string p, int n, string domain);
                
                public static string GetString (string s);
                public static string GetString (string s, string
                domain);
                // ...
        }

"Prior art," as it were, is System.Diagnostics.Trace.WriteLine[0]:

        public class Trace {
                public static void WriteLine (string message);
                public static void WriteLine (string message, string
                category);
        }

So I'm torn as to the "proper" thing to do here, as we have three
choices:

     1. Follow convention and make the 'domain' parameter last (above).
     2. Break convention and make the 'domain' parameter first
        (original).
     3. Use different method names, e.g. GetDomainString(),
        GetPluralDomainString(), and keep 'domain' as the first
        parameter.

Of these choices, I'm inclined toward (3) or (1), but could be argued
either way.

Thoughts?

 - Jon

[0]
http://msdn.microsoft.com/en-us/library/system.diagnostics.trace.writeline.aspx



More information about the Mono-devel-list mailing list