ngx-translate-multi-http-loader 19.0.0 → 19.0.2
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.
@@ -15,7 +15,7 @@ export class MultiTranslateHttpLoader {
|
|
15
15
|
if (typeof resource === 'string')
|
16
16
|
path = `${resource}${lang}.json`;
|
17
17
|
else
|
18
|
-
path = `${resource.prefix}${lang}${resource.suffix
|
18
|
+
path = `${resource.prefix}${lang}${resource.suffix ?? '.json'}`;
|
19
19
|
return new HttpClient(this._handler).get(path).pipe(catchError((res) => {
|
20
20
|
if (typeof resource !== 'string' && !resource.optional) {
|
21
21
|
console.group();
|
@@ -28,9 +28,5 @@ export class MultiTranslateHttpLoader {
|
|
28
28
|
});
|
29
29
|
return forkJoin(requests).pipe(map((response) => response.reduce((acc, curr) => mergeDeep(acc, curr), {})));
|
30
30
|
}
|
31
|
-
// @ToDo: Use it from ngx-translate once it gets exported: https://github.com/rbalet/ngx-translate-multi-http-loader/issues/35
|
32
|
-
isObject(item) {
|
33
|
-
return item && typeof item === 'object' && !Array.isArray(item);
|
34
|
-
}
|
35
31
|
}
|
36
|
-
//# sourceMappingURL=data:application/json;base64,
|
32
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibXVsdGktaHR0cC1sb2FkZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9tdWx0aS1odHRwLWxvYWRlci9zcmMvbGliL211bHRpLWh0dHAtbG9hZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBZSxVQUFVLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQTtBQUM5RCxPQUFPLEVBQUUsU0FBUyxFQUFtQixNQUFNLHFCQUFxQixDQUFBO0FBQ2hFLE9BQU8sRUFBRSxRQUFRLEVBQWMsRUFBRSxFQUFFLE1BQU0sTUFBT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gIH0pXG5cbiAgICByZXR1cm4gZm9ya0pvaW4ocmVxdWVzdHMpLnBpcGUoXG4gICAgICBtYXAoKHJlc3BvbnNlKSA9PiByZXNwb25zZS5yZWR1Y2UoKGFjYywgY3VycikgPT4gbWVyZ2VEZWVwKGFjYywgY3VyciksIHt9KSksXG4gICAgKVxuICB9XG59XG4iXX0=
|
@@ -16,7 +16,7 @@ class MultiTranslateHttpLoader {
|
|
16
16
|
if (typeof resource === 'string')
|
17
17
|
path = `${resource}${lang}.json`;
|
18
18
|
else
|
19
|
-
path = `${resource.prefix}${lang}${resource.suffix
|
19
|
+
path = `${resource.prefix}${lang}${resource.suffix ?? '.json'}`;
|
20
20
|
return new HttpClient(this._handler).get(path).pipe(catchError((res) => {
|
21
21
|
if (typeof resource !== 'string' && !resource.optional) {
|
22
22
|
console.group();
|
@@ -29,10 +29,6 @@ class MultiTranslateHttpLoader {
|
|
29
29
|
});
|
30
30
|
return forkJoin(requests).pipe(map((response) => response.reduce((acc, curr) => mergeDeep(acc, curr), {})));
|
31
31
|
}
|
32
|
-
// @ToDo: Use it from ngx-translate once it gets exported: https://github.com/rbalet/ngx-translate-multi-http-loader/issues/35
|
33
|
-
isObject(item) {
|
34
|
-
return item && typeof item === 'object' && !Array.isArray(item);
|
35
|
-
}
|
36
32
|
}
|
37
33
|
|
38
34
|
/**
|
@@ -1 +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'\nimport { mergeDeep, TranslateLoader } from '@ngx-translate/core'\nimport { forkJoin, Observable, of } from 'rxjs'\nimport { catchError, map } from 'rxjs/operators'\n\nexport interface TranslationResource {\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
|
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'\nimport { mergeDeep, TranslateLoader } from '@ngx-translate/core'\nimport { forkJoin, Observable, of } from 'rxjs'\nimport { catchError, map } from 'rxjs/operators'\n\nexport interface TranslationResource {\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 | TranslationResource)[],\n ) {}\n\n public getTranslation(lang: string): Observable<any> {\n const requests: Observable<Object | {}>[] = this._resourcesPrefix.map((resource) => {\n let path: string\n\n if (typeof resource === 'string') path = `${resource}${lang}.json`\n else path = `${resource.prefix}${lang}${resource.suffix ?? '.json'}`\n\n return new HttpClient(this._handler).get(path).pipe(\n catchError((res) => {\n if (typeof resource !== 'string' && !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(\n map((response) => response.reduce((acc, curr) => mergeDeep(acc, curr), {})),\n )\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAWa,wBAAwB,CAAA;AAEzB,IAAA,QAAA,CAAA;AACA,IAAA,gBAAA,CAAA;IAFV,WACU,CAAA,QAAqB,EACrB,gBAAkD,EAAA;QADlD,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAa;QACrB,IAAgB,CAAA,gBAAA,GAAhB,gBAAgB,CAAkC;KACxD;AAEG,IAAA,cAAc,CAAC,IAAY,EAAA;QAChC,MAAM,QAAQ,GAA8B,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAI;AACjF,YAAA,IAAI,IAAY,CAAA;YAEhB,IAAI,OAAO,QAAQ,KAAK,QAAQ;AAAE,gBAAA,IAAI,GAAG,CAAG,EAAA,QAAQ,CAAG,EAAA,IAAI,OAAO,CAAA;;AAC7D,gBAAA,IAAI,GAAG,CAAA,EAAG,QAAQ,CAAC,MAAM,CAAG,EAAA,IAAI,CAAG,EAAA,QAAQ,CAAC,MAAM,IAAI,OAAO,EAAE,CAAA;YAEpE,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CACjD,UAAU,CAAC,CAAC,GAAG,KAAI;gBACjB,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE;oBACtD,OAAO,CAAC,KAAK,EAAE,CAAA;AACf,oBAAA,OAAO,CAAC,KAAK,CAAC,0DAA0D,EAAE,IAAI,CAAC,CAAA;AAC/E,oBAAA,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;oBAClB,OAAO,CAAC,QAAQ,EAAE,CAAA;iBACnB;AACD,gBAAA,OAAO,EAAE,CAAC,EAAE,CAAC,CAAA;aACd,CAAC,CACH,CAAA;AACH,SAAC,CAAC,CAAA;AAEF,QAAA,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAC5B,GAAG,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAC5E,CAAA;KACF;AACF;;ACzCD;;AAEG;;;;"}
|
@@ -9,7 +9,6 @@ export interface TranslationResource {
|
|
9
9
|
export declare class MultiTranslateHttpLoader implements TranslateLoader {
|
10
10
|
private _handler;
|
11
11
|
private _resourcesPrefix;
|
12
|
-
constructor(_handler: HttpBackend, _resourcesPrefix: string
|
12
|
+
constructor(_handler: HttpBackend, _resourcesPrefix: (string | TranslationResource)[]);
|
13
13
|
getTranslation(lang: string): Observable<any>;
|
14
|
-
isObject(item: any): boolean;
|
15
14
|
}
|
package/package.json
CHANGED
package/README.md
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
# @ngx-translate/multi-http-loader
|
2
|
-
|
3
|
-
A loader for [ngx-translate](https://github.com/ngx-translate/core) that loads translations using http.
|
4
|
-
|
5
|
-
[](https://www.npmjs.com/package/ngx-translate-multi-http-loader)  
|
6
|
-

|
7
|
-
|
8
|
-
Angular 14 example: https://stackblitz.com/edit/ngx-translate-multi-http-loader-sample-2clau3?file=src/app/app.module.ts
|
9
|
-
|
10
|
-
Angular 6 example: https://stackblitz.com/edit/ngx-translate-multi-http-loader-sample
|
11
|
-
|
12
|
-
Get the complete changelog here: https://github.com/rbalet/ngx-translate-multi-http-loader/releases
|
13
|
-
|
14
|
-
* [Installation](#installation)
|
15
|
-
* [Usage](#usage)
|
16
|
-
* [Error & BugFix](#possible-error--bugfix)
|
17
|
-
|
18
|
-
## breaking change: v19.0.0
|
19
|
-
* Uses `mergeDeep` from `@ngx-translate/core@16` making it's `v16` mandatory
|
20
|
-
|
21
|
-
## breaking change: v9.0.0
|
22
|
-
* This library is now using `httpBackend` instead of the `httpClient`, to avoid being delayed by interceptor, which was creating errors while loading.
|
23
|
-
* 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.
|
24
|
-
|
25
|
-
## Installation
|
26
|
-
|
27
|
-
We assume that you already installed [ngx-translate](https://github.com/ngx-translate/core).
|
28
|
-
|
29
|
-
Now you need to install the npm module for `MultiTranslateHttpLoader`:
|
30
|
-
|
31
|
-
```sh
|
32
|
-
npm install ngx-translate-multi-http-loader
|
33
|
-
```
|
34
|
-
|
35
|
-
Choose the version corresponding to your Angular version:
|
36
|
-
|
37
|
-
| Angular | @ngx-translate/core | ngx-translate-multi-http-loader |
|
38
|
-
| ------- | ------------------- | ------------------------------- |
|
39
|
-
| >= 16 | 16.x+ | >= 19.x+ |
|
40
|
-
| >= 16 | 15.x+ | >= 15.x+ |
|
41
|
-
| 15 | 14.x+ | 9.x+ |
|
42
|
-
| 14 | 14.x+ | 8.x+ |
|
43
|
-
| 13 | 14.x+ | 7.x+ |
|
44
|
-
| 6 | 10.x+ | 1.x+ |
|
45
|
-
|
46
|
-
## Usage
|
47
|
-
_The `MultiTranslateHttpLoader` uses HttpBackend to load translations, therefore :_
|
48
|
-
1. Create and export a new `HttpLoaderFactory` function
|
49
|
-
2. Import the `HttpClientModule` from `@angular/common/http`
|
50
|
-
3. Setup the `TranslateModule` to use the `MultiTranslateHttpLoader`
|
51
|
-
|
52
|
-
```typescript
|
53
|
-
import {NgModule} from '@angular/core';
|
54
|
-
import {BrowserModule} from '@angular/platform-browser';
|
55
|
-
import {HttpClientModule, HttpBackend} from '@angular/common/http';
|
56
|
-
import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
|
57
|
-
import {MultiTranslateHttpLoader} from 'ngx-translate-multi-http-loader';
|
58
|
-
import {AppComponent} from './app';
|
59
|
-
|
60
|
-
// AoT requires an exported function for factories
|
61
|
-
export function HttpLoaderFactory(_httpBackend: HttpBackend) {
|
62
|
-
return new MultiTranslateHttpLoader(_httpBackend, ['/assets/i18n/core/', '/assets/i18n/vendors/']); // /i18n/core/ on angular >= v18 with the new public logic
|
63
|
-
}
|
64
|
-
|
65
|
-
@NgModule({
|
66
|
-
imports: [
|
67
|
-
BrowserModule,
|
68
|
-
HttpClientModule,
|
69
|
-
TranslateModule.forRoot({
|
70
|
-
loader: {
|
71
|
-
provide: TranslateLoader,
|
72
|
-
useFactory: HttpLoaderFactory,
|
73
|
-
deps: [HttpBackend]
|
74
|
-
}
|
75
|
-
})
|
76
|
-
],
|
77
|
-
bootstrap: [AppComponent]
|
78
|
-
})
|
79
|
-
export class AppModule { }
|
80
|
-
```
|
81
|
-
|
82
|
-
The `MultiTranslateHttpLoader` takes a list of `string[]` or `TranslationResource[]`.
|
83
|
-
|
84
|
-
### String[]
|
85
|
-
For example `['/assets/i18n/core/', '/assets/i18n/vendors/']`,
|
86
|
-
will load your translations files for the lang "en" from : `/assets/i18n/core/en.json` and `/assets/i18n/vendors/en.json`
|
87
|
-
|
88
|
-
### Custom suffix
|
89
|
-
**For now this loader only support the `json` format.**
|
90
|
-
|
91
|
-
Instead of an array of `string[]`,
|
92
|
-
you may pass a list of parameters:
|
93
|
-
- `prefix: string = '/assets/i18n/'`
|
94
|
-
- `suffix: string = '.json'`
|
95
|
-
- `optional: boolean = true`
|
96
|
-
|
97
|
-
```typescript
|
98
|
-
export function HttpLoaderFactory(_httpBackend: HttpBackend) {
|
99
|
-
return new MultiTranslateHttpLoader(_httpBackend, [
|
100
|
-
{prefix: './assets/i18n/core/', suffix: '.json'},
|
101
|
-
{prefix: './assets/i18n/vendors/'}, // , "suffix: '.json'" being the default value
|
102
|
-
{prefix: './assets/i18n/non-existent/', optional: true}, // Wont create any log
|
103
|
-
]);
|
104
|
-
}
|
105
|
-
```
|
106
|
-
|
107
|
-
The loader will merge all translation files from the server
|
108
|
-
|
109
|
-
|
110
|
-
## Possible error & Bugfix
|
111
|
-
### values.at is not a function
|
112
|
-
1. Install `core-js`
|
113
|
-
2. In `polyfills.ts`, add `import 'core-js/modules/es.array.at'`
|
114
|
-
|
115
|
-
|
116
|
-
## Authors and acknowledgment
|
117
|
-
* maintainer [Raphaël Balet](https://github.com/rbalet)
|
118
|
-
* Former maintainer [Dennis Keil](https://github.com/denniske)
|
119
|
-
*
|
120
|
-
[](https://www.buymeacoffee.com/widness)
|