[Django] #34268: Internationalization does not localize functional model choices

5 views
Skip to first unread message

Django

unread,
Jan 17, 2023, 12:31:34 PM1/17/23
to django-...@googlegroups.com
#34268: Internationalization does not localize functional model choices
-------------------------------------+-------------------------------------
Reporter: nima-sa | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: | Version: 4.2
Internationalization |
Severity: Release | Keywords: Functional choice
blocker | generation
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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 ...''

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

Django

unread,
Jan 17, 2023, 12:31:49 PM1/17/23
to django-...@googlegroups.com
#34268: Internationalization does not localize functional model choices
-------------------------------------+-------------------------------------
Reporter: nima-sa | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 4.2
Internationalization |
Severity: Release blocker | Resolution:
Keywords: Functional choice | Triage Stage:
generation | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by nima-sa):

* type: Cleanup/optimization => Uncategorized


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

Django

unread,
Jan 17, 2023, 1:35:12 PM1/17/23
to django-...@googlegroups.com
#34268: Internationalization does not localize functional model choices
-------------------------------------+-------------------------------------
Reporter: Nima | Owner: nobody

Type: Uncategorized | Status: new
Component: | Version: 4.2
Internationalization |
Severity: Normal | Resolution:

Keywords: Functional choice | Triage Stage:
generation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* severity: Release blocker => Normal


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

Django

unread,
Jan 18, 2023, 2:03:36 AM1/18/23
to django-...@googlegroups.com
#34268: Internationalization does not localize functional model choices
-------------------------------------+-------------------------------------
Reporter: Nima | Owner: nobody
Type: New feature | Status: closed
Component: | Version: 4.2
Internationalization |
Severity: Normal | Resolution: invalid

Keywords: Functional choice | Triage Stage:
generation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Claude Paroz (added)
* status: new => closed
* resolution: => invalid
* type: Uncategorized => New feature


Comment:

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.

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

Reply all
Reply to author
Forward
0 new messages