How to use the humanize.i18n.activate function in humanize

To help you get started, we’ve selected a few humanize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jmoiron / humanize / tests / test_i18n.py View on Github external
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"
github SamR1 / FitTrackee / fittrackee_api / fittrackee_api / users / utils.py View on Github external
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
github vitalk / flask-humanize / flask_humanize / __init__.py View on Github external
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