babel icon indicating copy to clipboard operation
babel copied to clipboard

babel.core.UnknownLocaleError: unknown locale 'und_BQ'

Open tedgoodley opened this issue 1 year ago • 1 comments

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

tedgoodley avatar Apr 03 '24 17:04 tedgoodley

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'}}
>>>

akx avatar Apr 24 '24 12:04 akx