Skip to content
22 changes: 20 additions & 2 deletions superset/initialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import wtforms_json
from deprecation import deprecated
from flask import Flask, redirect
from flask import abort, Flask, redirect, request, session
from flask_appbuilder import expose, IndexView
from flask_babel import gettext as __
from flask_babel import gettext as __, refresh
from flask_compress import Compress
from flask_session import Session
from werkzeug.middleware.proxy_fix import ProxyFix
Expand Down Expand Up @@ -701,3 +701,21 @@ class SupersetIndexView(IndexView):
@expose("/")
def index(self) -> FlaskResponse:
return redirect("/superset/welcome/")

@expose("/lang/<string:locale>")
def patch_flask_locale(self, locale):
"""
Change user's locale and redirect back to the previous page.

Overrides FAB's babel.views.LocaleView so we can use the request
Referrer as the redirect target, in case our previous page was actually
served by the frontend (and thus not added to the session's page_history
stack).
"""
if locale not in self.appbuilder.bm.languages:
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
abort(404, description="Locale not supported.")
Comment thread
pomegranited marked this conversation as resolved.
session["locale"] = locale
refresh()
self.update_redirect()
redirect_to = request.headers.get("Referer") or self.get_redirect()
Comment thread
pomegranited marked this conversation as resolved.
Outdated
Comment thread
pomegranited marked this conversation as resolved.
Outdated
return redirect(redirect_to)
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed