Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_i18n():
three_seconds = dt.timedelta(seconds=3)
assert humanize.naturaltime(three_seconds) == "3 seconds ago"
humanize.i18n.activate("ru_RU")
assert humanize.naturaltime(three_seconds) == "3 секунды назад"
humanize.i18n.deactivate()
assert humanize.naturaltime(three_seconds) == "3 seconds ago"
def get_readable_duration(duration, locale='en'):
if locale is not None and locale != 'en':
_t = humanize.i18n.activate(locale) # noqa
readable_duration = humanize.naturaldelta(timedelta(seconds=duration))
if locale is not None and locale != 'en':
humanize.i18n.deactivate()
return readable_duration
def _unset_locale(self, response):
humanize.i18n.deactivate()
return response