You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "jiderox (via GitHub)" <gi...@apache.org> on 2025/10/28 03:00:26 UTC
[D] /superset/language_pack/zh/ [superset]
GitHub user jiderox created a discussion: /superset/language_pack/zh/
在superset本身的界面显示中文是好的,但是在嵌入界面中请求这个接口的时候是不通的,报302状态码重定向到了登录界面。这种问题应该怎么做才能是中文接口正常登录
GitHub link: https://github.com/apache/superset/discussions/35864
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] /superset/language_pack/zh/ [superset]
Posted by "jiderox (via GitHub)" <gi...@apache.org>.
GitHub user jiderox added a comment to the discussion: /superset/language_pack/zh/
<img width="665" height="765" alt="image" src="https://github.com/user-attachments/assets/369bf55d-548a-4244-ad7d-8a4fba1f65a3" />
superset本身的界面翻译是正常的,但是嵌入界面的翻译还是不行,
<img width="510" height="626" alt="image" src="https://github.com/user-attachments/assets/3273ac48-875b-4096-8296-c0622186eb6f" />
我的配置文件
# superset_config.py
# -------------------------------
# FEATURE FLAGS
# -------------------------------
FEATURE_FLAGS = {
# 启用嵌入式 Superset Dashboard
"EMBEDDED_SUPERSET": True,
# 启用 Dashboard 原生过滤器
"DASHBOARD_NATIVE_FILTERS": True,
"DASHBOARD_RBAC": True,
}
# -------------------------------
# Guest Token 配置
# -------------------------------
# 定义可用于 Guest Token 的角色
GUEST_ROLE_NAME="Viewer"
# -------------------------------
# CSRF 配置
# -------------------------------
# 如果嵌入页面通过 API 调用 Guest Token,可以关闭 CSRF
WTF_CSRF_ENABLED = False
# -------------------------------
# X-Frame-Options / CSP 配置
# -------------------------------
# -------------------------------
# 代理修复(可选)
# -------------------------------
# 如果通过 Nginx 或其他反向代理访问,需要启用
ENABLE_PROXY_FIX = True
# -------------------------------
# 示例数据和加载配置
# -------------------------------
# 是否加载示例数据
LOAD_EXAMPLES = False
# 设置默认语言为中文
# ---------------------
# 🌐 多语言设置
# ---------------------
BABEL_DEFAULT_LOCALE = "zh"
#PUBLIC_ROUTES = ['language_pack']
BABEL_DEFAULT_FOLDER = "superset/translations"
LANGUAGES = {
"zh": {"flag": "cn", "name": "简体中文"},
"en": {"flag": "us", "name": "English"},
}
ENABLE_GUEST_TOKEN = True
GUEST_TOKEN_JWT_SECRET = "Xy7L9FvG3k8sDqH0u2b5M1aJz4TqYwPn"
GUEST_TOKEN_JWT_EXP_SECONDS = 3600
GUEST_TOKEN_JWT_AUDIENCE = "superset"
import logging
from superset.translations.utils import get_language_pack
# 初始化 logger
logger = logging.getLogger(__name__)
def override_bootstrap_locale(data):
logger.warning("[DEBUG] override_bootstrap_locale called")
current_locale = data.get("locale")
logger.warning(f"[DEBUG] 当前语言环境: {current_locale}")
# 判断语言环境
if current_locale in ["zh", "zh_CN", "zh_Hans"]:
try:
lang_pack = get_language_pack("zh")
data["locale"] = "zh"
data["language_pack"] = lang_pack
logger.warning(f"language_pack 内容示例: {list(data['language_pack'].items())[:100]}")
logger.warning(f"[DEBUG] ✅ 已注入中文语言包,共 {len(lang_pack)} 条翻译。")
# 👇 这里加中文确认信息
logger.warning("🌏 Superset 已加载中文语言包,嵌入式页面将显示中文。")
except Exception as e:
logger.error(f"[DEBUG] ❌ 注入中文语言包失败: {e}")
else:
logger.warning("[DEBUG] Locale 非中文,跳过语言包注入。")
return data
# 绑定函数
COMMON_BOOTSTRAP_OVERRIDES_FUNC = override_bootstrap_locale
-----------
[root@DMACC2 LC_MESSAGES]# ll
total 836
-rw-rw-r--. 1 azureuser azureuser 313627 Oct 28 07:31 messages.json
-rw-rw-r--. 1 azureuser azureuser 200593 Oct 28 07:55 messages.mo
-rw-r--r--. 1 azureuser azureuser 338039 Oct 27 09:07 messages.po
[root@DMACC2 LC_MESSAGES]# pwd
/data/superset/superset/translations/zh/LC_MESSAGES
这个目录下的编译文件也是好的
GitHub link: https://github.com/apache/superset/discussions/35864#discussioncomment-14802329
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] /superset/language_pack/zh/ [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: /superset/language_pack/zh/
<!-- Greeting -->
Hi @jiderox! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the superset team.
<!-- Answer -->
你遇到的 302 跳转到登录页,是因为 /superset/language_pack/zh/ 这个接口默认需要认证,嵌入式场景下没有有效的登录态或 session,所以会被 Flask AppBuilder 重定向到登录页(302)[参考](https://github.com/apache/superset/discussions/35099#discussioncomment-14370512)。
Superset 6.0 之后,语言包已经不再通过 /superset/language_pack/ 接口动态加载,而是直接打包进前端的 bootstrap 数据,页面初始化时自动注入,不再需要单独请求接口[参考](https://github.com/apache/superset/discussions/34885)。如果你的嵌入式页面还在请求 /superset/language_pack/zh/,建议:
1. 检查你的 Superset 版本和前端代码,确保用的是官方标准的 6.0+ 版本,不要再通过接口动态加载语言包。
2. 如果有自定义代码或老版本逻辑,请升级或调整,改为直接用 bootstrap 里的语言包数据。
3. 如果确实需要接口方式,必须保证嵌入页面有有效的 Superset 登录态(比如通过 guest token 认证),否则所有受保护接口都会 302 跳转[参考](https://github.com/apache/superset/discussions/35099#discussioncomment-14370512)。
总之,推荐升级到标准用法,避免再请求 /superset/language_pack/zh/,这样嵌入式页面就能正常显示中文,无需额外认证处理。
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/8eb08746-b598-4def-b57b-5224a0d33f20?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/8eb08746-b598-4def-b57b-5224a0d33f20?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/8eb08746-b598-4def-b57b-5224a0d33f20?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/8eb08746-b598-4def-b57b-5224a0d33f20?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/8eb08746-b598-4def-b57b-5224a0d33f20?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/8eb08746-b598-4def-b57b-5224a0d33f20?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/8eb08746-b598-4def-b57b-5224a0d33f20?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&
nbsp;[](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/35864)
GitHub link: https://github.com/apache/superset/discussions/35864#discussioncomment-14799636
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] /superset/language_pack/zh/ [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: /superset/language_pack/zh/
<!-- Answer -->
Superset 6.0 的嵌入式仪表盘如果还在请求 /superset/language_pack/zh/,通常说明前端没有正确获取到 bootstrap 里的语言包数据,或者 locale 配置和语言包文件夹名不一致,导致前端 fallback 到动态请求接口(这在 6.0+ 已经废弃)[参考](https://github.com/apache/superset/discussions/34885)。
你可以这样排查和修复:
1. **superset_config.py 里加 locale override**
有时 Superset 后端传给前端的 locale 是 'zh',但实际语言包文件夹是 'zh_CN' 或 'zh_TW',导致找不到。可以用 override 函数强制 locale 和语言包一致:
```python
from superset.translations.utils import get_language_pack
def override_bootstrap_locale(data):
if data.get("locale") == "zh":
data["locale"] = "zh"
data["language_pack"] = get_language_pack("zh")
return data
COMMON_BOOTSTRAP_OVERRIDES_FUNC = override_bootstrap_locale
```
如果你用的是 'zh_CN' 或 'zh_TW',把上面 "zh" 换成对应的 locale。
2. **重建前端语言包**
进入 superset-frontend 目录,执行
```
npm run build-translation
```
然后重启 Superset 服务。
3. **确保 initialBootstrapData 正确传递**
你的 embedDashboard 配置已经传递了 `initialBootstrapData: { common: { locale: 'zh' } }`,但如果前端包没同步或 locale 不匹配,还是会 fallback 到接口请求。
4. **彻底清理缓存和旧前端包**
确保没有老的前端构建缓存,浏览器和服务器都清理一下。
5. **确认 superset-frontend 代码和 superset_config.py 都是 6.0+ 的标准实现**
避免有自定义或老版本代码路径。
如果这样配置后,嵌入式页面依然请求 /superset/language_pack/zh/,可以在 override_bootstrap_locale 里加 print/log,确认函数被调用,且 data["language_pack"] 正确注入。这样前端就不会再请求接口,而是直接用 bootstrap 里的语言包数据,嵌入式页面就能正常显示中文了。[参考](https://github.com/apache/superset/discussions/33594#discussioncomment-13290644)
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=696121a9-c583-4e14-938a-4e349aadd478) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)
GitHub link: https://github.com/apache/superset/discussions/35864#discussioncomment-14799855
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] /superset/language_pack/zh/ [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: /superset/language_pack/zh/
<!-- Answer -->
Superset 6.0 的嵌入式仪表盘如果还在请求 /superset/language_pack/zh/,通常说明前端没有正确获取到 bootstrap 里的语言包数据,或者 locale 配置和语言包文件夹名不一致,导致前端 fallback 到动态请求接口(这在 6.0+ 已经废弃)[参考](https://github.com/apache/superset/discussions/34885)。
你可以这样排查和修复:
1. **superset_config.py 里加 locale override**
有时 Superset 后端传给前端的 locale 是 'zh',但实际语言包文件夹是 'zh_CN' 或 'zh_TW',导致找不到。可以用 override 函数强制 locale 和语言包一致:
```python
from superset.translations.utils import get_language_pack
def override_bootstrap_locale(data):
if data.get("locale") == "zh":
data["locale"] = "zh"
data["language_pack"] = get_language_pack("zh")
return data
COMMON_BOOTSTRAP_OVERRIDES_FUNC = override_bootstrap_locale
```
如果你用的是 'zh_CN' 或 'zh_TW',把上面 "zh" 换成对应的 locale。
2. **重建前端语言包**
进入 superset-frontend 目录,执行
```
npm run build-translation
```
然后重启 Superset 服务。
3. **确保 initialBootstrapData 正确传递**
你的 embedDashboard 配置已经传递了 `initialBootstrapData: { common: { locale: 'zh' } }`,但如果前端包没同步或 locale 不匹配,还是会 fallback 到接口请求。
4. **彻底清理缓存和旧前端包**
确保没有老的前端构建缓存,浏览器和服务器都清理一下。
5. **确认 superset-frontend 代码和 superset_config.py 都是 6.0+ 的标准实现**
避免有自定义或老版本代码路径。
如果这样配置后,嵌入式页面依然请求 /superset/language_pack/zh/,可以在 override_bootstrap_locale 里加 print/log,确认函数被调用,且 data["language_pack"] 正确注入。这样前端就不会再请求接口,而是直接用 bootstrap 里的语言包数据,嵌入式页面就能正常显示中文了。[参考](https://github.com/apache/superset/discussions/33594#discussioncomment-13290644)
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/696121a9-c583-4e14-938a-4e349aadd478?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/696121a9-c583-4e14-938a-4e349aadd478?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/696121a9-c583-4e14-938a-4e349aadd478?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/696121a9-c583-4e14-938a-4e349aadd478?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/696121a9-c583-4e14-938a-4e349aadd478?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/696121a9-c583-4e14-938a-4e349aadd478?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/696121a9-c583-4e14-938a-4e349aadd478?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&
nbsp;[](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/35864)
GitHub link: https://github.com/apache/superset/discussions/35864#discussioncomment-14799855
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] /superset/language_pack/zh/ [superset]
Posted by "jiderox (via GitHub)" <gi...@apache.org>.
GitHub user jiderox added a comment to the discussion: /superset/language_pack/zh/
前端代码sdk嵌入
<template>
<div class="amount-appeal-page">
<div class="h-[70vh] border rounded shadow-lg">
<div id="my-superset-container"></div>
</div>
</div>
</template>
<style>
#my-superset-container iframe {
width: 100%;
height: 100vh;
border: 0;
overflow: hidden;
}
</style>
<script>
import { embedDashboard } from '@superset-ui/embedded-sdk'
import { getAction } from '@/api/manage'
import { USER_INFO, USER_AUTH } from '@/store/mutation-types'
export default {
data() {
return {
tabIndex: 'product_tag',
info: {},
dashboardId: '',
dashboardUrl: ''
}
},
async mounted() {
await getAction('/sys/bi/superSet/getSupersetDomain/').then(res => {
this.dashboardUrl = res.result
})
this.embedDashboardTabs()
},
methods: {
async embedDashboardTabs() {
await getAction(`/sys/bi/superSet/getResourceIdByResourceTag/${this.tabIndex}`).then(res => {
this.dashboardId = res.result
})
console.log(this.dashboardUrl + '', 'this.dashboardUrl', this.dashboardId, 'this')
embedDashboard({
id: this.dashboardId, // given by the Superset embedding UI
supersetDomain: this.dashboardUrl,
mountPoint: document.getElementById('my-superset-container'), // any html element that can contain an iframe
fetchGuestToken: () => this.fetchEmbedGuestToken(), // guest_token
dashboardUiConfig: {
hideTitle: true,
hideTab: false,
hideChartControls: false,
filters: {
expanded: true,
visible: true
} // dashboard UI config: hideTitle, hideTab, hideChartControls (optional)
},
initialBootstrapData: {
common: { locale: 'zh' }
},
debug: true
})
},
async fetchEmbedGuestToken() {
return new Promise(resolve => {
getAction('/sys/bi/superSet/fetchEmbedGuestToken/', {
dashboardTag: this.tabIndex
}).then(res => {
if (res.success) {
let token = res.result
console.log('token: ' + token)
resolve(token)
}
})
})
}
}
}
</script>
GitHub link: https://github.com/apache/superset/discussions/35864#discussioncomment-14802495
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] /superset/language_pack/zh/ [superset]
Posted by "jiderox (via GitHub)" <gi...@apache.org>.
GitHub user jiderox added a comment to the discussion: /superset/language_pack/zh/
我在superset_config中配置了BABEL_DEFAULT_LOCALE = "zh"
才会有这个中文的请求接口,我的superset的前后端版本都是6.0;我嵌入sdk中是这样配置的
embedDashboard({
id: this.dashboardId, // given by the Superset embedding UI
supersetDomain: this.dashboardUrl,
mountPoint: document.getElementById('my-superset-container'), // any html element that can contain an iframe
fetchGuestToken: () => this.fetchEmbedGuestToken(), // guest_token
dashboardUiConfig: {
hideTitle: true,
hideTab: false,
hideChartControls: false,
filters: {
expanded: true,
visible: true
} // dashboard UI config: hideTitle, hideTab, hideChartControls (optional)
},
initialBootstrapData: {
common: { locale: 'zh' }
},
debug: true
})
,目前只有嵌入的页面中文显示有问题,我该怎么做
GitHub link: https://github.com/apache/superset/discussions/35864#discussioncomment-14799839
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] /superset/language_pack/zh/ [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: /superset/language_pack/zh/
<!-- Greeting -->
Hi @jiderox! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the superset team.
<!-- Answer -->
你遇到的 302 跳转到登录页,是因为 /superset/language_pack/zh/ 这个接口默认需要认证,嵌入式场景下没有有效的登录态或 session,所以会被 Flask AppBuilder 重定向到登录页(302)[参考](https://github.com/apache/superset/discussions/35099#discussioncomment-14370512)。
Superset 6.0 之后,语言包已经不再通过 /superset/language_pack/ 接口动态加载,而是直接打包进前端的 bootstrap 数据,页面初始化时自动注入,不再需要单独请求接口[参考](https://github.com/apache/superset/discussions/34885)。如果你的嵌入式页面还在请求 /superset/language_pack/zh/,建议:
1. 检查你的 Superset 版本和前端代码,确保用的是官方标准的 6.0+ 版本,不要再通过接口动态加载语言包。
2. 如果有自定义代码或老版本逻辑,请升级或调整,改为直接用 bootstrap 里的语言包数据。
3. 如果确实需要接口方式,必须保证嵌入页面有有效的 Superset 登录态(比如通过 guest token 认证),否则所有受保护接口都会 302 跳转[参考](https://github.com/apache/superset/discussions/35099#discussioncomment-14370512)。
总之,推荐升级到标准用法,避免再请求 /superset/language_pack/zh/,这样嵌入式页面就能正常显示中文,无需额外认证处理。
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=8eb08746-b598-4def-b57b-5224a0d33f20) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)
GitHub link: https://github.com/apache/superset/discussions/35864#discussioncomment-14799636
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org