tt-a1i commented on issue #35569:
URL: https://github.com/apache/superset/issues/35569#issuecomment-3707876800
Hey, ran into this exact issue while setting up Superset with Chinese as the
default language. Spent some time digging into the code and I think I found
what's going on.
## The Problem (Two Parts)
### 1. Backend: hardcoded fallback
In `superset/views/base.py`, there's this line:
```python
language = locale.language if locale else "en"
```
When `get_locale()` returns `None` (like for unauthenticated users on the
login page), it just falls back to `"en"` instead of using the
`BABEL_DEFAULT_LOCALE` config. So the frontend gets `locale: "en"` in bootstrap
data and never even tries to load the language pack.
### 2. Frontend: race condition
In `preamble.ts`, the language pack loads in an async IIFE:
```typescript
(async () => {
// load language pack...
})();
// nobody awaits this!
```
And `index.tsx` just does:
```typescript
import 'src/preamble';
ReactDOM.render(<App />, ...); // runs immediately
```
So React starts rendering before the language pack is ready. By the time it
loads, the components already rendered with English text.
## Fix I've Been Using
**Backend:**
```python
language = locale.language if locale else
app.config.get("BABEL_DEFAULT_LOCALE", "en")
```
**Frontend:** Export `initPreamble()` as a function returning
`Promise<void>`, then `await` it before rendering:
```typescript
// index.tsx
(async () => {
try {
await initPreamble();
} finally {
const { default: App } = await import('./App');
ReactDOM.render(<App />, appMountPoint);
}
})();
```
This has been working well in my deployment. Happy to put together a PR if
this approach makes sense to you all.
--
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]