From 9324935c3e67c01f665df9dd3a7197a68f8365a8 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 21 Aug 2015 14:09:29 +0200 Subject: [PATCH] Fixed #25295 -- Restored 'no active translation' after language override Thanks David Nelson Adamec for the report and Tim Graham for the review. --- 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 246936e4034..7311a6145cf 100644 --- a/django/utils/translation/__init__.py +++ b/django/utils/translation/__init__.py @@ -164,7 +164,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 d1e75d97d61..3f1674b9793 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 a4e6fc9fc2a..00e9bf85d91 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -76,6 +76,9 @@ class TranslationTests(SimpleTestCase): 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()