UNPKG

ngx-translate-multi-http-loader

Version:

A loader for [ngx-translate](https://github.com/ngx-translate/core) that loads translations using http.

1 lines 2.71 kB
{"version":3,"file":"ngx-translate-multi-http-loader.mjs","sources":["../../../projects/multi-http-loader/src/lib/multi-http-loader.ts","../../../projects/multi-http-loader/src/ngx-translate-multi-http-loader.ts"],"sourcesContent":["import { HttpBackend, HttpClient } from '@angular/common/http'\nimport { TranslateLoader } from '@ngx-translate/core'\nimport { deepmerge } from 'deepmerge-ts'\nimport { forkJoin, Observable, of } from 'rxjs'\nimport { catchError, map } from 'rxjs/operators'\n\nexport interface ITranslationResource {\n prefix: string\n suffix?: string\n optional?: boolean\n}\n\nexport class MultiTranslateHttpLoader implements TranslateLoader {\n constructor(\n private _handler: HttpBackend,\n private _resourcesPrefix: string[] | ITranslationResource[],\n ) {}\n\n public getTranslation(lang: string): Observable<any> {\n const requests: Observable<Object | {}>[] = this._resourcesPrefix.map((resource) => {\n let path: string\n if (resource.prefix) path = `${resource.prefix}${lang}${resource.suffix || '.json'}`\n else path = `${resource}${lang}.json`\n\n return new HttpClient(this._handler).get(path).pipe(\n catchError((res) => {\n if (!resource.optional) {\n console.group()\n console.error('Something went wrong for the following translation file:', path)\n console.error(res)\n console.groupEnd()\n }\n return of({})\n }),\n )\n })\n\n return forkJoin(requests).pipe(map((response) => deepmerge(...response)))\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAYa,wBAAwB,CAAA;IACnC,WACU,CAAA,QAAqB,EACrB,gBAAmD,EAAA;QADnD,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAa;QACrB,IAAgB,CAAA,gBAAA,GAAhB,gBAAgB,CAAmC;KACzD;AAEG,IAAA,cAAc,CAAC,IAAY,EAAA;QAChC,MAAM,QAAQ,GAA8B,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAI;AACjF,YAAA,IAAI,IAAY,CAAA;YAChB,I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