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
[EDIT]
You might get what you need using the NativeModules
module from react-native itself, like as follows:
import { NativeModules } from 'react-native'
[...]
//Getting the device language:
// iOS
let deviceLanguage = NativeModules.SettingsManager.settings.AppleLocale || NativeModules.SettingsManager.settings.AppleLanguages[0]
// Android
let deviceLanguage = NativeModules.I18nManager.localeIdentifier
//Getting keyboard Information (1)
// iOS:
let keyboardData = NativeModules.SettingsManager.settings
// Android:
let keyboardData = NativeModules.I18nManager
(1): I did not test this, you will need to see the output and see if it helps in your case. But, the output for IOS should look like this:
{
[...]
AppleKeyboards: [
"es_419@sw=QWERTY-Spanish;hw=Automatic",
"en_US@sw=QWERTY;hw=Automatic",
"fr_FR@hw=US;sw=QWERTY",
"emoji@sw=Emoji"
]
AppleLanguages: ["fr-US", "en-US", "es-US", "en"],
NSLanguages: ["fr-US", "en-US", "es-US", "en"],
AppleLanguagesDidMigrate: "9.2",
AppleLocale: "fr_FR"
[...]
}
Got this answer here.