Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect active keyboard language on text input - react native

Tags:

react-native

on a multi-lang device, where user can switch the keyboard/language. how to detect what keyboard the user is using? for example, if the user has arabic and english keyboards. how to detect if he is using the arabic or the english one?

is there a way OTHER than checking the input and determine which language is he typing?

like image 950
Zorox Avatar asked Jun 21 '18 20:06

Zorox


1 Answers

by searching on the react native documentation https://facebook.github.io/react-native/docs/keyboard.html there no property or function that provides the actual language of the keyboard , but you can do it by yourself by implementing a function in your java or objective-C code

you can learn here on how to add your personal native code and use it on react native : https://facebook.github.io/react-native/docs/native-modules-android.html

then simply add this method on your "MyCustomKeyboard" class ( java ) :

@ReactMethod
public String getKeyboardLanguage() {
  InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
  String locale = ims.getLocale();
  return locale;
}
like image 56
Djellal Mohamed Aniss Avatar answered Nov 04 '22 09:11

Djellal Mohamed Aniss