Is there a way to identify RTL (right-to-left) language, apart from testing language code against all RTL languages?
Since API 17+ allows several resources for RTL a
@cyanide's answer has the right approach but a critical bug.
Character.getDirectionality returns the Bi-directional (bidi) character type. Left-to-right text is a predictable type L and right-to-left is also predictably type R. BUT, Arabic text returns another type, type AL.
I added a check for both type R and type AL and then manually tested every RTL language Android comes with: Hebrew (Israel), Arabic (Egypt), and Arabic (Israel).
As you can see, this leaves out other right-to-left languages, so I was concerned that as Android adds these languages, there might have a similar issue and one might not notice right away.
So I tested manually each RTL language.
So it looks like this should work great:
public static boolean isRTL() {
return isRTL(Locale.getDefault());
}
public static boolean isRTL(Locale locale) {
final int directionality = Character.getDirectionality(locale.getDisplayName().charAt(0));
return directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;
}
Thanks @cyanide for sending me the right direction!