Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format_timedelta fails on es_US / narrow #798

Closed
ikonst opened this issue Jul 29, 2021 · 5 comments · Fixed by #855
Closed

format_timedelta fails on es_US / narrow #798

ikonst opened this issue Jul 29, 2021 · 5 comments · Fixed by #855

Comments

@ikonst
Copy link

ikonst commented Jul 29, 2021

This code:

from datetime import timedelta

from babel.dates import format_timedelta

format_timedelta(timedelta(), format='narrow', locale='es_US')

works on babel 2.7 but breaks since babel 2.8 with:

  ...
  File ".../site-packages/babel/dates.py", line 944, in format_timedelta
    pattern = patterns[plural_form]
  File ".../site-packages/babel/localedata.py", line 218, in __getitem__
    orig = val = self._data[key]
KeyError: 'other'

(I suspect the CLDR 35 to 36 upgrade.)

@akx akx self-assigned this Jan 25, 2022
@akx akx closed this as completed in #855 Apr 20, 2022
@akx akx added this to the Babel 2.10 milestone Apr 20, 2022
@ikonst
Copy link
Author

ikonst commented Apr 23, 2022

Thank you!

@ikonst
Copy link
Author

ikonst commented Jul 6, 2022

Similarly, #855 fixes this:

from datetime import timedelta

import babel.dates

# raises: KeyError: 'one'
babel.dates.format_timedelta(
    timedelta(minutes=1),
    format="short",
    locale='pt_BR',
)

@jun66j5
Copy link
Contributor

jun66j5 commented Jul 7, 2022

Hi @ikonst,

The issue doesn't occur with Babel 2.10.3. I guess that's an installation issue on your environment. Could you please recheck Babel's version?

$ pip install --no-cache-dir Babel
Collecting Babel
  Downloading Babel-2.10.3-py3-none-any.whl (9.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.5/9.5 MB 7.5 MB/s eta 0:00:00
Collecting pytz>=2015.7
  Downloading pytz-2022.1-py2.py3-none-any.whl (503 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 503.5/503.5 kB 22.3 MB/s eta 0:00:00
Installing collected packages: pytz, Babel
Successfully installed Babel-2.10.3 pytz-2022.1
$ python
Python 3.10.4 (main, Apr  8 2022, 17:35:13) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import babel
>>> babel.__version__
'2.10.3'
>>> from datetime import timedelta
>>> from babel import dates
>>> dates.format_timedelta(timedelta(minutes=1), format='short', locale='pt_BR')
'1 min'

@ikonst
Copy link
Author

ikonst commented Jul 7, 2022

@jun66j5 That's precisely what I was saying, that babel 2.10 has fixed this issue too (which was present with 2.9).

@jun66j5
Copy link
Contributor

jun66j5 commented Jul 7, 2022

Okay. Sorry about my wrong comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants