code: def set_locale(ln):
      
      ctx = _request_ctx_stack.top
      if ctx is None:
          raise RuntimeError('Working outside of request context.')
      new_locale = current_app.extensions['babel'].load_locale(ln)
      old_locale = getattr(ctx, 'babel_locale', None)
      setattr(ctx, 'babel_locale', new_locale)
      yield
      setattr(ctx, 'babel_locale', old_locale)
docs: Set Babel localization in request context.
  
      :param ln: Language identifier.