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