Reputation: 21
I have an issue with the Device plugin from Capacitor. When using Device.getLanguageCode() I get the correct language code when I am testing the application in the browser with ionic serve. However, when I am testing the application on my own phone with android studio, the language code is not retrieved. I tried to print the language code to the screen, but there is nothing coming up.
I suspect that it may be because the app is just in testing-mode, but it is still installed on the phone, so shouldn't it be able to get the device info? Help is much appreciated!
I am using ionic with react.
Code:
/* --------------------- Setting Language --------------------- */
const { Device } = Plugins;
const languageCtx = useContext(LanguageContext);
let fixedLangCode = 0; // 0 is default language code (English).
Device.getLanguageCode().then((langCode) => {
if (langCode.value.includes("NO")) {
fixedLangCode = 1; //1 is Norwegian language code.
}
languageCtx.updateLanguageCode(fixedLangCode);
});
/* ---------------------------------------------------------- */
Error message: There does not seem to be any error message. The only thing that is mentioned when starting up the application about the getLanguageCode is this:
V/Capacitor/Plugin: To native (Capacitor plugin): callbackId: 27212778, pluginId: Device, methodName: getLanguageCode
V/Capacitor: callback: 27212778, pluginId: Device, methodName: getLanguageCode, methodData: {}
And the Device plugin is mentioned among all the other plugins like this:
D/Capacitor: Registering plugin: Device
Upvotes: 0
Views: 1168
Reputation: 21
I have found the problem and solution. Turns out there was nothing wrong, it was just a difference between the getLanguageCode.value result in the browser and on the phone.
In the browser, the getLanguageCode.value returns "nb-NO".
In the mobile application, the getLanguageCode.value returns "nb".
Since my program was designed to detect "NO" and not "nb" it seemed like it didn't work.
Upvotes: 1