LBeaudoux / iso639

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

Feature Request : RTL (right-to-left) Flag #19

Closed advl closed 3 months ago

advl commented 3 months ago

Hi,

First of all thank you for this library - it has been significantly helpful in a personal project I'm currently working on.

I would like to submit for consideration the addition of a rtl flag to the list of languages. This could take the shape of a simple boolean accessible on Lang instances. I believe we can trivially populate the values for the list of languages with an AI prompt.

For instance

>>> lg = Lang("Arabic")
>>> lg.rtl
True

or

>>> lg = Lang("French")
>>> lg.rtl
False

I would use this feature to automatically set up css properties on my front-end.

If this feature can be considered, I can submit a pull request for it. I can see this feature would fall slightly outside of the strict scope of ISO639 mappings, so I would understand it being a reason for not implementing it. However, having this feature would help have one source of truth for language information.

Thank you for reading me !

ic-it commented 3 months ago

I think this might be a separate package that can be installed as an optional dependency (feature)

LBeaudoux commented 3 months ago

Thanks for posting this issue.

As you know, text direction is a property associated with a script, not a language. So I don't want to include it in this package dedicated to language codes.

Note that the Unicode Common Locale Data Repository (CLDR) maps languages to their scripts, and that the Babel package provides a Python interface to the CLDR.

from babel import Locale
from iso639 import Lang

def is_rtl(language_name):
    language = Lang(language_name)
    language_code = language.pt1 if language.pt1 else language.pt3
    return Locale(language_code).text_direction == "rtl"
>>> is_rtl("Arabic")
True
>>> is_rtl("French")
False
advl commented 3 months ago

Thank you for taking the time to answer and propose a solution. This is indeed helpful and solves my problem !