Opened 22 months ago
Closed 22 months ago
#34268 closed New feature (invalid)
Internationalization does not localize functional model choices
Reported by: | Nima | Owned by: | nobody |
---|---|---|---|
Component: | Internationalization | Version: | 4.2 |
Severity: | Normal | Keywords: | Functional choice generation |
Cc: | Claude Paroz | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Given a lazy/functional choice generator for a model, Django's internationalization cannot fully comprehend the lazy localizable text generated by the function.
Imagine a base class:
# gettext_lazy also does not work from django.utils.translation import gettext as _ class SelectableModelField: @classmethod def make_choices(cls): return [(value, _(key.replace('_', ' '))) for (key, value) in vars(cls).items() if not (key[-1] + key[0]).__contains__('_')] bool_choices = ((True, 'Yes'), (False, 'No'))
which is inherited by:
class User(models.Model): class __UserType__(SelectableModelField): basic = 0 premium = 1 user_type = models.PositiveSmallIntegerField(choices=__UserType__.make_choices())
the django.po file will not contain the functionally-generated choices after running python manage.py makemessages -l ...
Change History (3)
comment:1 by , 22 months ago
Type: | Cleanup/optimization → Uncategorized |
---|
comment:2 by , 22 months ago
Severity: | Release blocker → Normal |
---|
comment:3 by , 22 months ago
Cc: | added |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Type: | Uncategorized → New feature |
Note:
See TracTickets
for help on using tickets.
Thanks for this ticket, however I don't think it's feasible (not only in Django but in general). You can only translate a fixed list of strings.