python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.29k stars 432 forks source link

babel.core.UnknownLocaleError: unknown locale 'und_BQ' #1069

Open tedgoodley opened 3 months ago

tedgoodley commented 3 months ago

Overview Description

Steps to Reproduce

  1. Try to initialize a locale with undetermined language using BQ (Caribbean Netherlands) country code, e.g. und_BQ

Actual Results

This causes an error babel.core.UnknownLocaleError: unknown locale 'und_BQ'

Expected Results

I would expect this to succeed and use the only matching locale, nl_BQ, instead when formatting dates

Reproducibility

Additional Information

akx commented 2 months ago

I think implicitly finding nl_BQ for und_BQ would be unexpected behavior.

If you have an und_XX locale, you can use get_territory_language_info() to find which language(s) are spoken in XX, and figure out which one is relevant for your users:

>>> import babel.languages as bl
>>> bl.get_territory_language_info("BQ")
{'pap': {'population_percent': 81.0, 'official_status': None}, 'nl': {'population_percent': 8.0, 'official_status': 'official'}}
>>>