LBeaudoux / iso639

A fast, simple ISO 639 library.
MIT License
32 stars 4 forks source link

paired list #9

Closed AtomicNess123 closed 3 years ago

AtomicNess123 commented 3 years ago

How to get a paired list of language and iso codes from the package? Thanks.

LBeaudoux commented 3 years ago

Sorry but this package does not aim at listing language code mappings. That said, you can still probably generate the data your are looking for from Lang._data:

>>> from iso639 import Lang
>>> [(d["name"], pt3) for pt3, d in Lang._data["pt3"].items()]
[('Ghotuo', 'aaa'), ('Alumu-Tesu', 'aab'), ... , ('Zaza', 'zza'), ('Zuojiang Zhuang', 'zzj')]
AtomicNess123 commented 3 years ago

Thanks so much. These are three letter codes. Are there also two letter codes (eg., EN, RU, FR)?

LBeaudoux commented 3 years ago

Just replace pt3 bypt1:

>>> [(d["name"], pt1) for pt1, d in Lang._data["pt1"].items()]
[('Afar', 'aa'), ('Abkhazian', 'ab'),  ... , ('Chinese', 'zh'), ('Zulu', 'zu')]
AtomicNess123 commented 3 years ago

Silly me, thanks!

LBeaudoux commented 3 years ago

Since v2.0, you can now iterate more easily and efficiently through all possible Lang instances with iter_langs:

>>> from iso639 import iter_langs
>>> [(lang.name, lang.pt3) for lang in iter_langs() if lang.pt3]
[("'Are'are", 'alu'), ("'Auhelawa", 'kud'), ... , ('ǂUngkue', 'gku'), ('ǃXóõ', 'nmn')]