Globalization in browser throws cordova not available


#1

I want to use the method Globalization.getPreferredLanguage() as described here.

   platform.ready().then(() => {
      Globalization.getPreferredLanguage().then((value) => {
        console.log(value);
      }).catch((err) => {
        console.error(err);
      });
    });

But in the browser (Google Chrome), it outputs cordova_not_available to the console.

This is unexpected because the official doc for this plugin specifies that it works inside a browser and should return the same result as getLocaleName().

It works as expected on an Android emulator.


#2

Are you running with ionic serve command or ionic run browser?


#3

I’m running with ionic serve


#4

Try with ionic run browser.


#5

Thanks it’s working with ionic run browser


#6

While this might be true, this is not a solution for ionic serve. Will this be fixed?


#7

I don’t believe it’s “fixable”, due to the way cordova is architected. Cordova plugins require some sort of backend to implement themselves, and ionic serve doesn’t provide any infrastructure for one.


#8

as there are some differencies between ionic serve and ionic cordova run browser one option is to mock the plugin -
if no too complex config is required this may be an option.