pemistahl / lingua-py

The most accurate natural language detection library for Python, suitable for short text and mixed-language text
Apache License 2.0
1.08k stars 44 forks source link

Returning IsoCode639_1 #129

Closed joshdehlong closed 1 year ago

joshdehlong commented 1 year ago

Hello, is there any option to make lingua return the language as its IsoCode639_1 instead of Language.ENGLISH? In the API documentation I have found a class for it but no further information/an example on how to use it.

Thank you

pemistahl commented 1 year ago

There is an attribute on each Language that gives you the ISO code.

>>> from lingua import Language
>>> Language.ENGLISH.iso_code_639_1
IsoCode639_1.EN
>>> Language.ENGLISH.iso_code_639_1.name
'EN'

I'm surprised that this attribute is not listed in the generated API docs. Probably, it's because this is not a real class member but an attribute of an enum entry. I will try to find a better API docs generator or simplify the API somehow. The least I can do is to provide an example in the README.

Thank you for making me aware of this. :)