Ionic2 RC2 With ng2-translate - can't config


#1

app.component.ts:

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';

import { TabsPage } from '../pages/tabs/tabs';
import {TranslateService} from 'ng2-translate/ng2-translate';
import {TranslateLoader, TranslateStaticLoader} from "ng2-translate";
import {Http} from "@angular/http";

@Component({
  template: '<ion-nav [root]="rootPage"></ion-nav>',
  providers: [
    provide(TranslateLoader, {**//provide not found**
      useFactory: (http: Http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'),
      deps: [Http]
    }),
    TranslateService
  ]
})
export class MyApp {
  rootPage = TabsPage;

  constructor(platform: Platform) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      StatusBar.styleDefault();
      Splashscreen.hide();
    });
  }
}

Please HELP…

system information:

Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.2
Ionic CLI Version: 2.1.4
Ionic App Lib Version: 2.1.2
Ionic App Scripts Version: 0.0.44
OS:
Node Version: v4.5.0

#2

in app.module.ts just add this in import array :

    TranslateModule.forRoot({
      provide: TranslateLoader,
      useFactory: (createTranslateLoader),
      deps: [Http]
    })

Then in constructor of app.component.ts :

      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);

#3

THANKS!!!
Works fine.


#4

I still get the error - could you please share your repo ?
thank you :slight_smile:

UPDATE:
Everything is fine now - here is a repo of ng2-translate with Ionic2 rc3