Skip to content

Commit

Permalink
feat(MultiTranslateHttpLoader): Enable use of multiple translation fi…
Browse files Browse the repository at this point in the history
…les.

BREAKING CHANGE: MultiTranslateHttpLoader now takes an array of translation file configuration
instead of just one config.
  • Loading branch information
denniske committed Jun 20, 2018
1 parent 01339c0 commit 7bcd991
Showing 1 changed file with 0 additions and 41 deletions.
41 changes: 0 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,44 +78,3 @@ export function HttpLoaderFactory(http: HttpClient) {
```

For now this loader only support the json format.

## Angular CLI/Webpack TranslateLoader Example
If you are using Angular CLI (uses webpack under the hood) you can write your own `TranslateLoader` that always loads the latest translation file available during your application build.

```typescript
// webpack-translate-loader.ts
import { TranslateLoader } from '@ngx-translate/core';
import { Observable } from 'rxjs/Observable';

export class WebpackTranslateLoader implements TranslateLoader {
getTranslation(lang: string): Observable<any> {
return Observable.fromPromise(System.import(`../assets/i18n/${lang}.json`));
}
}
```

Cause `System` will not be available you need to add it to your custom `typings.d.ts`:
```typescript
declare var System: System;
interface System {
import(request: string): Promise<any>;
}
```

Now you can use the `WebpackTranslateLoader` with your `app.module`:
```typescript
@NgModule({
bootstrap: [AppComponent],
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: WebpackTranslateLoader
}
})
]
})
export class AppModule { }
```

The disadvantage of this solution is that you have to rebuild the application everytime your translate files has changes.

0 comments on commit 7bcd991

Please sign in to comment.