Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N__p returns all its argument as a list which makes using the marked-up string non-transparent and troublesome #13

Open
az143 opened this issue Nov 27, 2023 · 3 comments
Assignees
Labels

Comments

@az143
Copy link

az143 commented Nov 27, 2023

N__("some msgid") works great and its entry in the manpage explains perfectly what it does: mark a string for translation, but not translate it immediately ("for example when you also need the unmodified original string.").

if you do, however, both require the original string and translate it with/in a context, then N__p() will not work as well or out of the box: it returns all its arguments as a list, ie. the context and the msgid. this means that you cannot just write

my $onestringplease =  N__p("identifies as a verb","somemsgid");

as the list is interpreted in scalar context and your $onestringplease now contains the number 2. to retain the msgid you'd have to manually extract the second element from the result of the N__p, everywhere which defeats the purpose of a just-mark-me-up-please function like N__p.

i think that N__p should return only its msgid argument and ditch the context as that is really only relevant for
the translation activity, not for the program itself at the point when N__p is called.

the situation with N__n and N__np seems even worse as the list-or-scalar aspect also applies but there doesn't seem to be a 'natural' return value for those: just the msgid, or just the plural form, or both or neither?

@gflohr gflohr self-assigned this Nov 27, 2023
@gflohr gflohr added the bug label Nov 27, 2023
@gflohr
Copy link
Owner

gflohr commented Nov 27, 2023

That looks like missing test coverage, sorry. I'll fix it as soon as possible.

@gflohr
Copy link
Owner

gflohr commented Nov 27, 2023

As it turns out, that was actually by design, see https://rt.cpan.org/Ticket/Display.html?id=46471. I just forgot that issue.

The idea is that you can always feed the return value(s) of N__.*() into the corresponding __*() function and you will then get the translation, like this:

my @whatever = N__p('context', 'some message');
...
say __p(@whatever);

In a way the current implementation avoids DRY.

Do I see it correctly that you actually have a workaround for your issue by just calling the function in array context? Like this:

my (undef, $onestringplease) =  N__p("identifies as a verb","somemsgid");

If it that workaround is okay for you I would prefer to close your issue as wontfix because changing the implementation back and forth does not make sense and the use case is pretty exotic anyhow.

@az143
Copy link
Author

az143 commented Nov 27, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants