I have a webview which will load a string from a url, I'm not sure if this is the correct way or not but what I want to do is to check if the string is in persian so I change my webview's text alignment to rtl and else if it's in english change it to ltr. Is it possible to determine if the string is in persian or english? or if there's any other better way to handle this matter ?
Thanks in advance.
Try the following regular expression, to check the Arabic, Persian and Hebrew characters range.
public static final Pattern RTL_CHARACTERS =
Pattern.compile("[\u0600-\u06FF\u0750-\u077F\u0590-\u05FF\uFE70-\uFEFF]");
Matcher matcher = RTL_CHARACTERS.matcher("براي تست");
if(matcher.find()){
return true; // it's RTL
}
Try Persian-tools an awesome javascript library for this matter and also many other useful functionalities.
import { isPersian, toPersianChars } from "persian-tools2";
isPersian("این یک متن فارسی است؟") // true
isPersian("Lorem Ipsum Test") // false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With