On Fri May 29 11:10:30 2009, user42@zip.com.au wrote:
Show quoted text> ...
> It'd be good if a call to N__() with one arg in scalar context returned
> that arg.
Yes, confirmed. The function is prototyped, so it can actually not be
called with more than one arg.
Anyway, both in scalar and array context, the argument should be
returned, for practical reasons.
Show quoted text> I see the SYNOPSIS section of Locale::TextDomain shows N__ with two
> args,
>
> my @plurals = (N__ ("One world", "{num} worlds"),
> N__ ("1 file", "%d files"));
>
> so I suppose in array context it should continue to return all args in
> case someone has cut and pasted from there. Perhaps N__n() is intended
> though, or if all of N__ N__n N__xn etc are aliases anyway then it
> doesn't matter which.
Yes N__n() was meant.
However, all N__[np]+ functions that take more than one argument are
tricky. What should be returned?
Their purpose is to postpone actual translation, typically because they
are called to early, and the user locale is not yet set.
Let's look at N__n(). In array context, it is pretty obvious, that the
caller wants all three arguments. And in scalar context? If somebody
uses these functions in scalar context, it is probably a bug. Say for
example, somebody really writes:
my $message = N__n("One world", "{num} worlds", 3);
Both strings are marked and will appear in one entry in the po file, but
in this case (count is 3), the first string is effectively discarded
inside the script. If you later really want the translation, you have
to write it again. And either it will be found again by xgettext, or
you write something really braindamaged like:
my $count = int rand 10;
my $void = N__n("One world", "{num} worlds", $count;
my $sg = "One world";
my $pl = "{num} worlds";
POSIX::setlocale (LC_ALL, '');
my $non_void = N__n($sg, $pl, $count);
Well, pretty esoteric.
I will change the implementation of implementation of N__(), although it
is actually a little inconsistent. But for convenience it makes sense.