Skip to content

Commit

Permalink
fix(server): properly localize timedelta string
Browse files Browse the repository at this point in the history
Fixes #248
  • Loading branch information
ericswpark committed Nov 24, 2023
1 parent 6212c7d commit c384a47
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
from django.urls import reverse
from datetime import date

from django.utils.translation import get_language, to_locale

from .utils import is_version_in_target_versions

LOCALE_MAPPING = {"en": "en_US", "ko": "ko_KR"}


# Device Model
class Device(models.Model):
Expand Down Expand Up @@ -366,6 +370,12 @@ def get_absolute_url(self):
)

def human_readable_timedelta(self):
locale = LOCALE_MAPPING[get_language()]
if locale != "en_US":
try:
humanize.i18n.activate(locale=locale)
except FileNotFoundError:
pass
return humanize.naturaltime(date.today() - self.build_date)


Expand Down

0 comments on commit c384a47

Please sign in to comment.