[Django] #18731: "makemessages" management command should handle import aliases

25 views
Skip to first unread message

Django

unread,
Aug 7, 2012, 11:06:15 PM8/7/12
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Keywords: makemessages i18n
Severity: Normal | gettext
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Hi there,

when doing translations for one of my projects, I noticed that none of the
strings that I had identified as "translatable" in python files were
gathered in PO files.

After some code browsing, I saw that the "makemessages" management command
has a fixed set of --keyword arguments passed to xgettext.

It occurs that I don't use imports with their full name:

{{{
from django.utils.translation import ugettext
}}}

Nor with the standard "_" alias:

{{{
from django.utils.translation import ugettext as _
}}}

Because "_" is a dummy variable that I use a lot when doing tuple
expansion with unused items (I do use "tr" because it does not mix with
other of my stuff but that's not the point here)

It would be cool if the "makemessages" command could accept user defined
keywords. I did a small patch myself that accomplishes this. Please take
it in consideration :-)

Thanks in advance keep up the great work,

Robin

--
Ticket URL: <https://code.djangoproject.com/ticket/18731>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 9, 2012, 6:29:47 AM8/9/12
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage:
Keywords: makemessages i18n | Unreviewed
gettext | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by diabeteman):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

I forgot to explain some stuff about the patch :)

Basically, if you use the i18n functions like this:

{{{
from django.utils.translation import ugettext as tr, ugettext_lazy as
tr_lazy

tr('some translatable string')
tr_lazy('some lazy translatable string')
}}}

You can generate/update the .po files with this command (run into the app
directory and/or from the project root)

{{{
$ django-admin.py makemessages --locale=fr_FR --extra-keyword=tr --extra-
keyword=tr_lazy
}}}

It will take all your translatable strings into account.

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:1>

Django

unread,
Aug 12, 2012, 2:41:36 PM8/12/12
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: closed
Component: Core (Management | Version: 1.4
commands) | Resolution: fixed
Severity: Normal | Triage Stage:
Keywords: makemessages i18n | Unreviewed
gettext | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Anssi Kääriäinen <akaariai@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [c1684e3dcb2adf0fec8fd423cc73122330c268fe]:
{{{
#!CommitTicketReference repository=""
revision="c1684e3dcb2adf0fec8fd423cc73122330c268fe"
Fixed #18731 -- Cleaned up split_exclude's use of can_reuse

The outer query's set of reusable joins (can_reuse) was passed to the
inner query's add_filter call. This was incorrect.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:2>

Django

unread,
Aug 12, 2012, 2:43:00 PM8/12/12
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: reopened
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage:
Keywords: makemessages i18n | Unreviewed
gettext | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by akaariai):

* status: closed => reopened
* resolution: fixed =>


Comment:

Wrong ticket number in commit message -- reopening.

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:3>

Django

unread,
Oct 12, 2012, 7:36:18 PM10/12/12
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: reopened

Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 1
gettext | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by lrekucki):

* needs_docs: 0 => 1
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:4>

Django

unread,
Mar 22, 2013, 4:08:13 PM3/22/13
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 1
gettext | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by diabeteman):

Hello,

could this patch be integrated in the next release ?
It is not a big change :)

Thanks,
--Robin

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:6>

Django

unread,
Mar 22, 2013, 6:15:06 PM3/22/13
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 1
gettext | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by aaugustin):

It looks like the patch needs tests and documentation. Uploading a new
diff against master with code, docs and tests changes would help.

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:7>

Django

unread,
Mar 24, 2013, 8:58:22 AM3/24/13
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 1
gettext | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by diabeteman):

Hello,

I wrote docs and tests in a new patch against master. Tell me if I need to
change something :)

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:8>

Django

unread,
Mar 25, 2013, 12:00:04 PM3/25/13
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 1
gettext | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by diabeteman):

Oops,

the patch I uploaded is not complete (missing sample files)
Here are 2 new patches (one for django 1.5.x and one for the master HEAD)

my bad :)

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:9>

Django

unread,
Mar 26, 2013, 12:35:34 PM3/26/13
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 1
gettext | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by diabeteman):

I made a pull request on github :)

https://github.com/django/django/pull/959

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:10>

Django

unread,
Feb 7, 2014, 2:26:30 PM2/7/14
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 0
gettext | Patch needs improvement: 1

Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* needs_docs: 1 => 0
* needs_tests: 1 => 0
* needs_better_patch: 0 => 1


Comment:

Patch no longer applies cleanly (and docs need updating for the fact that
this would go in 1.7).

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:11>

