ionic2 - ng2-translate fails on iOS device when trying to set language with NetworkError (DOM Exception 19): A network error occurred -
i have been trying figure out why globalization.getpreferredlanguage() fail when running on ios device (not when running on simulator or android device / emulator)
globalization.getpreferredlanguage().then((property) => { let lang = property.value; if (lang) { if (lang.startswith('en')){ this.translate.use('en_gb'); } else if (lang.startswith('fr')) { this.translate.use('fr_fr'); } else { this.translate.use('en_gb'); } } else { console.log("property.value null"); } }).catch((reason) => { this.translate.use('en_gb');// <-- not not work, reason given networkerror (dom exception 19): network error occurred. });
what have tried:
- removing , adding globalization plugin both ionic , cordova instructions:
ionic plugin rm cordova-plugin-globalization && ionic plugin add cordova-plugin-globalization
sudo cordova plugin rm cordova-plugin-globalization && sudo cordova plugin add cordova-plugin-globalization
edit 1 after more debugging can see angular ng2-translate 'use' function failing. in app.module.ts:
import { translateloader, translatemodule, translatestaticloader } 'ng2-translate/ng2-translate'; ... export function createtranslateloader(http: http) { return new translatestaticloader(http, '/assets/i18n', '.json'); } ... @ngmodule({ declarations: [ ... ], imports: [ ... browsermodule, httpmodule, translatemodule.forroot({ provide: translateloader, usefactory: (createtranslateloader), deps: [http] }), ... ] ... }) export class appmodule { }
but in app.component.ts when call
this.translate.use('en_gb');
it throws exception. have checked , files exist in folder:
/.../platforms/ios/www/assets/i18n
for me, globalization.getpreferredlanguage() never resolved. using
this.devicelang = navigator.language;
this returns device language variant (fr-fr / en-us)
Comments
Post a Comment