Globalization in browser throws cordova not available

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.

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

I’m running with ionic serve

Try with ionic run browser.

1 Like

Thanks it’s working with ionic run browser

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

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.

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.

1 Like