ngx-translate-multi-http-loader 8.0.2 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -90
- package/esm2020/lib/multi-http-loader.mjs +27 -0
- package/esm2020/ngx-translate-multi-http-loader.mjs +5 -0
- package/esm2020/public-api.mjs +2 -0
- package/fesm2015/ngx-translate-multi-http-loader.mjs +34 -0
- package/fesm2015/ngx-translate-multi-http-loader.mjs.map +1 -0
- package/fesm2020/ngx-translate-multi-http-loader.mjs +34 -0
- package/fesm2020/ngx-translate-multi-http-loader.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/multi-http-loader.d.ts +13 -0
- package/package.json +41 -17
- package/public-api.d.ts +1 -0
- package/LICENSE +0 -7
- package/dist/multi-http-loader.d.ts +0 -13
- package/dist/multi-http-loader.js +0 -21
package/README.md
CHANGED
@@ -1,90 +1,99 @@
|
|
1
|
-
# @ngx-translate/multi-http-loader [](https://badge.fury.io/js/ngx-translate-multi-http-loader)
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
* [
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
import {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
1
|
+
# @ngx-translate/multi-http-loader [](https://badge.fury.io/js/ngx-translate-multi-http-loader)
|
2
|
+
|
3
|
+
|
4
|
+
A loader for [ngx-translate](https://github.com/ngx-translate/core) that loads translations using http.
|
5
|
+
|
6
|
+
Angular 13 example: https://github.com/denniske/ngx-translate-multi-http-loader-demo
|
7
|
+
|
8
|
+
Angular 6 example: https://stackblitz.com/edit/ngx-translate-multi-http-loader-sample
|
9
|
+
|
10
|
+
Get the complete changelog here: https://github.com/denniske/ngx-translate-multi-http-loader/releases
|
11
|
+
|
12
|
+
* [Installation](#installation)
|
13
|
+
* [Usage](#usage)
|
14
|
+
|
15
|
+
## breaking change: v9.0.0
|
16
|
+
* This library is now using `httpBackend` instead of the `httpClient`, to avoid being delayed by interceptor, which was creating errors while loading.
|
17
|
+
* From the v9, the library will only be using a list of `string[]` so `prefix` & `suffix` aren't needed anymore and `.json` gonna be the default suffix.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
We assume that you already installed [ngx-translate](https://github.com/ngx-translate/core).
|
22
|
+
|
23
|
+
Now you need to install the npm module for `MultiTranslateHttpLoader`:
|
24
|
+
|
25
|
+
```sh
|
26
|
+
npm install ngx-translate-multi-http-loader --save
|
27
|
+
```
|
28
|
+
|
29
|
+
Choose the version corresponding to your Angular version:
|
30
|
+
|
31
|
+
| Angular | @ngx-translate/core | ngx-translate-multi-http-loader |
|
32
|
+
| ------- | ------------------- | ------------------------------- |
|
33
|
+
| 14 | 14.x+ | 8.x+ |
|
34
|
+
| 13 | 14.x+ | 7.x+ |
|
35
|
+
| 6 | 10.x+ | 1.x+ |
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
_The `MultiTranslateHttpLoader` uses HttpBackend to load translations, therefore :_
|
39
|
+
1. Create and export a new `HttpLoaderFactory` function
|
40
|
+
2. Import the `HttpClientModule` from `@angular/common/http`
|
41
|
+
3. Setup the `TranslateModule` to use the `MultiTranslateHttpLoader`
|
42
|
+
|
43
|
+
```typescript
|
44
|
+
import {NgModule} from '@angular/core';
|
45
|
+
import {BrowserModule} from '@angular/platform-browser';
|
46
|
+
import {HttpClientModule, HttpBackend} from '@angular/common/http';
|
47
|
+
import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
|
48
|
+
import {MultiTranslateHttpLoader} from 'ngx-translate-multi-http-loader';
|
49
|
+
import {AppComponent} from './app';
|
50
|
+
|
51
|
+
// AoT requires an exported function for factories
|
52
|
+
export function HttpLoaderFactory(_httpBackend: HttpBackend) {
|
53
|
+
return new MultiTranslateHttpLoader(_httpBackend, ['/assets/i18n/core/', '/assets/i18n/vendors/']);
|
54
|
+
}
|
55
|
+
|
56
|
+
@NgModule({
|
57
|
+
imports: [
|
58
|
+
BrowserModule,
|
59
|
+
HttpClientModule,
|
60
|
+
TranslateModule.forRoot({
|
61
|
+
loader: {
|
62
|
+
provide: TranslateLoader,
|
63
|
+
useFactory: HttpLoaderFactory,
|
64
|
+
deps: [HttpBackend]
|
65
|
+
}
|
66
|
+
})
|
67
|
+
],
|
68
|
+
bootstrap: [AppComponent]
|
69
|
+
})
|
70
|
+
export class AppModule { }
|
71
|
+
```
|
72
|
+
|
73
|
+
The `MultiTranslateHttpLoader` takes a list of `string[]` or `ITranslationResource[]`.
|
74
|
+
|
75
|
+
### String[]
|
76
|
+
For example `['/assets/i18n/core/', '/assets/i18n/vendors/']`,
|
77
|
+
will load your translations files for the lang "en" from : `/assets/i18n/core/en.json` and `/assets/i18n/vendors/en.json`
|
78
|
+
|
79
|
+
### Custom suffix
|
80
|
+
**For now this loader only support the `json` format.**
|
81
|
+
|
82
|
+
Instead of an array of `string[]`,
|
83
|
+
you may pass a list of parameters:
|
84
|
+
- `prefix: string = '/assets/i18n/'`
|
85
|
+
- `suffix: string = '.json'`
|
86
|
+
|
87
|
+
```typescript
|
88
|
+
export function HttpLoaderFactory(_httpBackend: HttpBackend) {
|
89
|
+
return new MultiTranslateHttpLoader(_httpBackend, [
|
90
|
+
{prefix: './assets/i18n/core/', suffix: '.json'},
|
91
|
+
{prefix: './assets/i18n/vendors/'}, // , "suffix: '.json'" being the default value
|
92
|
+
]);
|
93
|
+
}
|
94
|
+
```
|
95
|
+
|
96
|
+
The loader will merge all translation files from the server using [deepmerge](https://github.com/KyleAMathews/deepmerge).
|
97
|
+
|
98
|
+
## Authors and acknowledgment
|
99
|
+
* Former maintainer [Dennis Keil](https://github.com/denniske)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
2
|
+
import * as merge from 'deepmerge';
|
3
|
+
import { forkJoin, of } from 'rxjs';
|
4
|
+
import { catchError, map } from 'rxjs/operators';
|
5
|
+
export class MultiTranslateHttpLoader {
|
6
|
+
constructor(_handler, _resourcesPrefix) {
|
7
|
+
this._handler = _handler;
|
8
|
+
this._resourcesPrefix = _resourcesPrefix;
|
9
|
+
}
|
10
|
+
getTranslation(lang) {
|
11
|
+
const requests = this._resourcesPrefix.map((resource) => {
|
12
|
+
let path;
|
13
|
+
if (resource.prefix)
|
14
|
+
path = `${resource.prefix}${lang}${resource.suffix || '.json'}`;
|
15
|
+
else {
|
16
|
+
path = `${resource}${lang}.json`;
|
17
|
+
}
|
18
|
+
return new HttpClient(this._handler).get(path).pipe(catchError((res) => {
|
19
|
+
console.error('Something went wrong for the following translation file:', path);
|
20
|
+
console.error(res.message);
|
21
|
+
return of({});
|
22
|
+
}));
|
23
|
+
});
|
24
|
+
return forkJoin(requests).pipe(map((response) => merge.all(response)));
|
25
|
+
}
|
26
|
+
}
|
27
|
+
//# sour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gICAgICApXHJcbiAgICB9KVxyXG5cclxuICAgIHJldHVybiBmb3JrSm9pbihyZXF1ZXN0cykucGlwZShtYXAoKHJlc3BvbnNlKSA9PiBtZXJnZS5hbGwocmVzcG9uc2UpKSlcclxuICB9XHJcbn1cclxuIl19
|
@@ -0,0 +1,5 @@
|
|
1
|
+
/**
|
2
|
+
* Generated bundle index. Do not edit.
|
3
|
+
*/
|
4
|
+
export * from './public-api';
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmd4LXRyYW5zbGF0ZS1tdWx0aS1odHRwLWxvYWRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL211bHRpLWh0dHAtbG9hZGVyL3NyYy9uZ3gtdHJhbnNsYXRlLW11bHRpLWh0dHAtbG9hZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBRUgsY0FBYyxjQUFjLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIEdlbmVyYXRlZCBidW5kbGUgaW5kZXguIERvIG5vdCBlZGl0LlxuICovXG5cbmV4cG9ydCAqIGZyb20gJy4vcHVibGljLWFwaSc7XG4iXX0=
|
@@ -0,0 +1,2 @@
|
|
1
|
+
export * from './lib/multi-http-loader';
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL211bHRpLWh0dHAtbG9hZGVyL3NyYy9wdWJsaWMtYXBpLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMseUJBQXlCLENBQUEiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgKiBmcm9tICcuL2xpYi9tdWx0aS1odHRwLWxvYWRlcidcclxuIl19
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
2
|
+
import * as merge from 'deepmerge';
|
3
|
+
import { of, forkJoin } from 'rxjs';
|
4
|
+
import { catchError, map } from 'rxjs/operators';
|
5
|
+
|
6
|
+
class MultiTranslateHttpLoader {
|
7
|
+
constructor(_handler, _resourcesPrefix) {
|
8
|
+
this._handler = _handler;
|
9
|
+
this._resourcesPrefix = _resourcesPrefix;
|
10
|
+
}
|
11
|
+
getTranslation(lang) {
|
12
|
+
const requests = this._resourcesPrefix.map((resource) => {
|
13
|
+
let path;
|
14
|
+
if (resource.prefix)
|
15
|
+
path = `${resource.prefix}${lang}${resource.suffix || '.json'}`;
|
16
|
+
else {
|
17
|
+
path = `${resource}${lang}.json`;
|
18
|
+
}
|
19
|
+
return new HttpClient(this._handler).get(path).pipe(catchError((res) => {
|
20
|
+
console.error('Something went wrong for the following translation file:', path);
|
21
|
+
console.error(res.message);
|
22
|
+
return of({});
|
23
|
+
}));
|
24
|
+
});
|
25
|
+
return forkJoin(requests).pipe(map((response) => merge.all(response)));
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Generated bundle index. Do not edit.
|
31
|
+
*/
|
32
|
+
|
33
|
+
export { MultiTranslateHttpLoader };
|
34
|
+
//# sourceMappingURL=ngx-translate-multi-http-loader.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"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'\r\nimport { TranslateLoader } from '@ngx-translate/core'\r\nimport * as merge from 'deepmerge'\r\nimport { forkJoin, Observable, of } from 'rxjs'\r\nimport { catchError, map } from 'rxjs/operators'\r\n\r\nexport interface ITranslationResource {\r\n prefix: string\r\n suffix?: string\r\n}\r\n\r\nexport class MultiTranslateHttpLoader implements TranslateLoader {\r\n constructor(\r\n private _handler: HttpBackend,\r\n private _resourcesPrefix: string[] | ITranslationResource[],\r\n ) {}\r\n\r\n public getTranslation(lang: string): Observable<any> {\r\n const requests = this._resourcesPrefix.map((resource) => {\r\n let path: string\r\n if (resource.prefix) path = `${resource.prefix}${lang}${resource.suffix || '.json'}`\r\n else {\r\n path = `${resource}${lang}.json`\r\n }\r\n\r\n return new HttpClient(this._handler).get(path).pipe(\r\n catchError((res) => {\r\n console.error('Something went wrong for the following translation file:', path)\r\n console.error(res.message)\r\n return of({})\r\n }),\r\n )\r\n })\r\n\r\n return forkJoin(requests).pipe(map((response) => merge.all(response)))\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAWa,wBAAwB,CAAA;IACnC,WACU,CAAA,QAAqB,EACrB,gBAAmD,EAAA;AADnD,QAAA,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAa;AACrB,QAAA,IAAgB,CAAA,gBAAA,GAAhB,gBAAgB,CAAmC;KACzD;AAEG,IAAA,cAAc,CAAC,IAAY,EAAA;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAI;AACtD,YAAA,IAAI,IAAY,CAAA;YAChB,IAAI,QAAQ,CAAC,MAAM;AAAE,gBAAA,IAAI,GAAG,CAAA,EAAG,QAAQ,CAAC,MAAM,CAAG,EAAA,IAAI,CAAG,EAAA,QAAQ,CAAC,MAAM,IAAI,OAAO,EAAE,CAAA;AAC/E,iBAAA;AACH,gBAAA,IAAI,GAAG,CAAG,EAAA,QAAQ,CAAG,EAAA,IAAI,OAAO,CAAA;AACjC,aAAA;YAED,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CACjD,UAAU,CAAC,CAAC,GAAG,KAAI;AACjB,gBAAA,OAAO,CAAC,KAAK,CAAC,0DAA0D,EAAE,IAAI,CAAC,CAAA;AAC/E,gBAAA,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;AAC1B,gBAAA,OAAO,EAAE,CAAC,EAAE,CAAC,CAAA;aACd,CAAC,CACH,CAAA;AACH,SAAC,CAAC,CAAA;QAEF,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAK,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;KACvE;AACF;;ACpCD;;AAEG;;;;"}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
2
|
+
import * as merge from 'deepmerge';
|
3
|
+
import { of, forkJoin } from 'rxjs';
|
4
|
+
import { catchError, map } from 'rxjs/operators';
|
5
|
+
|
6
|
+
class MultiTranslateHttpLoader {
|
7
|
+
constructor(_handler, _resourcesPrefix) {
|
8
|
+
this._handler = _handler;
|
9
|
+
this._resourcesPrefix = _resourcesPrefix;
|
10
|
+
}
|
11
|
+
getTranslation(lang) {
|
12
|
+
const requests = this._resourcesPrefix.map((resource) => {
|
13
|
+
let path;
|
14
|
+
if (resource.prefix)
|
15
|
+
path = `${resource.prefix}${lang}${resource.suffix || '.json'}`;
|
16
|
+
else {
|
17
|
+
path = `${resource}${lang}.json`;
|
18
|
+
}
|
19
|
+
return new HttpClient(this._handler).get(path).pipe(catchError((res) => {
|
20
|
+
console.error('Something went wrong for the following translation file:', path);
|
21
|
+
console.error(res.message);
|
22
|
+
return of({});
|
23
|
+
}));
|
24
|
+
});
|
25
|
+
return forkJoin(requests).pipe(map((response) => merge.all(response)));
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Generated bundle index. Do not edit.
|
31
|
+
*/
|
32
|
+
|
33
|
+
export { MultiTranslateHttpLoader };
|
34
|
+
//# sourceMappingURL=ngx-translate-multi-http-loader.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"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'\r\nimport { TranslateLoader } from '@ngx-translate/core'\r\nimport * as merge from 'deepmerge'\r\nimport { forkJoin, Observable, of } from 'rxjs'\r\nimport { catchError, map } from 'rxjs/operators'\r\n\r\nexport interface ITranslationResource {\r\n prefix: string\r\n suffix?: string\r\n}\r\n\r\nexport class MultiTranslateHttpLoader implements TranslateLoader {\r\n constructor(\r\n private _handler: HttpBackend,\r\n private _resourcesPrefix: string[] | ITranslationResource[],\r\n ) {}\r\n\r\n public getTranslation(lang: string): Observable<any> {\r\n const requests = this._resourcesPrefix.map((resource) => {\r\n let path: string\r\n if (resource.prefix) path = `${resource.prefix}${lang}${resource.suffix || '.json'}`\r\n else {\r\n path = `${resource}${lang}.json`\r\n }\r\n\r\n return new HttpClient(this._handler).get(path).pipe(\r\n catchError((res) => {\r\n console.error('Something went wrong for the following translation file:', path)\r\n console.error(res.message)\r\n return of({})\r\n }),\r\n )\r\n })\r\n\r\n return forkJoin(requests).pipe(map((response) => merge.all(response)))\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAWa,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,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAI;AACtD,YAAA,IAAI,IAAY,CAAA;YAChB,IAAI,QAAQ,CAAC,MAAM;AAAE,gBAAA,IAAI,GAAG,CAAA,EAAG,QAAQ,CAAC,MAAM,CAAG,EAAA,IAAI,CAAG,EAAA,QAAQ,CAAC,MAAM,IAAI,OAAO,EAAE,CAAA;AAC/E,iBAAA;AACH,gBAAA,IAAI,GAAG,CAAG,EAAA,QAAQ,CAAG,EAAA,IAAI,OAAO,CAAA;AACjC,aAAA;YAED,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CACjD,UAAU,CAAC,CAAC,GAAG,KAAI;AACjB,gBAAA,OAAO,CAAC,KAAK,CAAC,0DAA0D,EAAE,IAAI,CAAC,CAAA;AAC/E,gBAAA,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;AAC1B,gBAAA,OAAO,EAAE,CAAC,EAAE,CAAC,CAAA;aACd,CAAC,CACH,CAAA;AACH,SAAC,CAAC,CAAA;QAEF,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAK,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;KACvE;AACF;;ACpCD;;AAEG;;;;"}
|
package/index.d.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import { HttpBackend } from '@angular/common/http';
|
2
|
+
import { TranslateLoader } from '@ngx-translate/core';
|
3
|
+
import { Observable } from 'rxjs';
|
4
|
+
export interface ITranslationResource {
|
5
|
+
prefix: string;
|
6
|
+
suffix?: string;
|
7
|
+
}
|
8
|
+
export declare class MultiTranslateHttpLoader implements TranslateLoader {
|
9
|
+
private _handler;
|
10
|
+
private _resourcesPrefix;
|
11
|
+
constructor(_handler: HttpBackend, _resourcesPrefix: string[] | ITranslationResource[]);
|
12
|
+
getTranslation(lang: string): Observable<any>;
|
13
|
+
}
|
package/package.json
CHANGED
@@ -1,28 +1,52 @@
|
|
1
1
|
{
|
2
2
|
"name": "ngx-translate-multi-http-loader",
|
3
|
-
"version": "
|
3
|
+
"version": "9.0.1",
|
4
4
|
"license": "MIT",
|
5
|
+
"author": "Raphael Balet",
|
5
6
|
"maintainers": [
|
6
|
-
"
|
7
|
+
"raphael.balet@outlook.com"
|
7
8
|
],
|
8
|
-
"
|
9
|
-
"
|
10
|
-
"
|
9
|
+
"keywords": [
|
10
|
+
"angular",
|
11
|
+
"i18n",
|
12
|
+
"transalte",
|
13
|
+
"ngx-translate"
|
14
|
+
],
|
15
|
+
"homepage": "https://github.com/rbalet/ngx-translate-multi-http-loader#readme",
|
16
|
+
"bugs": {
|
17
|
+
"url": "https://github.com/rbalet/ngx-translate-multi-http-loader/issues"
|
18
|
+
},
|
19
|
+
"repository": {
|
20
|
+
"url": "https://github.com/rbalet/ngx-translate-multi-http-loader"
|
11
21
|
},
|
12
22
|
"dependencies": {
|
13
|
-
"
|
14
|
-
|
23
|
+
"tslib": "^2.4.0"
|
24
|
+
},
|
25
|
+
"peerDependencies": {
|
26
|
+
"@angular/common": ">=12.0.0",
|
27
|
+
"@angular/core": ">=12.0.0",
|
15
28
|
"@ngx-translate/core": ">=14.0.0",
|
16
29
|
"deepmerge": ">=4.2.2",
|
17
|
-
"rxjs": "
|
18
|
-
"tslib": ">=2.0.0"
|
30
|
+
"rxjs": "7.5.7"
|
19
31
|
},
|
20
|
-
"
|
21
|
-
|
32
|
+
"module": "fesm2015/ngx-translate-multi-http-loader.mjs",
|
33
|
+
"es2020": "fesm2020/ngx-translate-multi-http-loader.mjs",
|
34
|
+
"esm2020": "esm2020/ngx-translate-multi-http-loader.mjs",
|
35
|
+
"fesm2020": "fesm2020/ngx-translate-multi-http-loader.mjs",
|
36
|
+
"fesm2015": "fesm2015/ngx-translate-multi-http-loader.mjs",
|
37
|
+
"typings": "index.d.ts",
|
38
|
+
"exports": {
|
39
|
+
"./package.json": {
|
40
|
+
"default": "./package.json"
|
41
|
+
},
|
42
|
+
".": {
|
43
|
+
"types": "./index.d.ts",
|
44
|
+
"esm2020": "./esm2020/ngx-translate-multi-http-loader.mjs",
|
45
|
+
"es2020": "./fesm2020/ngx-translate-multi-http-loader.mjs",
|
46
|
+
"es2015": "./fesm2015/ngx-translate-multi-http-loader.mjs",
|
47
|
+
"node": "./fesm2015/ngx-translate-multi-http-loader.mjs",
|
48
|
+
"default": "./fesm2020/ngx-translate-multi-http-loader.mjs"
|
49
|
+
}
|
22
50
|
},
|
23
|
-
"
|
24
|
-
|
25
|
-
"files": [
|
26
|
-
"/dist"
|
27
|
-
]
|
28
|
-
}
|
51
|
+
"sideEffects": false
|
52
|
+
}
|
package/public-api.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './lib/multi-http-loader';
|
package/LICENSE
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
Copyright (c) 2022 Dennis Keil
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
-
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
-
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { HttpClient } from "@angular/common/http";
|
2
|
-
import { TranslateLoader } from "@ngx-translate/core";
|
3
|
-
import { Observable } from "rxjs";
|
4
|
-
export interface ITranslationResource {
|
5
|
-
prefix: string;
|
6
|
-
suffix: string;
|
7
|
-
}
|
8
|
-
export declare class MultiTranslateHttpLoader implements TranslateLoader {
|
9
|
-
private http;
|
10
|
-
private resources;
|
11
|
-
constructor(http: HttpClient, resources: ITranslationResource[]);
|
12
|
-
getTranslation(lang: string): Observable<any>;
|
13
|
-
}
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import { forkJoin, of } from "rxjs";
|
2
|
-
import { catchError, map } from "rxjs/operators";
|
3
|
-
// @ts-ignore
|
4
|
-
import merge from 'deepmerge';
|
5
|
-
export class MultiTranslateHttpLoader {
|
6
|
-
constructor(http, resources) {
|
7
|
-
this.http = http;
|
8
|
-
this.resources = resources;
|
9
|
-
}
|
10
|
-
getTranslation(lang) {
|
11
|
-
const requests = this.resources.map(resource => {
|
12
|
-
const path = resource.prefix + lang + resource.suffix;
|
13
|
-
return this.http.get(path).pipe(catchError(res => {
|
14
|
-
console.error("Something went wrong for the following translation file:", path);
|
15
|
-
console.error(res.message);
|
16
|
-
return of({});
|
17
|
-
}));
|
18
|
-
});
|
19
|
-
return forkJoin(requests).pipe(map(response => merge.all(response)));
|
20
|
-
}
|
21
|
-
}
|