[Django] #23196: Don't translate empty string as gettext metadata

13 views
Skip to first unread message

Django

unread,
Aug 4, 2014, 6:14:03 PM8/4/14
to django-...@googlegroups.com
#23196: Don't translate empty string as gettext metadata
--------------------------------------+--------------------
Reporter: nedbatchelder | Owner: nobody
Type: Uncategorized | Status: new
Component: Internationalization | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
(this is very similar to #11363)

If you pass an empty string to django.utils.translation.ugettext, it
returns the metadata from the translations file. I know that this is the
GNU gettext behavior, but honestly, I can't imagine a use for it.

This is a problem when you have a string which can be overridden by a
user, but usually is not, and the default value for the string is
translated. If the user enters an empty string, ugettext returns the
metadata. Surprise!

Of course, an option is to check the string before calling ugettext, but
this is an easy step to overlook, especially because it is conceptually
unnecessary. It would be great if Django's wrappers for gettext would do
the obvious thing and return an empty string if asked to translate an
empty string.

For a low-level library, it could make sense to get the metadata with
gettext(""), but how would you reasonably use that in Django? And ffs,
why didn't they just make a function to get the metadata if people wanted
metadata? :)

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

Django

unread,
Aug 4, 2014, 6:15:12 PM8/4/14
to django-...@googlegroups.com
#23196: Don't translate empty string as gettext metadata
--------------------------------------+------------------------------------

Reporter: nedbatchelder | Owner: nobody
Type: Uncategorized | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by apollo13):

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


Comment:

Accepting based on the fact that there are valid usecases and the current
behavior can be really really annoying :)

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

Django

unread,
Aug 5, 2014, 9:46:00 AM8/5/14
to django-...@googlegroups.com
#23196: Don't translate empty string as gettext metadata
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Internationalization | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* type: Uncategorized => Cleanup/optimization


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

Django

unread,
Sep 7, 2014, 6:40:06 AM9/7/14
to django-...@googlegroups.com
#23196: Don't translate empty string as gettext metadata
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: yrik
Type: Cleanup/optimization | Status: assigned
Component: Internationalization | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by yrik):

* owner: nobody => yrik
* status: new => assigned


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

Django

unread,
Sep 7, 2014, 8:37:02 AM9/7/14
to django-...@googlegroups.com
#23196: Don't translate empty string as gettext metadata
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: yrik
Type: Cleanup/optimization | Status: assigned
Component: Internationalization | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by yrik):

Handled case with empty string by returning empty string of corresponding
type.

Here is pull request:
https://github.com/django/django/pull/3192

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

Django

unread,
Sep 21, 2014, 11:11:43 AM9/21/14
to django-...@googlegroups.com
#23196: Don't translate empty string as gettext metadata
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: yrik
Type: Cleanup/optimization | Status: closed
Component: Internationalization | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Claude Paroz <claude@…>):

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


Comment:

In [changeset:"11f307a5a8fa66605652e0496c7385e584bfcad7"]:
{{{
#!CommitTicketReference repository=""
revision="11f307a5a8fa66605652e0496c7385e584bfcad7"
Fixed #23196 -- Short-circuited empty string translation

Translating an empty string used to return the gettext catalog
metadata instead of the empty string.
Thanks Ned Batchelder for the suggestion, Tim Graham for the review
and Anton Berezin and Claude Paroz for contributions to the patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23196#comment:5>

Reply all
Reply to author
Forward
0 new messages