Hi there. I’m having some trouble to use the ECMAScript Internationalization API.
Initially on my project I’ve used the Globalization API from ionic, cordova which worked fine. While trying to lint my project I’ve got the following error
WARNING: […]: Globalization is deprecated: With the ECMA Internationalization API now supported on iOS, Android and Windows devices, this plugin is not required any more.
Migrating from this plugin to the ECMA Internationalization API is explained in this Cordova blog post.
I’ve read the migration post, which seems rather simple. By just using the navigator which is a global variable then you can make use of the globalization functions, such as the getPreferredLanguage function which I’m interested on for initializing the language based on the device (mobile or browser) locale. There doesn’t seem to be any extra configuration.
But then while trying to compile I’m getting
error TS2339: Property ‘globalization’ does not exist on type ‘Navigator’.
This seems rather strange to me, I’ve installed the “cordova-plugin-globalization” plugin on my package.json, also on my config.xml file and then both my andorid.json and browser.json files in the plugins folder. Yet this isn’t detected. I’ve tried to overpass this error while compiling by doing something like
let nav: any = (navigator as any);
if (nav.globalization) {
nav.globalization.getPreferredLanguage(
(res) => {
console.log('globalization lang ', res);
},
(error) => {
console.error('error ');
}
);
} else {
console.log('no globalization');
}
but this always evals to ‘no globalization’. Does someone stumbled with this problem or knows a possible solution?