Skip to content

Commit 1a3184c

Browse files
author
Raphael Balet
committed
enable - string[] | update - readme
1 parent 919d5c7 commit 1a3184c

File tree

6 files changed

+165
-10725
lines changed

6 files changed

+165
-10725
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: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
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+
1418
## Installation
1519

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

2428
Choose the version corresponding to your Angular version:
2529

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+
30+
| Angular | @ngx-translate/core | ngx-translate-multi-http-loader |
31+
| ------- | ------------------- | ------------------------------- |
32+
| 14 | 14.x+ | 8.x+ |
33+
| 13 | 14.x+ | 7.x+ |
34+
| 6 | 10.x+ | 1.x+ |
3135

3236
## Usage
33-
#### 1. Setup the `TranslateModule` to use the `MultiTranslateHttpLoader`:
37+
_The `MultiTranslateHttpLoader` uses HttpBackend to load translations, therefore :_
38+
1. Create and export a new `HttpLoaderFactory` function
39+
2. Import the `HttpClientModule` from `@angular/common/http`
40+
3. Setup the `TranslateModule` to use the `MultiTranslateHttpLoader`
3441

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
42+
```typescript
3943
import {NgModule} from '@angular/core';
4044
import {BrowserModule} from '@angular/platform-browser';
41-
import {HttpClientModule, HttpClient} from '@angular/common/http';
45+
import {HttpClientModule, HttpBackend} from '@angular/common/http';
4246
import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
43-
import {MultiTranslateHttpLoader} from "ngx-translate-multi-http-loader";
44-
import {AppComponent} from "./app";
47+
import {MultiTranslateHttpLoader} from 'ngx-translate-multi-http-loader';
48+
import {AppComponent} from './app';
4549

4650
// 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-
]);
51+
export function HttpLoaderFactory(_httpBackend: HttpBackend) {
52+
return new MultiTranslateHttpLoader(_httpBackend, ['/assets/i18n/core/', '/assets/i18n/vendors/']);
5253
}
5354

5455
@NgModule({
@@ -59,7 +60,7 @@ export function HttpLoaderFactory(http: HttpClient) {
5960
loader: {
6061
provide: TranslateLoader,
6162
useFactory: HttpLoaderFactory,
62-
deps: [HttpClient]
63+
deps: [HttpBackend]
6364
}
6465
})
6566
],
@@ -68,23 +69,26 @@ export function HttpLoaderFactory(http: HttpClient) {
6869
export class AppModule { }
6970
```
7071

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"
72+
The `MultiTranslateHttpLoader` takes a list of strings.
7473

75-
By using those default parameters, it will load your translations files for the lang "en" from: `/assets/translate/en.json`.
74+
Those strings, for example `['/assets/i18n/core/', '/assets/i18n/vendors/']`,
75+
will load your translations files for the lang "en" from : `/assets/i18n/core/en.json` and `/assets/i18n/vendors/en.json`
7676

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:
77+
### Custom suffix
78+
**For now this loader only support the `json` format.**
7879

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"},
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
8490
]);
8591
}
8692
```
8793

88-
For now this loader only support the json format.
89-
9094
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)