ERGO1995 commented on code in PR #31646:
URL: https://github.com/apache/superset/pull/31646#discussion_r2151687597


##########
superset/views/base.py:
##########
@@ -347,8 +348,18 @@ def cached_common_bootstrap_data(  # pylint: 
disable=unused-argument
 
 
 def common_bootstrap_payload() -> dict[str, Any]:
+    # get locale from URL, else use default locale
+    locale = get_locale()
+    if request.args.get("locale"):
+        try:
+            locale = Locale.parse(request.args.get("locale"))
+            session["locale"] = str(locale)
+            refresh()

Review Comment:
   Flask-Babel by default will look up the locale once (using our 
@babel.localeselector) and then cache that value for the rest of the request. 
If you change session["locale"] mid-request, Babel would not pick up the new 
value unless you clear its cache. Calling refresh() forces Flask-Babel to:
   
   - Clear its internal cache of the selected locale,
   - Re-invoke the localeselector on the very next translation call,
   - Apply your updated session["locale"] immediately.
   
   Without it, you’d have to wait until the next HTTP request for Babel to see 
the new locale. That’s why, after grabbing ?locale= and writing it into the 
session, we call refresh() so that any translations rendered later in the same 
request use the newly selected language.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to