-1

I need to detect the keyboard language not the locale or device language or anything else. and i can't write java code. is there any way to find the language of the keyboard ?

in this case it should show 'en' or 'ltr'

in this case it must show en or ltr

in this case it should show 'fa' or 'rtl'

and in this case it must say fa or rtl

i am using i18n but i don't need the locale, its fixed and i can't get the info i need from it.

react-native : 0.59.5

Gray
  • 489
  • 8
  • 23

1 Answers1

1

You can get the keyboard language if you create an native module.

Here's a example of how to get it using java for android:

private void printInputLanguages() {
   InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
   List<InputMethodInfo> ims = imm.getEnabledInputMethodList();

   for (InputMethodInfo method : ims) {
       List<InputMethodSubtype> submethods = imm.getEnabledInputMethodSubtypeList(method, true);
       for (InputMethodSubtype submethod : submethods) {
          if (submethod.getMode().equals("keyboard")) {
             String currentLocale = submethod.getLocale();
             Log.i(TAG, "Available input method locale: " + currentLocale);
          }
       }
   }
}

And here's how to do it with swift, for IOS:

var language = textfield.textInputMode?.primaryLanguage

And here's how to create a native module for react-native