core
core copied to clipboard
How to custom TranslateLoader to pass multi parameters to URL?
I have url to get file json from backend like this
/assets/${customerName}/${lang}.json
I tried to many way but i don't know how to pass customerName to url inside prefix of TranslateHttpLoader. pls help me ASAP. I really appreciate your support.
Hi, I too have the same question. Do we got a answer? Actually I like to call the getTranslation method but it has only one parameter that is language. Here I like to call the api and pass the list of keys to api and get the values only for the requested key. So I am looking how to pass the parameter to the api call.
Try below one.
//imports
let yourParam: string;
class CustomLoader implements TranslateLoader {
constructor() { }
getTranslation(lang: string): Observable<any> {
console.log(yourParam);
}
}
@NgModule({
imports: [
CommonModule,
TranslateModule.forRoot({
defaultLanguage: 'en-us',
loader: {
provide: TranslateLoader,
useClass: CustomLoader,
deps: []
}
}),
],
exports: [CommonModule, TranslateModule],
providers: []
})
export class i18nModule {
static forRoot(customParam: string): ModuleWithProviders<i18nModule> {
yourParam = customParam;
return {
ngModule: i18nModule
}
}
constructor(translate: TranslateService) {
//do logic of translation
}
}