Ngx-translate and lazy loading - some languages not found

This solved the issue. Thank you sonuyadav!

However - a few things:

  • Only the page that is changing the language needs to have the second loader in it:
    (TranslateModule.forChild({...}). All other pages just need TranslateModule.forChild()

  • Instead of having 2 TranslateLoaderFactory… you can just import the factory from your app.module.ts

So in the settings.ts page where I have the control to change the language I have this:

...
import {TranslateLoader, TranslateModule} from "@ngx-translate/core";
import {createTranslateLoader} from "../../app/app.module";
import {Http} from "@angular/http";

@NgModule({
  declarations: [...],
  imports: [
    IonicPageModule.forChild(SettingsPage),
    TranslateModule.forChild({
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [Http]
      }
    })
  ],
  exports: [...]
})

and then of course the default set up stuff in the app.module and app.component files. (Link to Ionic ngx-translate setup guide)

3 Likes