Django

unread,
Feb 16, 2014, 12:34:21 PM2/16/14
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 0
gettext | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by diabeteman):

The patch has been reworked on the HEAD.

Here's a new pull request: https://github.com/django/django/pull/2311

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:12>

Django

unread,
Mar 6, 2014, 6:01:35 PM3/6/14
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: makemessages i18n | checkin

gettext | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by diabeteman):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


Comment:

Gentle bump.

I hope it is not too late for integration in 1.7 :-)

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:13>

Django

unread,
Mar 6, 2014, 6:46:58 PM3/6/14
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:

Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 0
gettext | Patch needs improvement: 0

Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* stage: Ready for checkin => Accepted


Comment:

You need someone besides yourself to review the patch in order to mark it
RFC, thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:14>

Django

unread,
Mar 7, 2014, 4:00:55 AM3/7/14
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.4
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 0
gettext | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by diabeteman):

oops sorry :-/

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:15>

Django

unread,
Mar 7, 2014, 5:37:06 AM3/7/14
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: master
Component: | Resolution:
Internationalization | Triage Stage: Accepted
Severity: Normal | Needs documentation: 1
Keywords: makemessages i18n | Patch needs improvement: 1
gettext | UI/UX: 0
Has patch: 1 |

Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by claudep):

* component: Core (Management commands) => Internationalization


* needs_better_patch: 0 => 1

* version: 1.4 => master
* type: New feature => Cleanup/optimization


* needs_docs: 0 => 1


Comment:

In my recent commit in `makemessages`
([06efeae598c6dafbe56d2ea323a0dccdd5bf2b8e]), I added an options list for
various gettext commands at the `Command` level.

Therefore, the new way to solve this issue is to create a custom
`makemessages` command in one of your project's apps, and complete the
`Command.xgettext_options` list. I'm keeping this ticket open so as to add
an example in the documentation.

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:16>

Django

unread,
Aug 12, 2014, 2:18:04 AM8/12/14
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: master
Component: | Resolution:
Internationalization | Triage Stage: Accepted
Severity: Normal | Needs documentation: 1
Keywords: makemessages i18n | Patch needs improvement: 1
gettext | UI/UX: 0
Has patch: 1 |
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by tkhyn):

To people who - like me lately - would land here after a google search and
want to add gettext extra keywords to Django < 1.7 without having to patch
Django, you may want to use [https://bitbucket.org/tkhyn/django-
extra_keywords/src/ced532843875/extra_keywords/management/commands/makemessages.py
this management command override] which will work with Django 1.6 and
earlier. Or simply use the [https://pypi.python.org/pypi/django-
extra_keywords django-extra_keywords] package.

It uses an approach that differs from what is suggested above, by monkey-
patching `popen_wrapper` (>= 1.6) or `_popen` (< 1.6) in
`core.management.commands.makemessages` and adding arguments to the
command. A bit hackish, but it does the job.

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:17>

Django

unread,
Oct 29, 2014, 10:44:19 AM10/29/14
to django-...@googlegroups.com
#18731: "makemessages" management command should handle import aliases
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: master
Component: Documentation | Resolution:

Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 0
gettext | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0

* component: Internationalization => Documentation


* needs_docs: 1 => 0


Comment:

Berker created a [https://github.com/django/django/pull/3439 documentation
pull request] as suggested by Claude.

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:18>

Django

unread,
Oct 29, 2014, 10:58:16 AM10/29/14
to django-...@googlegroups.com
#18731: Document how to pass additional keywords to xgettext in makemessages

-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: master
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 0
gettext | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by timgraham):

The patch looks okay to me, but Claude should review as well as I'm not a
makemessages user.

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:19>

Django

unread,
Oct 30, 2014, 8:22:59 AM10/30/14
to django-...@googlegroups.com
#18731: Document how to pass additional keywords to xgettext in makemessages
-------------------------------------+-------------------------------------
Reporter: diabeteman | Owner: nobody
Type: | Status: closed
Cleanup/optimization | Version: master
Component: Documentation | Resolution: fixed

Severity: Normal | Triage Stage: Accepted
Keywords: makemessages i18n | Needs documentation: 0
gettext | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"cbd936d0f87cf5109d3ef67c07797c657912f424"]:
{{{
#!CommitTicketReference repository=""
revision="cbd936d0f87cf5109d3ef67c07797c657912f424"
Fixed #18731 -- Added an example about customizing "makemessages" command.

Thanks claudp for the suggestion and review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/18731#comment:20>

Reply all
Reply to author
Forward
0 new messages