Skip to content

Commit 8695e15

Browse files
author
Raphael Balet
committed
remove - ITranslationResource logic
1 parent 1a3184c commit 8695e15

File tree

2 files changed

+5
-31
lines changed

2 files changed

+5
-31
lines changed

README.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Get the complete changelog here: https://github.com/denniske/ngx-translate-multi
1313
* [Usage](#usage)
1414

1515
## 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.
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.
1718

1819
## Installation
1920

@@ -74,21 +75,5 @@ The `MultiTranslateHttpLoader` takes a list of strings.
7475
Those strings, for example `['/assets/i18n/core/', '/assets/i18n/vendors/']`,
7576
will load your translations files for the lang "en" from : `/assets/i18n/core/en.json` and `/assets/i18n/vendors/en.json`
7677

77-
### Custom suffix
78-
**For now this loader only support the `json` format.**
79-
80-
Instead of an array of `string[]`,
81-
you may pass a list of parameters:
82-
- `prefix: string = '/assets/i18n/'`
83-
- `suffix: string = '.json'`
84-
85-
```typescript
86-
export function HttpLoaderFactory(_httpBackend: HttpBackend) {
87-
return new MultiTranslateHttpLoader(_httpBackend, [
88-
{prefix: './assets/i18n/core/', suffix: '.json'},
89-
{prefix: './assets/i18n/vendors/'}, // , "suffix: '.json'" being the default value
90-
]);
91-
}
92-
```
9378

9479
The loader will merge all translation files from the server using [deepmerge](https://github.com/KyleAMathews/deepmerge).

src/multi-http-loader.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,15 @@ import * as merge from "deepmerge";
44
import { forkJoin, Observable, of } from "rxjs";
55
import { catchError, map } from "rxjs/operators";
66

7-
export interface ITranslationResource {
8-
prefix: string;
9-
suffix?: string;
10-
}
11-
127
export class MultiTranslateHttpLoader implements TranslateLoader {
138
constructor(
149
private _handler: HttpBackend,
15-
private _resources: string[] | ITranslationResource[]
10+
private _resourcesPrefix: string[]
1611
) {}
1712

1813
public getTranslation(lang: string): Observable<any> {
19-
const requests = this._resources.map((resource) => {
20-
let path: string;
21-
22-
if (resource.prefix)
23-
path = `${resource.prefix}${lang}${resource.suffix || ".json"}`;
24-
else {
25-
path = `${resource}${lang}.json`;
26-
}
14+
const requests = this._resourcesPrefix.map((prefix) => {
15+
const path = `${prefix}${lang}.json`;
2716

2817
return new HttpClient(this._handler).get(path).pipe(
2918
catchError((res) => {

0 commit comments

Comments
 (0)