-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
base: master
Are you sure you want to change the base?
fix(translations): Fix translation of time-related strings like "7 seconds ago", "a minute ago", etc #34051
Conversation
There was a problem hiding this 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 |
---|---|---|
Inefficient Static Locale Imports ▹ view | 🧠 Not in scope | |
Hardcoded default locale ▹ view | 🧠 Not in scope | |
Redundant Time Formatting Logic ▹ view | 🧠 Not in standard | |
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.
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.
This comment was marked as resolved.
Sorry, something went wrong.
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.
This comment was marked as resolved.
Sorry, something went wrong.
@@ -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.
This comment was marked as resolved.
Sorry, something went wrong.
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.
This comment was marked as resolved.
Sorry, something went wrong.
result = humanize.naturaltime(datetime.now() - self.changed_on) | ||
humanize.i18n.deactivate() | ||
return result | ||
except: |
There was a problem hiding this comment.
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
.
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 topreamble.ts
. Without them,dayjs.locale()
calls have no effect, leaving dates/times in the default language.Fix humanized strings: translate
changed_on_humanized
andcreated_on_humanized
using current locale from flask_babel.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION