@@ -10,10 +10,16 @@ export interface TranslateHttpLoaderResource {
1010}
1111
1212export interface TranslateHttpLoaderConfig {
13- prefix : string ;
14- suffix : string ;
13+ /**
14+ * @deprecated Use `resources` instead. `prefix` and `suffix` will be removed in a future version.
15+ */
16+ prefix ?: string ;
17+ /**
18+ * @deprecated Use `resources` instead. `prefix` and `suffix` will be removed in a future version.
19+ */
20+ suffix ?: string ;
1521 showLog ?: boolean ;
16- ressources : ( string | TranslateHttpLoaderResource ) [ ] ;
22+ resources : ( string | TranslateHttpLoaderResource ) [ ] ;
1723 enforceLoading : boolean ;
1824 useHttpBackend : boolean ;
1925}
@@ -31,7 +37,7 @@ export class TranslateHttpLoader implements TranslateLoader {
3137 this . config = {
3238 prefix : "/assets/i18n/" ,
3339 suffix : ".json" ,
34- ressources : [ ] ,
40+ resources : [ ] ,
3541 enforceLoading : false ,
3642 useHttpBackend : false ,
3743 ...inject ( TRANSLATE_HTTP_LOADER_CONFIG ) ,
@@ -48,43 +54,28 @@ export class TranslateHttpLoader implements TranslateLoader {
4854 public getTranslation ( lang : string ) : Observable < TranslationObject > {
4955 const cacheBuster = this . config . enforceLoading ? `?enforceLoading=${ Date . now ( ) } ` : "" ;
5056
51- if ( this . config . ressources . length > 0 ) {
52- const requests = this . config . ressources . map ( ( resource ) => {
53- let path : string ;
57+ if ( ( ! this . config . resources || this . config . resources . length <= 0 ) && this . config . prefix )
58+ this . config . resources = [ { prefix : this . config . prefix , suffix : this . config . suffix } ] ;
5459
55- if ( typeof resource === "string" ) path = ` ${ resource } ${ lang } .json` ;
56- else path = ` ${ resource . prefix } ${ lang } ${ resource . suffix ?? ".json" } ` ;
60+ const requests = this . config . resources . map ( ( resource ) => {
61+ let path : string ;
5762
58- return this . http . get < TranslationObject > ( `${ path } ${ cacheBuster } ` ) . pipe (
59- catchError ( ( err ) => {
60- if (
61- this . config . showLog ||
62- ( resource as TranslateHttpLoaderResource ) . showLog
63- ) {
64- console . error ( `Error loading translation for ${ lang } :` , err ) ;
65- }
66- return of ( { } ) ;
67- } ) ,
68- ) ;
69- } ) ;
63+ if ( typeof resource === "string" ) path = `${ resource } ${ lang } .json` ;
64+ else path = `${ resource . prefix } ${ lang } ${ resource . suffix ?? ".json" } ` ;
7065
71- return forkJoin ( requests ) . pipe (
72- map ( ( response ) => response . reduce ( ( acc , curr ) => mergeDeep ( acc , curr ) , { } ) ) ,
73- ) as Observable < TranslationObject > ;
74- }
75-
76- return this . http
77- . get < TranslationObject > (
78- `${ this . config . prefix } ${ lang } ${ this . config . suffix } ${ cacheBuster } ` ,
79- )
80- . pipe (
66+ return this . http . get < TranslationObject > ( `${ path } ${ cacheBuster } ` ) . pipe (
8167 catchError ( ( err ) => {
82- if ( this . config . showLog ) {
68+ if ( this . config . showLog || ( resource as TranslateHttpLoaderResource ) . showLog ) {
8369 console . error ( `Error loading translation for ${ lang } :` , err ) ;
8470 }
8571 return of ( { } ) ;
8672 } ) ,
8773 ) ;
74+ } ) ;
75+
76+ return forkJoin ( requests ) . pipe (
77+ map ( ( response ) => response . reduce ( ( acc , curr ) => mergeDeep ( acc , curr ) , { } ) ) ,
78+ ) as Observable < TranslationObject > ;
8879 }
8980}
9081
0 commit comments