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

Pāli language missing. #689

Open jenstroeger opened 4 years ago

jenstroeger commented 4 years ago

So, pi is the ISO_639-1 language code for the Pāli language, yet

>>> import babel
>>> babel.__version__
'2.7.0'
>>> babel.Locale.parse('pi_PI')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/…/lib/python3.7/site-packages/babel/core.py", line 331, in parse
    raise UnknownLocaleError(input_id)
babel.core.UnknownLocaleError: unknown locale 'pi_PI'
>>> babel.Locale.parse('pi')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/…/lib/python3.7/site-packages/babel/core.py", line 331, in parse
    raise UnknownLocaleError(input_id)
babel.core.UnknownLocaleError: unknown locale 'pi'

I’m not sure what’s required to add a new locale here, but would it be possible to add Pāli? Happy to submit a PR if somebody can give me pointers.

akx commented 4 years ago

All the locale data in Babel comes from the Unicode CLDR (at least until some planned custom overlays etc. are implemented).

I couldn't find an issue for Pāli in the CLDR issue tracker, so you may wish to follow the procedure to request a new locale.

jenstroeger commented 4 years ago

Thanks for the tip, @akx! I’ve opened CLDR-13555, and I guess we’ll just have to wait and see what happens next?

Feel free to close this one.

jenstroeger commented 4 years ago

@akx, hmm, looking at en.xml of the CLDR then both Pāli (pi) and Latin (la) are defined, yet:

>>> import babel
>>> babel.__version__
'2.8.0'
>>> babel.Locale('la')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/…/lib/python3.7/site-packages/babel/core.py", line 168, in __init__
    raise UnknownLocaleError(identifier)
babel.core.UnknownLocaleError: unknown locale 'la'
>>> babel.Locale('pi')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/…/lib/python3.7/site-packages/babel/core.py", line 168, in __init__
    raise UnknownLocaleError(identifier)
babel.core.UnknownLocaleError: unknown locale 'pi'

What am I missing here?

akx commented 4 years ago

You're looking at the list of language names in English, which is generally accessible with Locale.get_language_name()... but that API unfortunately doesn't work for languages that aren't available for Babel, so you'd have to look at the underlying languages dict instead to access that data:

>>> en = babel.Locale.parse("en")
>>> en.languages.get('pi')
'Pali'
>>> en.languages.get('la')
'Latin'
jenstroeger commented 4 years ago

@akx, thank you! Is the display name available as well? From the docs:

Locales itself can be used to describe the locale itself or other locales.

So I guess without having a Locale object for Pāli or Sanskrit I won’t be able to access their respective display names?

akx commented 4 years ago

Well, you could compose something akin to a display name from a language name and territory name (l.languages and l.territories), if you know the territory that language is spoken in.

srl295 commented 3 years ago

@jenstroeger CLDR ticket was closed due to no further data

jenstroeger commented 3 years ago

@srl295, just responded.

BTW, I came across similar issues with languages like Cree or Sanskrit.