-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ | |
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 | ||
|
@@ -546,10 +546,28 @@ | |
|
||
@property | ||
def changed_on_humanized(self) -> str: | ||
locale = str(get_locale() or 'en') | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
try: | ||
humanize.i18n.activate(locale) | ||
result = humanize.naturaltime(datetime.now() - self.changed_on) | ||
humanize.i18n.deactivate() | ||
return result | ||
Comment on lines
548
to
+554
This comment was marked as resolved.
Sorry, something went wrong. |
||
except: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Otherwise you may just never know that say your particular locale isn't handled by |
||
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) | ||
Comment on lines
548
to
571
This comment was marked as resolved.
Sorry, something went wrong. |
||
|
||
@renders("changed_on") | ||
|
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.