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 [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]