#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070185c0c93a7a-95e1bc5e-dd42-4db3-8384-21c009ca4328-000000%40eu-central-1.amazonses.com.

Reply via email to