You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "ViniciusCavalcanteSantos (via GitHub)" <gi...@apache.org> on 2025/05/30 12:23:12 UTC
[D] Translation of time passed [superset]
GitHub user ViniciusCavalcanteSantos created a discussion: Translation of time passed
I have translated most o the site to pt_BR, but i can't translate things like "7 seconds ago", "a minute ago", "2 minutes ago", "2 days ago" for example in the Last modified column of tables. How can i translate it?
GitHub link: https://github.com/apache/superset/discussions/33630
----
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] Translation of time passed [superset]
Posted by "ViniciusCavalcanteSantos (via GitHub)" <gi...@apache.org>.
GitHub user ViniciusCavalcanteSantos added a comment to the discussion: Translation of time passed
This problem i have already solved, i'll send to you the solution it's a little simpler you just need to add the currency to the list in your superset_config.py
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321594
----
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] Translation of time passed [superset]
Posted by "ViniciusCavalcanteSantos (via GitHub)" <gi...@apache.org>.
GitHub user ViniciusCavalcanteSantos deleted a comment on the discussion: Translation of time passed
@dosu
Inside changed_on_humanized `print("LOCALE: ", get_locale())` and it returned "en" instead of "pt_BR". I already have configured the babel locale on the superset_config.py with:
```
LANGUAGES = {
"en": {"flag": "us", "name": "English"},
"es": {"flag": "es", "name": "Spanish"},
"pt_BR": {"flag": "br", "name": "Brazilian Portuguese"}
}
BABEL_DEFAULT_LOCALE = 'pt_BR'
```
The other problem is that the code:
```
delta = datetime.utcnow() - self.changed_on
return format_timedelta(delta, granularity='second')
```
returned "in 3 days" instead of something like "3 days ago" as it was before, in pt_BR it return "em 3 dias", maybe i could use the tn function to translate it?
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13322351
----
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] Translation of time passed [superset]
Posted by "ViniciusCavalcanteSantos (via GitHub)" <gi...@apache.org>.
GitHub user ViniciusCavalcanteSantos edited a comment on the discussion: Translation of time passed
This problem i have already solved, i'll send to you the solution it's a little simpler you just need to add the currency to the list in your superset_config.py.
Look for superset/config.py it starts in the line 400, there you will see the configurations you can change, there you will be able to see the options you can override in the config file to add BRL as a option.
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321594
----
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] Translation of time passed [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Translation of time passed
<!-- Answer -->
The time-related strings like "7 seconds ago", "a minute ago", etc., in the "Last modified" column are generated using the dayjs library with its relativeTime plugin, which supports localization for pt_BR. Superset dynamically sets the locale for dayjs based on your language settings, using a hook that reads the locale from the Redux store (which is typically set via Flask-Babel) and loads the correct locale files for both dayjs and UI components. If your site is already set to pt_BR and most of the interface is translated, these time strings should also appear in Portuguese, such as "há 2 minutos" for "2 minutes ago"—provided the locale is correctly set and loaded in your Superset instance.
If you still see these strings in English, check that your Superset configuration is actually setting the locale to pt_BR and that the dayjs pt_BR locale is being loaded. You can verify this by ensuring your browser's language or Superset's user profile language is set to Brazilian Portuguese, and that there are no errors loading locale files in the browser console. No manual translation is needed for these strings, as dayjs provides full support for pt_BR out of the box. For reference, see how Superset handles locale loading and dayjs configuration [here](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset-frontend/src/hooks/useLocale.ts) and [here](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset-frontend/src/utils/dates.ts).
<!-- 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=b67d4b58-f034-4826-8378-a1dceab08a0a) [](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/33630#discussioncomment-13321084
----
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] Translation of time passed [superset]
Posted by "ViniciusCavalcanteSantos (via GitHub)" <gi...@apache.org>.
GitHub user ViniciusCavalcanteSantos added a comment to the discussion: Translation of time passed
@dosu
i have looked in the code an it seems that this information comes from the backend, a call is made for the api:
`/api/v1/chart/?q=(order_column:changed_on_delta_humanized,order_direction:desc,page:0,page_size:25)`
then it receives back the time in json format, like: `result.[id].changed_on_delta_humanized`,
where the superset receives this request?, and how to translate changed_on_delta_humanized?
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321788
----
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] Translation of time passed [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Translation of time passed
<!-- Answer -->
Your manual attempts to set the dayjs locale (e.g., with "pt_BR", "pt-br", "pt-BR", "pt", "de") do not work because, in the current Superset frontend code, there is no global connection between the user/app-chosen language and the dayjs locale. By default, dayjs only loads the English locale, and only updates the "en" locale for a custom invalidDate message. Other locales (like pt_BR) are not loaded or set globally unless explicitly handled in the code. This means that even if you call dayjs.locale('pt_BR'), it will not translate relative time strings unless the pt_BR locale is actually imported and registered with dayjs at runtime.
To make translations work, you need to ensure that:
1. The pt_BR locale is imported from dayjs (e.g., import 'dayjs/locale/pt-br';).
2. The locale is set using the correct string (dayjs uses 'pt-br', not 'pt_BR').
3. The locale is set before any relative time formatting is done.
Example:
```js
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import 'dayjs/locale/pt-br';
dayjs.extend(relativeTime);
dayjs.locale('pt-br');
console.log(dayjs().from(dayjs().subtract(2, 'minute'))); // "há 2 minutos"
```
In Superset, this integration is not handled globally, so you may need to add this import and locale setting in your custom code or in a place that runs before any date formatting occurs. Also, check the browser console for errors about missing locale files.
For more details on how dayjs is configured in Superset, see the code where plugins are extended and the locale is updated for 'en' only, but not for other languages: [superset-frontend/src/utils/dates.ts](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset-frontend/src/utils/dates.ts).
If you want this to work out-of-the-box for all users, you would need to ensure that the correct locale is imported and set based on the user's language selection, which is not currently done globally in Superset.
<!-- 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=a306369c-6ae9-4329-a645-e2e96cc280ce) [](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/33630#discussioncomment-13321260
----
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] Translation of time passed [superset]
Posted by "ViniciusCavalcanteSantos (via GitHub)" <gi...@apache.org>.
GitHub user ViniciusCavalcanteSantos edited a comment on the discussion: Translation of time passed
This problem i have already solved, i'll send to you the solution it's a little simpler you just need to add the currency to the list in your superset_config.py.
Look for superset/config.py it starts in the line 400, there you will see the configurations you can change, there you will be able to see the options you can override in the config file to add BRL as a option.
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321594
----
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] Translation of time passed [superset]
Posted by "ViniciusCavalcanteSantos (via GitHub)" <gi...@apache.org>.
GitHub user ViniciusCavalcanteSantos added a comment to the discussion: Translation of time passed
@dosu
Inside changed_on_humanized `print("LOCALE: ", get_locale())` and it returned "en" instead of "pt_BR". I already have configured the babel locale on the superset_config.py with:
```
LANGUAGES = {
"en": {"flag": "us", "name": "English"},
"es": {"flag": "es", "name": "Spanish"},
"pt_BR": {"flag": "br", "name": "Brazilian Portuguese"}
}
BABEL_DEFAULT_LOCALE = 'pt_BR'
```
The other problem is that the code:
```
delta = datetime.utcnow() - self.changed_on
return format_timedelta(delta, granularity='second')
```
returned "in 3 days" instead of something like "3 days ago" as it was before, in pt_BR it return "em 3 dias", maybe i could use the __() function to translate it?
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13322415
----
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] Translation of time passed [superset]
Posted by "ViniciusCavalcanteSantos (via GitHub)" <gi...@apache.org>.
GitHub user ViniciusCavalcanteSantos added a comment to the discussion: Translation of time passed
@dosu
if (typeof window !== 'undefined') {
configure({ languagePack: bootstrapData.common.language_pack });
dayjs.locale(bootstrapData.common.locale);
} else {
configure();
}
i tried changing manually "dayjs.locale()" the normal is to be passed "pt_BR", i tried passing "pt-br", "pt-BR", "pt" and other languages like "de" but it did not translate.
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321246
----
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] Translation of time passed [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Translation of time passed
<!-- Answer -->
The time-related strings like "7 seconds ago", "a minute ago", etc., in the "Last modified" column are generated using the dayjs library with its relativeTime plugin, which supports localization for pt_BR. Superset dynamically sets the locale for dayjs based on your language settings, using a hook that reads the locale from the Redux store (which is typically set via Flask-Babel) and loads the correct locale files for both dayjs and UI components. If your site is already set to pt_BR and most of the interface is translated, these time strings should also appear in Portuguese, such as "há 2 minutos" for "2 minutes ago"—provided the locale is correctly set and loaded in your Superset instance.
If you still see these strings in English, check that your Superset configuration is actually setting the locale to pt_BR and that the dayjs pt_BR locale is being loaded. You can verify this by ensuring your browser's language or Superset's user profile language is set to Brazilian Portuguese, and that there are no errors loading locale files in the browser console. No manual translation is needed for these strings, as dayjs provides full support for pt_BR out of the box. For reference, see how Superset handles locale loading and dayjs configuration [here](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset-frontend/src/hooks/useLocale.ts) and [here](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset-frontend/src/utils/dates.ts).
<!-- 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/b67d4b58-f034-4826-8378-a1dceab08a0a?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b67d4b58-f034-4826-8378-a1dceab08a0a?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b67d4b58-f034-4826-8378-a1dceab08a0a?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b67d4b58-f034-4826-8378-a1dceab08a0a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b67d4b58-f034-4826-8378-a1dceab08a0a?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b67d4b58-f034-4826-8378-a1dceab08a0a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b67d4b58-f034-4826-8378-a1dceab08a0a?feedback_type=other)</sup> [](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/33630)
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321084
----
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] Translation of time passed [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Translation of time passed
<!-- Answer -->
The backend receives the `/api/v1/chart/` request in the `ChartRestApi` class (`superset/charts/api.py`), which operates on the `Slice` model. The field `changed_on_delta_humanized` is generated by the `changed_on_humanized` property in the model mixin (`superset/models/helpers.py`). This property uses the Python `humanize.naturaltime` function to create human-readable time differences, like "2 minutes ago" or "a day ago" [(source)](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset/models/helpers.py).
Currently, this value is always rendered in English because the `humanize` library does not support localization out-of-the-box, and Superset does not add any translation layer for this field on the backend. Even though Flask-Babel is available in Superset, it is not used for these relative time strings.
To translate `changed_on_delta_humanized`, you would need to replace or wrap the `humanize.naturaltime` call with a localization-aware solution, such as using Flask-Babel's `format_timedelta` or another library that supports your target language. This would require a code change in the backend where `changed_on_humanized` is defined.
Let me know if you want more details on how to implement this.
<!-- 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/0cddda57-7372-4d96-8f8d-d50d074cf6fe?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/0cddda57-7372-4d96-8f8d-d50d074cf6fe?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/0cddda57-7372-4d96-8f8d-d50d074cf6fe?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/0cddda57-7372-4d96-8f8d-d50d074cf6fe?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/0cddda57-7372-4d96-8f8d-d50d074cf6fe?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/0cddda57-7372-4d96-8f8d-d50d074cf6fe?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/0cddda57-7372-4d96-8f8d-d50d074cf6fe?feedback_type=other)</sup> [](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/33630)
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321807
----
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] Translation of time passed [superset]
Posted by "ViniciusCavalcanteSantos (via GitHub)" <gi...@apache.org>.
GitHub user ViniciusCavalcanteSantos added a comment to the discussion: Translation of time passed
@dosu
yeah, explain it, i would like to implement this change
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321837
----
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] Translation of time passed [superset]
Posted by "ViniciusCavalcanteSantos (via GitHub)" <gi...@apache.org>.
GitHub user ViniciusCavalcanteSantos edited a comment on the discussion: Translation of time passed
This problem i have already solved, i'll send to you the solution it's a little simpler you just need to add the currency to the list in your superset_config.py.
Look for superset/config.py it starts in the line 400, there you will see the configurations you can change, there you will be able to see the options you can override in the config file to add BRL as a option.
@dosu explain it
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321594
----
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] Translation of time passed [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Translation of time passed
<!-- Answer -->
To localize the changed_on_delta_humanized field in Superset’s backend, you need to replace the use of humanize.naturaltime (which always returns English) with Flask-Babel’s format_timedelta, which supports translations based on the current locale.
Here’s how you can implement this:
1. In superset/models/helpers.py, locate the AuditMixinNullable class. The changed_on_humanized property currently looks like this:
```python
@property
def changed_on_humanized(self) -> str:
return humanize.naturaltime(datetime.now() - self.changed_on)
```
2. Replace humanize.naturaltime with Flask-Babel’s format_timedelta:
```python
from flask_babel import format_timedelta
from datetime import datetime
@property
def changed_on_humanized(self) -> str:
if self.changed_on:
delta = datetime.utcnow() - self.changed_on
return format_timedelta(delta, granularity='second')
return ""
```
You can adjust the granularity ('second', 'minute', 'hour', etc.) to match your needs. format_timedelta will automatically use the user’s locale if Flask-Babel is configured correctly in your Superset instance.
3. Do the same for created_on_humanized if you want that field localized as well.
4. Make sure your Superset backend is configured for Babel and your desired languages are enabled in superset/config.py:
```python
BABEL_DEFAULT_LOCALE = "en"
BABEL_DEFAULT_FOLDER = "superset/translations"
LANGUAGES = {
"en": {"flag": "us", "name": "English"},
"pt_BR": {"flag": "br", "name": "Brazilian Portuguese"},
# ... other languages ...
}
```
5. If you haven’t already, generate and update your translation files using pybabel:
```sh
pybabel extract -F superset/translations/babel.cfg -o superset/translations/messages.pot .
pybabel update -i superset/translations/messages.pot -d superset/translations
pybabel compile -d superset/translations
```
If you need to add a new language:
```sh
pybabel init -i superset/translations/messages.pot -d superset/translations -l pt_BR
```
6. Restart your Superset backend and test the API (e.g., /api/v1/chart/) with your user or browser set to pt_BR. The changed_on_delta_humanized field should now be localized.
References:
- [AuditMixinNullable implementation](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset/models/helpers.py)
- [pybabel translation management](https://github.com/apache/superset/issues/31396)
- [Superset i18n backend config](https://github.com/apache/superset/discussions/31444)
Let me know if you need a more detailed code example or run into any issues!
<!-- 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).*
---
Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-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=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=c3cd4cc4-0cb4-4c88-a5f9-0d48c336db99) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-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=static-docs-share-team&utm_term=apache%2Fsuperset)
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321869
----
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] Translation of time passed [superset]
Posted by "DanielViniAssis (via GitHub)" <gi...@apache.org>.
GitHub user DanielViniAssis added a comment to the discussion: Translation of time passed
Deu certo? estou tentando o mesmo e trocar a moeda para BRL (R$) mas não estou conseguindo
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321443
----
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] Translation of time passed [superset]
Posted by "ViniciusCavalcanteSantos (via GitHub)" <gi...@apache.org>.
GitHub user ViniciusCavalcanteSantos added a comment to the discussion: Translation of time passed
@dosu
Inside changed_on_humanized `print("LOCALE: ", get_locale())` and it returned "en" instead of "pt_BR". I already have configured the babel locale on the superset_config.py with:
```
LANGUAGES = {
"en": {"flag": "us", "name": "English"},
"es": {"flag": "es", "name": "Spanish"},
"pt_BR": {"flag": "br", "name": "Brazilian Portuguese"}
}
BABEL_DEFAULT_LOCALE = 'pt_BR'
```
The other problem is that the code:
```
delta = datetime.utcnow() - self.changed_on
return format_timedelta(delta, granularity='second')
```
returned "in 3 days" instead of something like "3 days ago" as it was before, in pt_BR it return "em 3 dias", maybe i could use the tn function to translate it?
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13322351
----
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] Translation of time passed [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Translation of time passed
<!-- Answer -->
Your locale issue is likely because, in Superset, the locale is determined by the user session and not just by the config file. Even if you set `BABEL_DEFAULT_LOCALE = 'pt_BR'` and include `'pt_BR'` in `LANGUAGES`, the locale will default to `'en'` unless the user session or request explicitly sets it. The locale is stored in the session under the key `"locale"`, and you can change it using the `/lang/<locale>` endpoint or by switching the language in the UI. If you want all users to default to `'pt_BR'`, make sure no other code or browser/user preference is overriding it, and that your session is fresh after changing the config. See [how Superset manages locale in the session](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset/initialization/__init__.py).
For the time delta formatting: Flask-Babel's `format_timedelta` returns "in 3 days" or "em 3 dias" by default because it tries to infer the direction (future/past) from the sign of the timedelta. If you want the output to always be "3 days ago" (or "há 3 dias" in pt_BR), you should pass the `direction="past"` argument:
```python
from flask_babel import format_timedelta
from datetime import datetime
@property
def changed_on_humanized(self) -> str:
if self.changed_on:
delta = datetime.utcnow() - self.changed_on
return format_timedelta(delta, granularity='second', direction='past')
return ""
```
This will force the output to use the "ago" form in all supported languages.
The `__()` function (or `_()`) is used for translating static strings, not for formatting timedeltas. It won't help here—`format_timedelta` is the right tool, just make sure to use the `direction` parameter for the "ago" style output.
If you want to ensure the frontend also gets the correct locale (for things like dayjs), you may need to override the bootstrap data as described [here](https://github.com/apache/superset/discussions/33594).
Let me know if you need more details or run into any other issues!
<!-- 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).*
---
Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-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=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=4fc93444-9c09-41c8-8968-4cfbde4a2209) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-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=static-docs-share-team&utm_term=apache%2Fsuperset)
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13322460
----
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] Translation of time passed [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Translation of time passed
<!-- Answer -->
Your locale issue is likely because, in Superset, the locale is determined by the user session and not just by the config file. Even if you set `BABEL_DEFAULT_LOCALE = 'pt_BR'` and include `'pt_BR'` in `LANGUAGES`, the locale will default to `'en'` unless the user session or request explicitly sets it. The locale is stored in the session under the key `"locale"`, and you can change it using the `/lang/<locale>` endpoint or by switching the language in the UI. If you want all users to default to `'pt_BR'`, make sure no other code or browser/user preference is overriding it, and that your session is fresh after changing the config. See [how Superset manages locale in the session](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset/initialization/__init__.py).
For the time delta formatting: Flask-Babel's `format_timedelta` returns "in 3 days" or "em 3 dias" by default because it tries to infer the direction (future/past) from the sign of the timedelta. If you want the output to always be "3 days ago" (or "há 3 dias" in pt_BR), you should pass the `direction="past"` argument:
```python
from flask_babel import format_timedelta
from datetime import datetime
@property
def changed_on_humanized(self) -> str:
if self.changed_on:
delta = datetime.utcnow() - self.changed_on
return format_timedelta(delta, granularity='second', direction='past')
return ""
```
This will force the output to use the "ago" form in all supported languages.
The `__()` function (or `_()`) is used for translating static strings, not for formatting timedeltas. It won't help here—`format_timedelta` is the right tool, just make sure to use the `direction` parameter for the "ago" style output.
If you want to ensure the frontend also gets the correct locale (for things like dayjs), you may need to override the bootstrap data as described [here](https://github.com/apache/superset/discussions/33594).
Let me know if you need more details or run into any other issues!
<!-- 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/4fc93444-9c09-41c8-8968-4cfbde4a2209?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/4fc93444-9c09-41c8-8968-4cfbde4a2209?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/4fc93444-9c09-41c8-8968-4cfbde4a2209?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/4fc93444-9c09-41c8-8968-4cfbde4a2209?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4fc93444-9c09-41c8-8968-4cfbde4a2209?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/4fc93444-9c09-41c8-8968-4cfbde4a2209?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/4fc93444-9c09-41c8-8968-4cfbde4a2209?feedback_type=other)</sup> [](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/33630)
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13322460
----
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] Translation of time passed [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Translation of time passed
<!-- Answer -->
Your manual attempts to set the dayjs locale (e.g., with "pt_BR", "pt-br", "pt-BR", "pt", "de") do not work because, in the current Superset frontend code, there is no global connection between the user/app-chosen language and the dayjs locale. By default, dayjs only loads the English locale, and only updates the "en" locale for a custom invalidDate message. Other locales (like pt_BR) are not loaded or set globally unless explicitly handled in the code. This means that even if you call dayjs.locale('pt_BR'), it will not translate relative time strings unless the pt_BR locale is actually imported and registered with dayjs at runtime.
To make translations work, you need to ensure that:
1. The pt_BR locale is imported from dayjs (e.g., import 'dayjs/locale/pt-br';).
2. The locale is set using the correct string (dayjs uses 'pt-br', not 'pt_BR').
3. The locale is set before any relative time formatting is done.
Example:
```js
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import 'dayjs/locale/pt-br';
dayjs.extend(relativeTime);
dayjs.locale('pt-br');
console.log(dayjs().from(dayjs().subtract(2, 'minute'))); // "há 2 minutos"
```
In Superset, this integration is not handled globally, so you may need to add this import and locale setting in your custom code or in a place that runs before any date formatting occurs. Also, check the browser console for errors about missing locale files.
For more details on how dayjs is configured in Superset, see the code where plugins are extended and the locale is updated for 'en' only, but not for other languages: [superset-frontend/src/utils/dates.ts](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset-frontend/src/utils/dates.ts).
If you want this to work out-of-the-box for all users, you would need to ensure that the correct locale is imported and set based on the user's language selection, which is not currently done globally in Superset.
<!-- 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/a306369c-6ae9-4329-a645-e2e96cc280ce?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/a306369c-6ae9-4329-a645-e2e96cc280ce?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/a306369c-6ae9-4329-a645-e2e96cc280ce?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/a306369c-6ae9-4329-a645-e2e96cc280ce?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/a306369c-6ae9-4329-a645-e2e96cc280ce?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/a306369c-6ae9-4329-a645-e2e96cc280ce?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/a306369c-6ae9-4329-a645-e2e96cc280ce?feedback_type=other)</sup> [](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/33630)
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321260
----
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] Translation of time passed [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Translation of time passed
<!-- Answer -->
To localize the changed_on_delta_humanized field in Superset’s backend, you need to replace the use of humanize.naturaltime (which always returns English) with Flask-Babel’s format_timedelta, which supports translations based on the current locale.
Here’s how you can implement this:
1. In superset/models/helpers.py, locate the AuditMixinNullable class. The changed_on_humanized property currently looks like this:
```python
@property
def changed_on_humanized(self) -> str:
return humanize.naturaltime(datetime.now() - self.changed_on)
```
2. Replace humanize.naturaltime with Flask-Babel’s format_timedelta:
```python
from flask_babel import format_timedelta
from datetime import datetime
@property
def changed_on_humanized(self) -> str:
if self.changed_on:
delta = datetime.utcnow() - self.changed_on
return format_timedelta(delta, granularity='second')
return ""
```
You can adjust the granularity ('second', 'minute', 'hour', etc.) to match your needs. format_timedelta will automatically use the user’s locale if Flask-Babel is configured correctly in your Superset instance.
3. Do the same for created_on_humanized if you want that field localized as well.
4. Make sure your Superset backend is configured for Babel and your desired languages are enabled in superset/config.py:
```python
BABEL_DEFAULT_LOCALE = "en"
BABEL_DEFAULT_FOLDER = "superset/translations"
LANGUAGES = {
"en": {"flag": "us", "name": "English"},
"pt_BR": {"flag": "br", "name": "Brazilian Portuguese"},
# ... other languages ...
}
```
5. If you haven’t already, generate and update your translation files using pybabel:
```sh
pybabel extract -F superset/translations/babel.cfg -o superset/translations/messages.pot .
pybabel update -i superset/translations/messages.pot -d superset/translations
pybabel compile -d superset/translations
```
If you need to add a new language:
```sh
pybabel init -i superset/translations/messages.pot -d superset/translations -l pt_BR
```
6. Restart your Superset backend and test the API (e.g., /api/v1/chart/) with your user or browser set to pt_BR. The changed_on_delta_humanized field should now be localized.
References:
- [AuditMixinNullable implementation](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset/models/helpers.py)
- [pybabel translation management](https://github.com/apache/superset/issues/31396)
- [Superset i18n backend config](https://github.com/apache/superset/discussions/31444)
Let me know if you need a more detailed code example or run into any issues!
<!-- 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/c3cd4cc4-0cb4-4c88-a5f9-0d48c336db99?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/c3cd4cc4-0cb4-4c88-a5f9-0d48c336db99?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/c3cd4cc4-0cb4-4c88-a5f9-0d48c336db99?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/c3cd4cc4-0cb4-4c88-a5f9-0d48c336db99?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/c3cd4cc4-0cb4-4c88-a5f9-0d48c336db99?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/c3cd4cc4-0cb4-4c88-a5f9-0d48c336db99?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/c3cd4cc4-0cb4-4c88-a5f9-0d48c336db99?feedback_type=other)</sup> [](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/33630)
GitHub link: https://github.com/apache/superset/discussions/33630#discussioncomment-13321869
----
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] Translation of time passed [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Translation of time passed
<!-- Answer -->
The backend receives the `/api/v1/chart/` request in the `ChartRestApi` class (`superset/charts/api.py`), which operates on the `Slice` model. The field `changed_on_delta_humanized` is generated by the `changed_on_humanized` property in the model mixin (`superset/models/helpers.py`). This property uses the Python `humanize.naturaltime` function to create human-readable time differences, like "2 minutes ago" or "a day ago" [(source)](https://github.com/apache/superset/blob/235c9d2ebf2b14af7afac854b5b15a877695d1b1/superset/models/helpers.py).
Currently, this value is always rendered in English because the `humanize` library does not support localization out-of-the-box, and Superset does not add any translation layer for this field on the backend. Even though Flask-Babel is available in Superset, it is not used for these relative time strings.
To translate `changed_on_delta_humanized`, you would need to replace or wrap the `humanize.naturaltime` call with a localization-aware solution, such as using Flask-Babel's `format_timedelta` or another library that supports your target language. This would require a code change in the backend where `changed_on_humanized` is defined.
Let me know if you want more details on how to implement this.
<!-- 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=0cddda57-7372-4d96-8f8d-d50d074cf6fe) [](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/33630#discussioncomment-13321807
----
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