Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

PolinaFam
Copy link

SUMMARY

Issue Description
Switching the language to English does not fully apply, leaving some time-related strings in the previous language. All untranslated time-related strings are created by dayjs and humanize libraries.

Solution
Fix dayjs strings: move all dayjs locale imports from useLocale.ts hook to preamble.ts. Without them, dayjs.locale() calls have no effect, leaving dates/times in the default language.
Fix humanized strings: translate changed_on_humanized and created_on_humanized using current locale from flask_babel.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

screenshot3
screenshot4

TESTING INSTRUCTIONS

  1. Add next lines to config file:
BABEL_DEFAULT_LOCALE` = "ru"
LANGUAGES = {
  "ru": {"flag": "ru", "name": "Русский"},
  "en": {"flag": "us", "name": "English"}
}
  1. Start the application.
  2. Switch the interface language to English.
  3. Verify the translations.

ADDITIONAL INFORMATION

Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Design Inefficient Static Locale Imports ▹ view 🧠 Not in scope
Readability Hardcoded default locale ▹ view 🧠 Not in scope
Design Redundant Time Formatting Logic ▹ view 🧠 Not in standard
Performance Inefficient Repeated Locale Switching ▹ view 🧠 Not in standard
Files scanned
File Path Reviewed
superset-frontend/src/hooks/useLocale.ts
superset-frontend/src/preamble.ts
superset/models/helpers.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Comment on lines +29 to +42
import 'dayjs/locale/en';
import 'dayjs/locale/fr';
import 'dayjs/locale/es';
import 'dayjs/locale/it';
import 'dayjs/locale/zh-cn';
import 'dayjs/locale/ja';
import 'dayjs/locale/de';
import 'dayjs/locale/pt';
import 'dayjs/locale/pt-br';
import 'dayjs/locale/ru';
import 'dayjs/locale/ko';
import 'dayjs/locale/sk';
import 'dayjs/locale/sl';
import 'dayjs/locale/nl';

This comment was marked as resolved.

Comment on lines 548 to +554
def changed_on_humanized(self) -> str:
locale = str(get_locale() or 'en')
try:
humanize.i18n.activate(locale)
result = humanize.naturaltime(datetime.now() - self.changed_on)
humanize.i18n.deactivate()
return result

This comment was marked as resolved.

@@ -546,10 +546,28 @@ def changed_on_utc(self) -> str:

@property
def changed_on_humanized(self) -> str:
locale = str(get_locale() or 'en')

This comment was marked as resolved.

Comment on lines 548 to 571
def changed_on_humanized(self) -> str:
locale = str(get_locale() or 'en')
try:
humanize.i18n.activate(locale)
result = humanize.naturaltime(datetime.now() - self.changed_on)
humanize.i18n.deactivate()
return result
except:
pass
# Fallback to English
return humanize.naturaltime(datetime.now() - self.changed_on)

@property
def created_on_humanized(self) -> str:
locale = str(get_locale() or 'en')
try:
humanize.i18n.activate(locale)
result = humanize.naturaltime(datetime.now() - self.created_on)
humanize.i18n.deactivate()
return result
except:
pass
# Fallback to English
return humanize.naturaltime(datetime.now() - self.created_on)

This comment was marked as resolved.

@dosubot dosubot bot added the i18n:general Related to translations label Jul 3, 2025
result = humanize.naturaltime(datetime.now() - self.changed_on)
humanize.i18n.deactivate()
return result
except:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we expecting this to fail? In what cases? Not sure if swallowing anything/everything is best here, often if we know something might fail we'd try to swallow just that one particular exception, and maybe logging.exception(e) to handle the rest of the pessimisticism, so it's unexcpected, handled - but logged somewhere.

Otherwise you may just never know that say your particular locale isn't handled by humanize.

Copy link

codecov bot commented Jul 5, 2025

Codecov Report

Attention: Patch coverage is 76.47059% with 4 lines in your changes missing coverage. Please review.

Project coverage is 72.71%. Comparing base (23b1fe3) to head (d3c4cac).
Report is 40 commits behind head on master.

Files with missing lines Patch % Lines
superset/models/helpers.py 76.47% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #34051       +/-   ##
===========================================
+ Coverage        0   72.71%   +72.71%     
===========================================
  Files           0      559      +559     
  Lines           0    40442    +40442     
  Branches        0     4247     +4247     
===========================================
+ Hits            0    29408    +29408     
- Misses          0     9937     +9937     
- Partials        0     1097     +1097     
Flag Coverage Δ
postgres 71.92% <76.47%> (?)
presto 50.95% <41.17%> (?)
python 72.68% <76.47%> (?)
sqlite 71.44% <76.47%> (?)
unit 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n:general Related to translations size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants