Skip to content

Problem in showing RTL texts #415

Open

Description

@kmirzavaziri

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions