evgeny-nadymov / telegram-react

Experimental Telegram web client with tdlib, webassembly and react js under the hood
https://evgeny-nadymov.github.io/telegram-react/
GNU General Public License v3.0
2.23k stars 583 forks source link

Problem in showing RTL texts #415

Open kmirzavaziri opened 2 years ago

kmirzavaziri commented 2 years ago

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.