django/django — pull request #3088 by tchaumeny (2014-08-19 17:06:02+00:00)
Title: Allow the use of translation.override as a decorator

This PR allows the use of `translation.override` as a decorator, as suggested in https://code.djangoproject.com/ticket/16690#comment:2

Although a comment in this ticket suggests that it is not useful, I have experienced several cases where it is. For instance, I have some functions which are sending mail and I want those mails to be translated in some default language which is not the one of the user doing the action. Having the function decorated is better in terms of readability than a long `with` statement which introducing indentation.

When turning `translation.override` into a `decorator`, I realized there was some duplicated code in Django doing exactly what a `ContextDecorator` (https://docs.python.org/3/library/contextlib.html#contextlib.ContextDecorator) is doing. The first commit backports a simple implementation of `ContextDecorator` and uses it where appropriate.