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 _set_locale(self):
if self.locale_selector_func is None:
locale = self.default_locale
else:
locale = self.locale_selector_func()
if locale is None:
locale = self.default_locale
try:
humanize.i18n.activate(locale)
except IOError:
pass