#16690: Add translation.activate decorator/context manager
-------------------------+--------------------------------------
 Reporter:  ralphje      |          Owner:  nobody
     Type:  New feature  |         Status:  new
Milestone:               |      Component:  Internationalization
  Version:  1.3          |       Severity:  Normal
 Keywords:               |   Triage Stage:  Unreviewed
Has patch:  0            |  Easy pickings:  0
    UI/UX:  0            |
-------------------------+--------------------------------------
 Currently, internationalization outside of templates and views requires
 several lines of code, identically each time:

 {{{
 from django.utils import translation
 def welcome_translated(language):
     cur_language = translation.get_language()
     try:
         translation.activate(language)
         text = translation.ugettext('welcome')
     finally:
         translation.activate(cur_language)
     return text
 }}}
 (source: https://docs.djangoproject.com/en/dev/howto/i18n/)

 However, this could easily be fitted within both decorators and context
 managers, allowing the following syntax:

 {{{
 @translation.activate(language)
 def welcome_translated(language):
     return translation.ugettext('welcome')
 }}}
 or
 {{{
 def welcome_translated(language):
     with translation.activate(language):
         return translation.ugettext('welcome')
 }}}

 This would decrease the lines of code and the developer would not have to
 care for the case when the execution somehow fails and forgets to add the
 try/finally clause.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16690>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to