You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wrt Np_, I agree it's actually a bit unclear what it should do. I wrote "just returns the msgid", which is wrong of course. You chose to return the couple, which is exact but does not leave a string. I was thinking about "#{msgctxt}\004#{msgid}" to stay consistent wrt types.
But then the question is how to resolve a Np_. Your proposal translates it via p_, mine would require _.
And it is absolutely critical that the context is preserved. I think it should work just the same for p_. So I would expect this to work properly:
str=Np_("foo","bar")
...
p_(str)
Yes, at the end I'm using p_ with a single argument (explained below), because:
I'm convinced Np_ should return a string
just like we do with s_ it must contain the context
so we should simply pass the result of Np_ to the translating function (just as we pass the result of N_ to s_ or _)
I disagree with what I initially stated: the key property of N_ is not that it "returns the msgid", but that it returns the key in the MO file. The key for simple messages is simply msgid, but for contextualized message, the key is composite: msgctxt and msgid.
as a consequence Np_ should return a string with both msgctxt and msgid.
Given that contextualized messages are internally converted into "#{msgctxt}\004#{msgid}", I strongly believe that Np_ should just do that.
we need a function to handle that contextualized string
There are then two cases that must work:
the message is translated and part of the catalogue
In that case, simply using _(s) would work
it is not
In that case, _(s) would show the context, which is wrong.
So I conclude that we need another function, that behaves like this:
defpp_(s)=p_(*s.split("\004",2))
Instead of splitting, if we can query the catalogue, it could be something like
defpp_(s)=get_msgstr(s) || s.split("\004",2)[1]
where get_msgstr is a hypothetical function that (i) returns the translation if it exists, (ii) returns nil otherwise. Or use translate_singular_message.
Finally, instead of naming this function pp_, we could use p_, but add a new behavior when it's called with a single argument.
Activity
kou commentedon Feb 27, 2024
OK. Let's add it!
This may work:
And we need to add tests for it.
akimd commentedon Feb 27, 2024
Hi!
Thanks for the fast reaction!
Wrt
Np_, I agree it's actually a bit unclear what it should do. I wrote "just returns the msgid", which is wrong of course. You chose to return the couple, which is exact but does not leave a string. I was thinking about "#{msgctxt}\004#{msgid}" to stay consistent wrt types.But then the question is how to resolve a
Np_. Your proposal translates it viap_, mine would require_.Cheers!
kou commentedon Mar 4, 2024
Ah, you're right. We should "just return the msgid" because
p_returns the msgid when the msgid isn't localized:akimd commentedon Mar 7, 2024
Hi,
I took some more time to think about that.
When using
s_(notp_), I definitely useN_upstream. So it looks likeAnd it is absolutely critical that the context is preserved. I think it should work just the same for
p_. So I would expect this to work properly:Yes, at the end I'm using
p_with a single argument (explained below), because:Np_should return a strings_it must contain the contextNp_to the translating function (just as we pass the result ofN_tos_or_)I disagree with what I initially stated: the key property of
N_is not that it "returns the msgid", but that it returns the key in the MO file. The key for simple messages is simply msgid, but for contextualized message, the key is composite: msgctxt and msgid.Np_should return a string with both msgctxt and msgid.Given that contextualized messages are internally converted into
"#{msgctxt}\004#{msgid}", I strongly believe thatNp_should just do that.There are then two cases that must work:
In that case, simply using
_(s)would workIn that case,
_(s)would show the context, which is wrong.So I conclude that we need another function, that behaves like this:
Instead of splitting, if we can query the catalogue, it could be something like
where
get_msgstris a hypothetical function that (i) returns the translation if it exists, (ii) returns nil otherwise. Or usetranslate_singular_message.Finally, instead of naming this function
pp_, we could usep_, but add a new behavior when it's called with a single argument.Do I make sense?
Cheers!
kou commentedon Mar 18, 2024
Thanks for considering API!
How about using
[msgctxt, msgid]instead of"#{msgctxt}\004#{msgid}"?We can write the following with this API: