Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in showing RTL texts #415

Open
kmirzavaziri opened this issue Oct 3, 2021 · 0 comments
Open

Problem in showing RTL texts #415

kmirzavaziri opened this issue Oct 3, 2021 · 0 comments

Comments

@kmirzavaziri
Copy link

It would be a great idea to show RTL texts RTL. This simple function would help to check if a text is RTL or not,

const isRtl = (text) => {
    var ltrChars = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF' + '\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF',
        rtlChars = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC',
        rtlDirCheck = new RegExp('^[^' + ltrChars + ']*[' + rtlChars + ']');

    return rtlDirCheck.test(text);
}

It's easy to use this and check if the content of a text element is RTL, and in that case add a class or style direction: rtl;. It's doesn't take much effort but would be a great help to many people who use Persian/Arabic/Hebrew languages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant