If arabic glyphs are a standard number of bytes you could convert letters to bytes and reverse those "groupings" instead of trying to use the standard string methods that work for single byte languages.
You could try running your string through
this library's string.utf8reverse(s) method and see what happens.