[Django] #34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO files

23 views
Skip to first unread message

Django

unread,
Jun 3, 2023, 5:13:34 PM6/3/23
to django-...@googlegroups.com
#34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO
files
------------------------------------------------+------------------------
Reporter: paduszykam | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 4.2
Severity: Normal | Keywords: tr
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
I have noticed the problem when moving from `4.1.9` to `4.2.1`.

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.

Django

unread,
Jun 4, 2023, 1:29:33 PM6/4/23
to django-...@googlegroups.com
#34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO
files
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 4.2
Internationalization | Resolution:
Severity: Normal | worksforme

Keywords: tr | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* 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>

Django

unread,
Jun 4, 2023, 3:34:50 PM6/4/23
to django-...@googlegroups.com
#34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO
files
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 4.2
Internationalization | Resolution:
Severity: Normal | worksforme
Keywords: tr | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 4, 2023, 11:40:28 PM6/4/23
to django-...@googlegroups.com
#34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO
files
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 4.2
Internationalization | Resolution:
Severity: Normal | worksforme
Keywords: tr | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 5, 2023, 6:50:13 AM6/5/23
to django-...@googlegroups.com
#34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO
files
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 4.2
Internationalization | Resolution:
Severity: Normal | worksforme
Keywords: tr | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 5, 2023, 9:56:09 AM6/5/23
to django-...@googlegroups.com
#34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO
files
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 4.2
Internationalization | Resolution:
Severity: Normal | worksforme
Keywords: tr | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 5, 2023, 10:48:21 AM6/5/23
to django-...@googlegroups.com
#34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO
files
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 4.2
Internationalization | Resolution:
Severity: Normal | worksforme
Keywords: tr | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 5, 2023, 12:48:41 PM6/5/23
to django-...@googlegroups.com
#34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO
files
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 4.2
Internationalization | Resolution:
Severity: Normal | worksforme
Keywords: tr | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 5, 2023, 1:50:48 PM6/5/23
to django-...@googlegroups.com
#34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO
files
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 4.2
Internationalization | Resolution:
Severity: Normal | worksforme
Keywords: tr | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 5, 2023, 3:52:29 PM6/5/23
to django-...@googlegroups.com
#34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO
files
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 4.2
Internationalization | Resolution:
Severity: Normal | worksforme
Keywords: tr | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 6, 2023, 3:17:55 PM6/6/23
to django-...@googlegroups.com
#34630: Neither `pgettext` nor `pgettext_lazy` return contextual markers in PO
files
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 4.2
Internationalization | Resolution:
Severity: Normal | worksforme
Keywords: tr | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages