Very very new to ionic.
I am trying to build a ionic 2 app with localization, so the user can change language inside the app. does anyone know about a up to date working example for localization (i18n), it will bee very much appreciated?
import { TranslateModule, TranslateLoader,
TranslateStaticLoader } from 'ng2-translate/ng2-translate';
Finally in constructor of app.component.ts :
import { TranslateService } from 'ng2-translate/ng2-translate';
constructor(public platform: Platform, public translate: TranslateService) {
this.platform.ready().then(() => {
var userLang = navigator.language.split('-')[0]; // use navigator lang if available
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
// this language will be used as a fallback when a translation isn't found in the current language
translate.setDefaultLang('en');
// the lang to use, if the lang isn't available, it will use the current loader to get them
translate.use(userLang);
});
}
You have to declare it somewhere, in your constructor parameters for example. constructor(public platform: Platform, public translate: TranslateService) {
and if it not enough use this.translate instead of translate.