python-babel / babel

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

babel.lists.format_list errors on 'standard-narrow' style for German locale #781

Open amelia-bruno opened 3 years ago

amelia-bruno commented 3 years ago

Steps to Reproduce

from babel.lists import format_list
format_list(['A', 'B', 'C'], style='standard-narrow', locale='de')

Actual Results

Traceback (most recent call last):
File "C:\Users\amelia.bruno\PycharmProjects\orion\prompt-generators\pg-sport\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3437, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-3-fdcd09f7f101>", line 1, in <module>
    format_list(['A', 'B', 'C'], style='standard-narrow', locale='de')
File "C:\Users\amelia.bruno\PycharmProjects\orion\prompt-generators\pg-sport\venv\lib\site-packages\babel\lists.py", line 82, in format_list
    result = patterns['start'].format(lst[0], lst[1])
File "C:\Users\amelia.bruno\PycharmProjects\orion\prompt-generators\pg-sport\venv\lib\site-packages\babel\localedata.py", line 218, in __getitem__
    orig = val = self._data[key]
KeyError: 'start'

Expected Results

The english locale gives the expected result:

format_list(['A', 'B', 'C'], style='standard-narrow', locale='en')
Out[4]: 'A, B, C'
jithenms commented 3 years ago

I believe that standard-narrow isn't a type of style available on babel. The key to fixing this issue might be to use one of the styles listed on their documentation page here.

Revised Code

from babel.lists import format_list format_list(['A', 'B', 'C'], style='unit-narrow', locale='de')

Or

format_list(['A', 'B', 'C'], style='standard', locale='de')

Take a look at their documentation page to see what might fit your use case best.

amelia-bruno commented 3 years ago

Thanks for the reference. I'll do that, but I'm curious as to why the 'standard-narrow' style does work for the English locale, despite it being omitted from the documentation. And in any case there is a gap between the functionality and the documentation that ought to be fixed. Does anyone know why it was implemented that way for English?