Permalink
Browse files

Merge branch 'new_i18n_settings' into new_i18n

  • Loading branch information...
2 parents a204712 + 203125e commit 422ceaa842ebda959da681b3c0aa8ad7d546fd36 @digi604 digi604 committed Oct 3, 2012
Showing with 7 additions and 10 deletions.
  1. +7 −10 cms/utils/i18n.py
View
@@ -1,17 +1,14 @@
# -*- coding: utf-8 -*-
+from contextlib import contextmanager
from django.conf import settings
from django.utils import translation
-class force_language(object):
- def __init__(self, new_lang):
- self.new_lang = new_lang
- self.old_lang = translation.get_language()
-
- def __enter__(self):
- translation.activate(self.new_lang)
-
- def __exit__(self, type, value, tb):
- translation.activate(self.old_lang)
+@contextmanager
+def force_language(new_lang):
+ old_lang = translation.get_language()
+ translation.activate(new_lang)
+ yield
+ translation.activate(old_lang)
def get_language_list(site_id=None):

0 comments on commit 422ceaa

Please sign in to comment.