Problems with ng2-translate and Ionic V3 after upgrading


#1

Hi everyone,

I got a problem with the ng2-translate module in combination with the new Ionic V3 release.

In previous V2 version, I did implement it like this in app.module.ts

...
import {TranslateModule, TranslateStaticLoader} from "ng2-translate/ng2-translate";
import {TranslateLoader} from "ng2-translate";
...
export function translateLoaderFactory(http: any) {
   return new TranslateStaticLoader(http, './assets/i18n', '.json');
}
...
@NgModule({
  declarations: [ 
    ...
  ],
  imports: [
    ...,
    TranslateModule.forRoot({
      provide: TranslateLoader,
      useFactory: translateLoaderFactory,
      deps: [Http] //Changed to "HttpModule" in V3 version
    })
  ],
...
})
....

Accessing the translate functions in TS templates or HTML templates works fine that way.

When upgrading to V3, I got an error message telling me “this.http.get is not a function”. After removing all http queries from my app I realized that not the custom queries are the problem but ng2-translate seems to load the required translation file via http.get and this seems not to be compatible with the changes in V3, e.g. the HttpModule.

Any hints what is going wrong or any alternatives how to implement ng2-translate?

Regards
Greg


#2

Check out the updated docs: https://ionicframework.com/docs/resources/ng2-translate/


#3

Thanks a lot :slight_smile:

Why did stupid google did not list that page? :sob: