HCTzz commented on issue #34084:
URL: https://github.com/apache/superset/issues/34084#issuecomment-3047024554

   > Hi [@HCTzz](https://github.com/HCTzz)! I'm 
[Dosu](https://go.dosu.dev/dosubot) and I’m helping the superset team.
   > 
   > This issue happens because Superset expects the language code sent from 
the backend to exactly match the translation folder name (like `zh_TW`), but 
the backend often sends a simplified code (like `zh`) or an expanded one (like 
`zh_Hant_TW`), which doesn't match your `translations/zh_TW` folder. As a 
result, the frontend loads the wrong or fallback language pack, making the 
zh_TW switch ineffective.
   > 
   > To fix this, you can override the bootstrap locale in your 
`superset/config.py` to normalize any variant (such as `zh`, `zh_Hant_TW`, or 
`zh_Cant_TW`) to `zh_TW`. Here’s an example:
   > 
   > def override_bootstrap_locale(data):
   >     # Normalize all Traditional Chinese variants to zh_TW
   >     if data.get("locale") in ["zh", "zh_Hant_TW", "zh_Cant_TW"]:
   >         data["locale"] = "zh_TW"
   >         data["language_pack"] = get_language_pack("zh_TW")
   >     return data
   > 
   > COMMON_BOOTSTRAP_OVERRIDES_FUNC = override_bootstrap_locale
   > After making this change, rebuild your frontend translations with:
   > 
   > cd superset-frontend/
   > npm run build-translation
   > This ensures the frontend receives and loads the correct language pack for 
Traditional Chinese. For more details, see [this 
discussion](https://github.com/apache/superset/discussions/33594) and [related 
code 
references](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/views/base.py).
   > 
   > If you still see mixed languages, double-check that your `LANGUAGES` 
config includes `"zh_TW"` and that your translation files are up to date.
   > 
   > _To reply, just mention [@dosu](https://go.dosu.dev/dosubot)._
   > 
   > How did I do? 
[Good](https://app.dosu.dev/response-feedback/a8ee40d6-8f22-467f-8132-6fcc94bfed70?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/a8ee40d6-8f22-467f-8132-6fcc94bfed70?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/a8ee40d6-8f22-467f-8132-6fcc94bfed70?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/a8ee40d6-8f22-467f-8132-6fcc94bfed70?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/a8ee40d6-8f22-467f-8132-6fcc94bfed70?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/a8ee40d6-8f22-467f-8132-6fcc94bfed70?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/a8ee40d6-8f22-467f-8132-6fcc94bfed70?feedback_type=other)
  [![Join 
Discord](https://camo.githubusercontent.com/d562c2df5e4567ea41d37f1d91a4da0839d8341037045b103b2da268998de17f/68747470733a2f2f696d672e736869656c64
 
732e696f2f62616467652f6a6f696e2d3538363546323f6c6f676f3d646973636f7264266c6f676f436f6c6f723d7768697465266c6162656c3d)](https://go.dosu.dev/discord-bot)
 [![Share on 
X](https://camo.githubusercontent.com/4649f705e2396d6f328dbc8e800a0509c9c17b3b20253b36706c393df124b93d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f582d73686172652d626c61636b)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/34084)
   
   
   This method will make the frontend work properly, but there are still issues 
in Flask Babel.
   Due to Flask Babel attempting to load internationalization files by 
attempting to load [zh_Cant_TW, zh], which does not exist, zh will be loaded. 
Therefore, Simplified Chinese and Traditional Chinese will always be translated 
into Simplified Chinese in Flask Babel.
   My solution is:
   Rename the translations/zh_TW folder to translations/zh_Cant_TW.


-- 
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