Contextual marker is returned as the message ID, whereas the actual
message is ignored. For example:
{{{#!python
pgettext_lazy("month name", "May")
}}}
gives the following in the respective PO file:
{{{
msgid "month name"
msgstr ""
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34630>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => worksforme
Comment:
Thanks for the report, however it works for me, see e.g.
[https://github.com/django/django/blob/1136aa5005f0ae70fea12796b7e37d6f027b9263/django/utils/dates.py#L52-L65
MONTHS_AP] and their
[https://github.com/django/django/blob/1136aa5005f0ae70fea12796b7e37d6f027b9263/django/conf/locale/en/LC_MESSAGES/django.po#L1248-L1306
translations]. Maybe it's an issue in `gettext`, I checked with `gettext`
version 0.21.
--
Ticket URL: <https://code.djangoproject.com/ticket/34630#comment:1>
Comment (by Kamil Paduszyński):
Replying to [comment:1 Mariusz Felisiak]:
Thanks for rapid review and answer!
To my surprise, it started to work on my setup (using the same version of
`gettext`, 0.21).
But... When I was posting the ticket, `pgettext_lazy` was aliased it with
`_` (like this is commonly done with `gettext_lazy`). If I do not use the
alias, everything works normally... So, it looks like the way
`pgettext_lazy` works depends on the way it's imported. Is that even
possible?
> Thanks for the report, however it works for me, see e.g.
[https://github.com/django/django/blob/1136aa5005f0ae70fea12796b7e37d6f027b9263/django/utils/dates.py#L52-L65
MONTHS_AP] and their
[https://github.com/django/django/blob/1136aa5005f0ae70fea12796b7e37d6f027b9263/django/conf/locale/en/LC_MESSAGES/django.po#L1248-L1306
translations]. Maybe it's an issue in `gettext`, I checked with `gettext`
version 0.21.
--
Ticket URL: <https://code.djangoproject.com/ticket/34630#comment:2>
Comment (by Mariusz Felisiak):
Replying to [comment:2 Kamil Paduszyński]:
> But... When I was posting the ticket, `pgettext_lazy` was aliased it
with `_` (like this is commonly done with `gettext_lazy`). If I do not use
the alias, everything works normally... So, it looks like the way
`pgettext_lazy` works depends on the way it's imported. Is that even
possible?
I don't think so. This can be an issue in your code. You can try to
prepare a minimum, sample project that reproduces your issue and ask folks
on one of
[https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
support channels] for help in debugging.
--
Ticket URL: <https://code.djangoproject.com/ticket/34630#comment:3>
Comment (by Kamil Paduszyński):
If you'll find a minute, please take a quick look:
https://github.com/paduszykam/django-pgettext_lazy-issue
Dzięki!
Replying to [comment:3 Mariusz Felisiak]:
> Replying to [comment:2 Kamil Paduszyński]:
> > But... When I was posting the ticket, `pgettext_lazy` was aliased it
with `_` (like this is commonly done with `gettext_lazy`). If I do not use
the alias, everything works normally... So, it looks like the way
`pgettext_lazy` works depends on the way it's imported. Is that even
possible?
>
> I don't think so. This can be an issue in your code. You can try to
prepare a minimum, sample project that reproduces your issue and ask folks
on one of
[https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
support channels] for help in debugging.
--
Ticket URL: <https://code.djangoproject.com/ticket/34630#comment:4>
Comment (by David Sanders):
Hi Kamil,
The project you posted is not configured correctly. `LOCALE_PATHS`
[https://docs.djangoproject.com/en/4.2/ref/settings/#locale-paths must be
a list of directories], not a single directory.
@felixx
I think part of the problem here is that the error message highlighting
this misconfiguration wasn't being shown when running `makemessages`, I
could only see it when I simply ran `./manage.py` with no args. I'm
unfamiliar with `makemessages` but should it be showing errors? 🤔 Note
that if I run `./manage.py showmigrations` (for eg) it does show the
error.
--
Ticket URL: <https://code.djangoproject.com/ticket/34630#comment:5>
Comment (by Kamil Paduszyński):
Sorry for that silly config error.
I have just fixed it and pushed the changes. This did not resolve the
issue though.
Replying to [comment:5 David Sanders]:
> Hi Kamil,
>
> The project you posted is not configured correctly. `LOCALE_PATHS`
[https://docs.djangoproject.com/en/4.2/ref/settings/#locale-paths must be
a list of directories], not a single directory.
>
> @felixx
> I think part of the problem here is that the error message highlighting
this misconfiguration wasn't being shown when running `makemessages`, I
could only see it when I simply ran `./manage.py` with no args. I'm
unfamiliar with `makemessages` but should it be showing errors? 🤔 Note
that if I run `./manage.py showmigrations` (for eg) it does show the
error.
--
Ticket URL: <https://code.djangoproject.com/ticket/34630#comment:6>
Comment (by Claude Paroz):
I'm pretty sure you can't simply alias the `(n|p)gettext` family like you
can do with the simpler `gettext/gettext_lazy` calls. Remember that
gettext works by parsing code. So this is not a Django-specific issue,
it's how gettext works. See also the `--keyword` xgettext parameters in
`makemessages.py`. If aliases are used, then those aliases should also be
present in some `--keyword` parameter (which are not customizable in
Django currently).
--
Ticket URL: <https://code.djangoproject.com/ticket/34630#comment:7>
Comment (by Kamil Paduszyński):
Thanks! Now it's clearer to me. Is that "aliasing limitation thing"
mentioned in docs? Maybe it should.
Replying to [comment:7 Claude Paroz]:
> I'm pretty sure you can't simply alias the `(n|p)gettext` family like
you can do with the simpler `gettext/gettext_lazy` calls. Remember that
gettext works by parsing code. So this is not a Django-specific issue,
it's how gettext works. See also the `--keyword` xgettext parameters in
`makemessages.py`. If aliases are used, then those aliases should also be
present in some `--keyword` parameter (which are not customizable in
Django currently).
--
Ticket URL: <https://code.djangoproject.com/ticket/34630#comment:8>
Comment (by Antoine Humbert):
This is clearly mentioned in documentation that you cannot alias non-
single argument translation functions with _
See https://docs.djangoproject.com/en/4.2/topics/i18n/translation/
What functions may be aliased as _?
Because of how xgettext (used by makemessages) works, only functions that
take a single string argument can be imported as _:
gettext()
gettext_lazy()
--
Ticket URL: <https://code.djangoproject.com/ticket/34630#comment:9>
Comment (by Kamil Paduszyński):
Thank you guys for all the help! And sorry for bothering. Next time I will
dive deeper into docs.
Replying to [comment:9 Antoine Humbert]:
> This is clearly mentioned in documentation that you cannot alias non-
single argument translation functions with _
>
> See https://docs.djangoproject.com/en/4.2/topics/i18n/translation/
>
> What functions may be aliased as _?
>
> Because of how xgettext (used by makemessages) works, only functions
that take a single string argument can be imported as _:
>
> gettext()
> gettext_lazy()
--
Ticket URL: <https://code.djangoproject.com/ticket/34630#comment:10>