Angular 2: How to use ng2-translate alongside in-memory-web-api

330 Views Asked by At

I'm using ng2-translate for i18n translations + in-memory-web-api for mock data.

Without the in-memory-web-api the i18n translations work as they should but with it enabled angular's Http service cannot resolve the correct path to the translation files because the mock data takes over.

Any way for both of them to work at the same time?

Here's what I have in the app.module.ts

export function createTranslateLoader(http: Http) {
    return new TranslateStaticLoader(http, '/assets/i18n', '.json');
}

@NgModule({
    imports: [
        BrowserModule,
        CoreModule,
        routing,
        CookieModule.forRoot(),
        TranslateModule.forRoot({
            provide: TranslateLoader,
            useFactory: (createTranslateLoader),
            deps: [Http]
        }),
        InMemoryWebApiModule.forRoot(MockDataService),
    ],
    declarations: [
        AppComponent
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule {
}
1

There are 1 best solutions below

0
Nik On BEST ANSWER

There is a config argument to handle requests for collections that are not in the in-memory database.

InMemoryWebApiModule.forRoot(MockDataService, { passThruUnknownUrl: true })