@contextmanager
def respect_language(language):
 if language:
  prev = translation.get_language()
  translation.activate(language)
  try:
   (yield)
  finally:
   translation.activate(prev)
 else:
  (yield)

@ contextmanager def respect_language ( language ) : if language : prev = translation . get_language ( ) translation . activate ( language ) try : ( yield ) finally : translation . activate ( prev ) else : ( yield )
context manager that changes the current translation language for all code inside the following block .