You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2025/08/21 16:40:50 UTC

(superset) branch 6.0 updated: fix(translations): Fix translation of time-related strings like "7 seconds ago", "a minute ago", etc (#34051)

This is an automated email from the ASF dual-hosted git repository.

jli pushed a commit to branch 6.0
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/6.0 by this push:
     new c199213e8e fix(translations): Fix translation of time-related strings like "7 seconds ago", "a minute ago", etc (#34051)
c199213e8e is described below

commit c199213e8eabb4b01681094bd9da48039c0d1589
Author: PolinaFam <45...@users.noreply.github.com>
AuthorDate: Thu Aug 21 01:20:35 2025 +0300

    fix(translations): Fix translation of time-related strings like "7 seconds ago", "a minute ago", etc (#34051)
    
    Co-authored-by: Polina Fam <pf...@ptsecurity.com>
    (cherry picked from commit b45141b2a1ce72ee6b0ee9ff692f424565c09dcc)
---
 superset-frontend/src/preamble.ts |  1 +
 superset/models/helpers.py        | 21 ++++++++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/superset-frontend/src/preamble.ts b/superset-frontend/src/preamble.ts
index 32010d6c0c..136856db32 100644
--- a/superset-frontend/src/preamble.ts
+++ b/superset-frontend/src/preamble.ts
@@ -32,6 +32,7 @@ import setupFormatters from './setup/setupFormatters';
 import setupDashboardComponents from './setup/setupDashboardComponents';
 import { User } from './types/bootstrapTypes';
 import getBootstrapData, { applicationRoot } from './utils/getBootstrapData';
+import './hooks/useLocale';
 
 configure();
 
diff --git a/superset/models/helpers.py b/superset/models/helpers.py
index 494aaa5e93..5e3fa66b3e 100644
--- a/superset/models/helpers.py
+++ b/superset/models/helpers.py
@@ -40,7 +40,7 @@ from flask_appbuilder import Model
 from flask_appbuilder.models.decorators import renders
 from flask_appbuilder.models.mixins import AuditMixin
 from flask_appbuilder.security.sqla.models import User
-from flask_babel import lazy_gettext as _
+from flask_babel import get_locale, lazy_gettext as _
 from jinja2.exceptions import TemplateError
 from markupsafe import escape, Markup
 from sqlalchemy import and_, Column, or_, UniqueConstraint
@@ -541,13 +541,28 @@ class AuditMixinNullable(AuditMixin):
         # Convert naive datetime to UTC
         return self.changed_on.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S.%f%z")
 
+    def _format_time_humanized(self, timestamp: datetime) -> str:
+        locale = str(get_locale())
+        time_diff = datetime.now() - timestamp
+        # Skip activation for 'en' locale as it's humanize's default locale
+        if locale == "en":
+            return humanize.naturaltime(time_diff)
+        try:
+            humanize.i18n.activate(locale)
+            result = humanize.naturaltime(time_diff)
+            humanize.i18n.deactivate()
+            return result
+        except Exception as e:
+            logger.warning(f"Locale '{locale}' is not supported in humanize: {e}")
+            return humanize.naturaltime(time_diff)
+
     @property
     def changed_on_humanized(self) -> str:
-        return humanize.naturaltime(datetime.now() - self.changed_on)
+        return self._format_time_humanized(self.changed_on)
 
     @property
     def created_on_humanized(self) -> str:
-        return humanize.naturaltime(datetime.now() - self.created_on)
+        return self._format_time_humanized(self.created_on)
 
     @renders("changed_on")
     def modified(self) -> Markup: