IONIC 2 Globalization Plugin Error

I am making ionic application 2 with angular 2 and typescript, and I had to use the globalization plugin offered by ionic / Cordova. The plugin always encounters an error when determining the preferred language the second time the application loads.

So, the error scenario is as follows: I change the language of my phone to French from English and run my application. The application works flawlessly and the plugin detects that I am using French. I close the application and open it again, then the plugin detects an error and catches it, and then displays it as a warning.

This happens all the time.

here is the code i use to determine the language:

let ln=''; this.globalization.getPreferredLanguage() .then(res => {ln =res.value; console.log(ln); if(ln.substring(0,2) ==='fr'){ this.translate.setDefaultLang('fr'); this.translate.reloadLang('fr'); localStorage.setItem("lang","1"); }else{ if(ln.substring(0,2)==="en"){ this.translate.setDefaultLang('en'); this.translate.reloadLang('en'); localStorage.setItem("lang","2"); }else{ this.translate.setDefaultLang('en'); this.translate.reloadLang('en'); localStorage.setItem("lang","2"); } } }) .catch(e => { console.log(e); this.translate.setDefaultLang('en'); this.translate.reloadLang('en'); localStorage.setItem("lang","2"); let altert= this.AlertC.create({ title: "Language selection problem" , message: "We have encountered an error in identifying your preferred language, so we put it to english as default.", buttons: [ { text: 'OK', handler: () => { console.log('Cancel clicked'); } }, ] }); altert.present(); }); 

Any ideas what could be the problem?

+5
angular cordova globalization ionic2
source share

No one has answered this question yet.

See related questions:

3
an android with an ionic cord does nothing
one
Source Code Karma Cordoba Native HTML Doc Keyboard Plugin Undefined
one
android ion cord run always fails
one
Failed to restore plugin "cordova-plugin-insomnia"
0
Cordova Console Does Not Catch Ionic Exceptions on iOS (xcode)
0
Ionic app not detecting iBeacons on iOS (cordova-plugin-rating)
0
Ionic - โ€œcamera canceledโ€ when allowEdit is true
0
Error using global variables from es5 library in typescript
0
Error installing plugin Ionic cordova
0
Ionic 2 - Use the installed settings plug-in from nGCordova

All Articles