From c177d0690e08628ccb83b021d413ff461f7d6002 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 21 Aug 2015 14:09:29 +0200 Subject: [PATCH] [1.8.x] Fixed #25295 -- Restored 'no active translation' after language override Thanks David Nelson Adamec for the report and Tim Graham for the review. Backport of 9324935c3 from master. --- django/utils/translation/__init__.py | 4 +++- docs/releases/1.8.5.txt | 2 ++ tests/i18n/tests.py | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py index 505d753268..a4c6963f0c 100644 --- a/django/utils/translation/__init__.py +++ b/django/utils/translation/__init__.py @@ -163,7 +163,9 @@ class override(ContextDecorator): deactivate_all() def __exit__(self, exc_type, exc_value, traceback): - if self.deactivate: + if self.old_language is None: + deactivate_all() + elif self.deactivate: deactivate() else: activate(self.old_language) diff --git a/docs/releases/1.8.5.txt b/docs/releases/1.8.5.txt index d1e75d97d6..3f1674b979 100644 --- a/docs/releases/1.8.5.txt +++ b/docs/releases/1.8.5.txt @@ -13,3 +13,5 @@ Bugfixes field that is both a foreign and primary key (:ticket:`24951`). * Fixed a migrations crash with ``GenericForeignKey`` (:ticket:`25040`). +* Made ``translation.override()`` clear the overridden language when a + translation isn't initially active (:ticket:`25295`). diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 470300ee93..58ef0c74a8 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -74,6 +74,9 @@ class TranslationTests(TestCase): self.assertEqual(get_language(), 'de') with translation.override(None): self.assertEqual(get_language(), None) + with translation.override('pl'): + pass + self.assertEqual(get_language(), None) self.assertEqual(get_language(), 'de') finally: deactivate()