GitHub user dosubot[bot] added a comment to the discussion: Can't translate the 
"Settings" on the menu for brazilian portuguese

<!-- Answer -->
You're correct that the frontend is loading the "pt" translation instead of 
"pt_BR", even when "pt" is removed from the LANGUAGES list. This happens 
because of how the locale is set and passed from the backend to the frontend.

Here's what is happening and how you can address it:

1. **How the locale is set:**  
   The locale sent to the frontend is determined in the backend, specifically 
in the `cached_common_bootstrap_data` function. By default, it uses 
`locale.language`, which will return "pt" for both "pt" and "pt_BR" locales. 
This means the frontend receives "pt" even if your backend is set to "pt_BR" 
[source](https://github.com/apache/superset/blob/master/superset/views/base.py).

2. **Frontend expects the full locale:**  
   The frontend translation system and locale mapping (`LOCALE_MAPPING`) do 
distinguish between "pt" and "pt_BR" 
[source](https://github.com/apache/superset/blob/master/superset-frontend/src/hooks/useLocale.ts).
 If the frontend receives "pt_BR" as the locale, it will load the correct 
Brazilian Portuguese translations.

3. **How to fix:**  
   You need to ensure that the backend sends the full locale code ("pt_BR") to 
the frontend. You can do this by customizing the 
`COMMON_BOOTSTRAP_OVERRIDES_FUNC` in your `superset/config.py` to override the 
`locale` field in the bootstrap data:

   ```python
   def override_bootstrap_locale(data):
       # If the session or user locale is 'pt_BR', force the frontend to use 
'pt_BR'
       if data.get("locale") == "pt":
           data["locale"] = "pt_BR"
       return data

   COMMON_BOOTSTRAP_OVERRIDES_FUNC = override_bootstrap_locale
   ```

   This will ensure that `bootstrapData.common.locale` is set to "pt_BR" when 
appropriate, and the frontend will load the correct translation pack.

4. **Rebuild frontend translations:**  
   After making changes, make sure to rebuild your frontend translations with:
   ```
   cd superset-frontend/
   npm run build-translation
   ```
   [source](https://github.com/apache/superset/discussions/31444)

5. **Verify mapping:**  
   The mapping for "pt_BR" is already present in the frontend, so once the 
correct locale is passed, it should work as expected 
[source](https://github.com/apache/superset/blob/master/superset-frontend/src/hooks/useLocale.ts).

If you follow these steps, the frontend should start using "pt_BR" and display 
the correct translations for Brazilian Portuguese.


<!-- Dosu Comment Footer -->
*To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/ffd7726d-f0e2-4333-8e43-de93ba604d50?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/ffd7726d-f0e2-4333-8e43-de93ba604d50?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/ffd7726d-f0e2-4333-8e43-de93ba604d50?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/ffd7726d-f0e2-4333-8e43-de93ba604d50?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/ffd7726d-f0e2-4333-8e43-de93ba604d50?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/ffd7726d-f0e2-4333-8e43-de93ba604d50?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/ffd7726d-f0e2-4333-8e43-de93ba604d50?feedback_type=other)</sup>&nbsp;&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Sh
 are on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/33594)

GitHub link: 
https://github.com/apache/superset/discussions/33594#discussioncomment-13290287

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: 
notifications-unsubscr...@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to