Search code examples
apicordovaemulationglobalizationintel-xdk

Cordova globalization plugin not working on intel xdk emulator


i'm trying to get the preferred language set on the device as following:

navigator.globalization.getPreferredLanguage(
   function (language) {
      alert('language: ' + language.value + '\n');
   },
   function () {
      alert('nope');
   }
);

And when I click on emulator i'm getting this pop-up: missing api emulation

I installed the cordova plug-in to use globalization:

cordova plugin add org.apache.cordova.globalization

And I also added this line on the config.xml:

<plugin name="Globalization" value="org.apache.cordova.Globalization" />

I tested on the device and it's working.

Btw, I'm using cordova 3.5 version but when i launch the intel xdk emulator it shows 2.9 version. Maybe that's causing this problem? I'm also using Storage plugin for sql queries and it's working fine!


Solution

  • Cordova plugins generally consist of two parts: 1) JavaScript API and 2) underlying native code that is specific to the target platform (e.g., Java code for Android, Objective C code for iOS, etc.) The Intel XDK emulator is a simulator that simulates that native part, but only in a very generic way and only for a select number of Cordova APIs. For any APIs that it does not have an underlying "native simulation" it provides this message so you can at least exercise code. It doesn't actually simulate the underlying functionality, but it does allow you to trace through those parts of your code.

    Ultimately, you need to run it on a real device with a real build, as you discovered.

    Also, the APIs that the XDK emulator knows about, at this time, are the 2.9.0 APIs. It is being modified to support 3.x APIs in a future release. BTW, the emulator in the XDK is a customized implementation of the Ripple emulator.