Other translation block

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from django.utils.translation import get_language,activate,check_for_language
from django.conf import settings

class Translation():
    def __init__(self,locale):
        self.old_locale = get_language()
        if locale and locale in dict(settings.LANGUAGES) and check_for_language(locale):
            self.locale=locale
        else:
            self.locale=self.old_locale

    def __enter__(self):
        activate(self.locale)

    def __exit__(self,exc_type, exc_val, exc_tb):
        activate(self.old_locale)

More like this

  1. ugettext tag by jezdez 4 years, 11 months ago
  2. Render specific blocks from templates (useful for AJAX) by sciyoshi 5 years ago
  3. Multilingual Models by Archatas 6 years, 2 months ago
  4. Django Dictionary Model by Morgul 1 year, 11 months ago
  5. i18n base model for translatable content by foxbunny 4 years, 10 months ago

Comments

(Forgotten your password?)