https://github.com/gilsdav/configurable-translate-http-loader
Be able to change prefix after "useFactory" call but before TranslateHttpLoader will be executed.
https://github.com/gilsdav/configurable-translate-http-loader
angular async asynchronous configurable http-loader ngx-translate translatehttploader
Last synced: 7 months ago
JSON representation
Be able to change prefix after "useFactory" call but before TranslateHttpLoader will be executed.
- Host: GitHub
- URL: https://github.com/gilsdav/configurable-translate-http-loader
- Owner: gilsdav
- Created: 2018-02-20T11:57:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-06T09:43:57.000Z (over 4 years ago)
- Last Synced: 2025-01-24T15:27:48.958Z (9 months ago)
- Topics: angular, async, asynchronous, configurable, http-loader, ngx-translate, translatehttploader
- Language: TypeScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# configurable-translate-http-loader
Be able to change prefix after "useFactory" call but before TranslateHttpLoader will be called.## Why ? ##
Because I need to get async configuration that contains the prefix.**Before**
```
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, '???', '.json'); // Don't know what to put as prefix because it's in config
}@NgModule({
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient] // Can not add 'CONFIG' here because is optional
}
})
]
})
export class AppModule {
constructor(@Optional()@Inject('CONFIG') config) {
// Have config.localesPath but too late to manage prefix of TranslateHttpLoader
}
}
```**After**
```
export function createTranslateLoader(http: HttpClient) {
return new ConfigurableTranslateHttpLoader(http, '', '.json'); // You can put anything for prefix here. It will not be used.
}@NgModule({
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient]
}
})
]
})
export class AppModule {
constructor(@Optional()@Inject('CONFIG') config) {
// Need minimum one call of this :
ConfigurableTranslateHttpLoader.localesPathSubject.next(config.localesPath); // Give path of locales and allow TranslateHttpLoader to answer
}
}
```