Skip to content

Commit 4923daa

Browse files
authored
Merge pull request #18 from rbalet/patch-2
use HttpBackend instead of HttpClient
2 parents 7879ef5 + 8695e15 commit 4923daa

File tree

6 files changed

+147
-10733
lines changed

6 files changed

+147
-10733
lines changed

notes.txt renamed to CONTRIBUTING.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
2-
3-
41
npm i
52
npx tsc && npm publish --access=public
63

7-
8-
9-
10-
11-
12-
134
npx nx serve example --port 4300
145
npx nx serve demo --port 4301
156

README.md

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# @ngx-translate/multi-http-loader [![npm version](https://badge.fury.io/js/ngx-translate-multi-http-loader.svg)](https://badge.fury.io/js/ngx-translate-multi-http-loader)
22

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

5-
Angular 6 example: https://stackblitz.com/edit/ngx-translate-multi-http-loader-sample
4+
A loader for [ngx-translate](https://github.com/ngx-translate/core) that loads translations using http.
65

76
Angular 13 example: https://github.com/denniske/ngx-translate-multi-http-loader-demo
87

8+
Angular 6 example: https://stackblitz.com/edit/ngx-translate-multi-http-loader-sample
9+
910
Get the complete changelog here: https://github.com/denniske/ngx-translate-multi-http-loader/releases
1011

1112
* [Installation](#installation)
1213
* [Usage](#usage)
1314

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+
1419
## Installation
1520

1621
We assume that you already installed [ngx-translate](https://github.com/ngx-translate/core).
@@ -23,32 +28,29 @@ npm install ngx-translate-multi-http-loader --save
2328

2429
Choose the version corresponding to your Angular version:
2530

26-
Angular | @ngx-translate/core | ngx-translate-multi-http-loader
27-
----------- |---------------------| --------------------------
28-
14 | 14.x+ | 8.x+
29-
13 | 14.x+ | 7.x+
30-
6 | 10.x+ | 1.x+
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+ |
3136

3237
## Usage
33-
#### 1. Setup the `TranslateModule` to use the `MultiTranslateHttpLoader`:
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`
3442

35-
The `MultiTranslateHttpLoader` uses HttpClient to load translations, which means that you have to import the HttpClientModule from `@angular/common/http` before the `TranslateModule`:
36-
37-
38-
```ts
43+
```typescript
3944
import {NgModule} from '@angular/core';
4045
import {BrowserModule} from '@angular/platform-browser';
41-
import {HttpClientModule, HttpClient} from '@angular/common/http';
46+
import {HttpClientModule, HttpBackend} from '@angular/common/http';
4247
import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
43-
import {MultiTranslateHttpLoader} from "ngx-translate-multi-http-loader";
44-
import {AppComponent} from "./app";
48+
import {MultiTranslateHttpLoader} from 'ngx-translate-multi-http-loader';
49+
import {AppComponent} from './app';
4550

4651
// AoT requires an exported function for factories
47-
export function HttpLoaderFactory(http: HttpClient) {
48-
return new MultiTranslateHttpLoader(http, [
49-
{prefix: "./assets/translate/core/", suffix: ".json"},
50-
{prefix: "./assets/translate/shared/", suffix: ".json"},
51-
]);
52+
export function HttpLoaderFactory(_httpBackend: HttpBackend) {
53+
return new MultiTranslateHttpLoader(_httpBackend, ['/assets/i18n/core/', '/assets/i18n/vendors/']);
5254
}
5355

5456
@NgModule({
@@ -59,7 +61,7 @@ export function HttpLoaderFactory(http: HttpClient) {
5961
loader: {
6062
provide: TranslateLoader,
6163
useFactory: HttpLoaderFactory,
62-
deps: [HttpClient]
64+
deps: [HttpBackend]
6365
}
6466
})
6567
],
@@ -68,23 +70,10 @@ export function HttpLoaderFactory(http: HttpClient) {
6870
export class AppModule { }
6971
```
7072

71-
The `MultiTranslateHttpLoader` takes a list of translation file configurations. Each configuration has two optional parameters:
72-
- prefix: string = "/assets/translate/"
73-
- suffix: string = ".json"
74-
75-
By using those default parameters, it will load your translations files for the lang "en" from: `/assets/translate/en.json`.
73+
The `MultiTranslateHttpLoader` takes a list of strings.
7674

77-
You can change those in the `HttpLoaderFactory` method that we just defined. For example if you want to load the "en" translations from `/assets/translate/core/en.json` and `/assets/translate/shared/en.json` you would use:
78-
79-
```ts
80-
export function HttpLoaderFactory(http: HttpClient) {
81-
return new MultiTranslateHttpLoader(http, [
82-
{prefix: "./assets/translate/core/", suffix: ".json"},
83-
{prefix: "./assets/translate/shared/", suffix: ".json"},
84-
]);
85-
}
86-
```
75+
Those strings, for example `['/assets/i18n/core/', '/assets/i18n/vendors/']`,
76+
will load your translations files for the lang "en" from : `/assets/i18n/core/en.json` and `/assets/i18n/vendors/en.json`
8777

88-
For now this loader only support the json format.
8978

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

package-lock.json

Lines changed: 52 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
{
22
"name": "ngx-translate-multi-http-loader",
3-
"version": "8.0.1",
3+
"version": "9.0.0",
44
"license": "MIT",
55
"maintainers": [
66
"denniske.npm@gmail.com"
77
],
8-
"peerDependencies": {
9-
"@angular/common": "^14.0.0",
10-
"@angular/core": "^14.0.0"
8+
"scripts": {
9+
"serve:example": "npx nx serve example --port 4300",
10+
"serve:demo": "npx nx serve demo --port 4301"
1111
},
12-
"dependencies": {
12+
"peerDependencies": {
1313
"@angular/common": ">=14.0.0",
1414
"@angular/core": ">=14.0.0",
1515
"@ngx-translate/core": ">=14.0.0",
1616
"deepmerge": ">=4.2.2",
17-
"rxjs": ">=7.4.0",
18-
"tslib": ">=2.0.0"
17+
"rxjs": "7.5.7"
18+
},
19+
"dependencies": {
20+
"tslib": "2.4.0"
1921
},
2022
"devDependencies": {
21-
"typescript": ">=4.4.3"
23+
"typescript": "4.8.4"
2224
},
2325
"main": "dist/multi-http-loader.js",
2426
"types": "dist/multi-http-loader.d.ts",

0 commit comments

Comments
 (0)