Skip to content

format_timedelta throws / default_locale('LC_CTIME') is None with POSIX locale #137

@tko

Description

@tko
import datetime
from babel.dates import format_timedelta
format_timedelta(datetime.timedelta(days=42))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "virtualenv/local/lib/python2.7/site-packages/babel/dates.py", line 779, in format_timedelta
    plural_form = locale.plural_form(value)
AttributeError: 'NoneType' object has no attribute 'plural_form'

This happens when no locale related environment variables are set, e.g.

$ env | egrep 'LANG|LC_'
(nothing)
$ locale
LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions