Check if the string is Persian or English

I have a webview that will load a string from a url, I'm not sure if this is the correct way or not, but I want to check if the string is in Persian, so I change my text in the webview to align to rtl and, if it's in English, change it to ltr. Is it possible to tell if a string is in Persian or English? or if there is another better way to handle this question?

Thanks in advance.

+3


source to share


3 answers


Try the following regex to check the character range of Arabic, Persian and Hebrew.



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 RTL
} 

      

+8


source


Here are the methods that are explained by Language Recognition in Java

What you can do is just check if the string is in English, if it shouldn't be Persian.



TextCat: http://textcat.sourceforge.net/

0


source


There is a language detection library in Java to detect the language. I think this might help you. try it.

you need to import the following library files to work with this.

import com.cybozu.labs.langdetect.Detector;
import com.cybozu.labs.langdetect.DetectorFactory;
import com.cybozu.labs.langdetect.Language;

      

for more help click here

0


source







All Articles