#25720 closed Bug (fixed)
1.8.x regression: Py2 gettext() returns unicode for bytestring input
Reported by: | Marti Raudsepp | Owned by: | nobody |
---|---|---|---|
Component: | Internationalization | Version: | 1.8 |
Severity: | Release blocker | Keywords: | regression |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
See pull request for the fix: https://github.com/django/django/pull/5615
In Django 1.7 and earlier, the django.utils.translation.gettext()
function always returned UTF-8 bytestrings for bytestring inputs. In Django 1.8, this behavior changed: when a translation is active, it now returns unicode
objects instead. (when translations are not activated, it returns bytestrings).
This does not appear to be an intentional change, there is nothing about this in release notes or documentation. Probably an unintended side-effect of the refactoring in commit a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45:
I narrowed it down to the removal of this line in __init__
:
self.set_output_charset('utf-8')
After re-adding the line it works as expected again (tests included). I don't understand gettext enough to know why the addition in the refactor commit gettext_module.translation(..., codeset='utf-8', ...)
doesn't have the same effect.
This fix was sponsored by voicecom.ee.
Change History (9)
comment:1 by , 9 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|---|
Type: | Uncategorized → Bug |
comment:2 by , 9 years ago
As for me, I don't understand why we keep this obsolete method at all :-/
comment:3 by , 9 years ago
Do you mean the gettext()
function or something else? (sorry for complete lack of knowledge here!)
comment:4 by , 9 years ago
Yes, I don't see the need of non-unicode translations. But as it will die with Python 2 anyway, I don't want to fight about this.
comment:8 by , 9 years ago
@claudep Some native Python 2 modules still don't get along with Unicode strings, such as the csv
module, which broke our app along with this Django regression.
comment:9 by , 9 years ago
Thanks for the use case example. I know the csv
limitation in Python2, but when I had to cope with it, I ensured to encode the strings before passing them to the module. Anyway, I don't want to argue about removal now.
Looks good pending some cosmetic comments. Claude, could you check it too?