Opened 10 years ago
Closed 10 years ago
#23196 closed Cleanup/optimization (fixed)
Don't translate empty string as gettext metadata
Reported by: | Ned Batchelder | Owned by: | Iurii Kriachko |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
(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? :)
Change History (5)
comment:1 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 10 years ago
Type: | Uncategorized → Cleanup/optimization |
---|
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 10 years ago
Handled case with empty string by returning empty string of corresponding type.
Here is pull request:
https://github.com/django/django/pull/3192
comment:5 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Accepting based on the fact that there are valid usecases and the current behavior can be really really annoying :)