Ticket #11118: basecommand.diff

File basecommand.diff, 1.5 KB (added by rvdrijst, 15 years ago)

patch with fix (restore translation)

  • django/core/management/base.py

     
    207207        # like permissions, and those shouldn't contain any translations.
    208208        # But only do this if we can assume we have a working settings file,
    209209        # because django.utils.translation requires settings.
     210        lang = None
    210211        if self.can_import_settings:
    211212            try:
    212213                from django.utils import translation
     214                lang = translation.get_language()
    213215                translation.activate('en-us')
    214216            except ImportError, e:
    215217                # If settings should be available, but aren't,
     
    232234        except CommandError, e:
    233235            sys.stderr.write(self.style.ERROR(str('Error: %s\n' % e)))
    234236            sys.exit(1)
     237        if lang is not None:
     238            # rolls back the temporary 'en-us' language to the one it
     239            # was set to before (useful when called programmaticaly, e.g.
     240            # in testing where the original language should be kept.
     241            try:
     242                from django.utils import translation
     243                translation.activate(lang)
     244            except ImportError, e:
     245                # Should never happen (TM) since it worked above (lang != None)
     246                sys.stderr.write(self.style.ERROR(str('Error: %s\n' % e)))
     247                sys.exit(1)
    235248
    236249    def validate(self, app=None, display_num_errors=False):
    237250        """
Back to Top