You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "rusackas (via GitHub)" <gi...@apache.org> on 2026/07/05 16:12:30 UTC
Re: [PR] fix(i18n): inject language pack into bootstrap to translate code-split chunks [superset]
rusackas commented on code in PR #39357:
URL: https://github.com/apache/superset/pull/39357#discussion_r3525203560
##########
superset-frontend/src/preamble.ts:
##########
@@ -64,34 +64,53 @@ export default function initPreamble(): Promise<void> {
// Setup SupersetClient early so we can fetch language pack
setupClient({ appRoot: applicationRoot() });
- // Load language pack before rendering
- // Use native fetch to avoid race condition with SupersetClient initialization
+ // Load language pack before rendering.
+ // Prefer the bootstrap-injected pack (stashed on window by the inline
+ // script in spa.html, sourced from common.language_pack) so
+ // module-level `const X = t('...')` calls in code-split chunks all
+ // see a configured translator. Fall back to the async fetch only
+ // when the bootstrap payload didn't carry the pack (e.g. embedded
+ // or a legacy entry that doesn't extend spa.html). See issue #35330.
if (lang !== 'en') {
- const abortController = new AbortController();
- const timeoutId = window.setTimeout(() => {
- abortController.abort();
- }, LANGUAGE_PACK_REQUEST_TIMEOUT_MS);
-
- try {
- const languagePackUrl = makeUrl(`/superset/language_pack/${lang}/`);
- const resp = await fetch(languagePackUrl, {
- signal: abortController.signal,
- });
- if (!resp.ok) {
- throw new Error(`Failed to fetch language pack: ${resp.status}`);
- }
- const json = await resp.json();
- configure({ languagePack: json as LanguagePack });
+ const bootstrapPack =
+ (bootstrapData.common as { language_pack?: LanguagePack })
+ .language_pack ??
+ (typeof window !== 'undefined'
+ ? window.__SUPERSET_LANGUAGE_PACK__
+ : undefined);
+ if (bootstrapPack) {
+ configure({ languagePack: bootstrapPack });
dayjs.locale(lang);
- } catch (err) {
- logging.warn(
- 'Failed to fetch language pack, falling back to default.',
- err,
- );
- configure();
- dayjs.locale('en');
- } finally {
- window.clearTimeout(timeoutId);
+ } else {
Review Comment:
Ahh, you're right about embedded... `EmbeddedView` renders `spa.html` too, so it gets the inline pack.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org