I want to detect if a string contains characters that are not in the device's language characters
Is it possible?
Some of my app users write in arabic, the rest write in english. I need to translate text only when the text is in arabic and the user's device is in english or the other way around
You can get the device language by
Locale.getDefault().getDisplayLanguage();
And then do a checking on the input string to see if any character in the string is in the range between
\u0600
and \u06FF
(Arabic charset in Unicode), then it should do the trick
Here is the answer of how to check if the string is in a specific charset
public boolean isEncoded(String text){
Charset charset = Charset.forName("US-ASCII");
String checked=new String(text.getBytes(charset),charset);
return !checked.equals(text);
}
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