Gathering detailed insights and metrics for itopplus-ngx-translate-multi-http-loader
Gathering detailed insights and metrics for itopplus-ngx-translate-multi-http-loader
Gathering detailed insights and metrics for itopplus-ngx-translate-multi-http-loader
Gathering detailed insights and metrics for itopplus-ngx-translate-multi-http-loader
A loader for ngx-translate that loads translations with http calls
npm install itopplus-ngx-translate-multi-http-loader
Typescript
Module System
Node Version
NPM Version
62.4
Supply Chain
96
Quality
75.2
Maintenance
100
Vulnerability
98.9
License
TypeScript (89.93%)
Shell (5.78%)
JavaScript (4.29%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
478
Last Day
1
Last Week
5
Last Month
10
Last Year
233
MIT License
78 Stars
147 Commits
16 Forks
3 Watchers
4 Branches
2 Contributors
Updated on Jan 20, 2025
Minified
Minified + Gzipped
Latest Version
16.0.0
Package Id
itopplus-ngx-translate-multi-http-loader@16.0.0
Unpacked Size
15.41 kB
Size
5.37 kB
File Count
10
NPM Version
9.6.4
Node Version
20.1.0
Published on
May 30, 2023
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
66.7%
5
Compared to previous week
Last Month
-44.4%
10
Compared to previous month
Last Year
-4.9%
233
Compared to previous year
1
5
A loader for ngx-translate that loads translations using http.
Angular 14 example: https://stackblitz.com/edit/ngx-translate-multi-http-loader-sample-2clau3?file=src/app/app.module.ts
Angular 6 example: https://stackblitz.com/edit/ngx-translate-multi-http-loader-sample
Get the complete changelog here: https://github.com/rbalet/ngx-translate-multi-http-loader/releases
httpBackend
instead of the httpClient
, to avoid being delayed by interceptor, which was creating errors while loading.string[]
so prefix
& suffix
aren't needed anymore and .json
gonna be the default suffix.We assume that you already installed ngx-translate.
Now you need to install the npm module for MultiTranslateHttpLoader
:
1npm install ngx-translate-multi-http-loader --save
Choose the version corresponding to your Angular version:
Angular | @ngx-translate/core | ngx-translate-multi-http-loader |
---|---|---|
14 | 14.x+ | 8.x+ |
13 | 14.x+ | 7.x+ |
6 | 10.x+ | 1.x+ |
The MultiTranslateHttpLoader
uses HttpBackend to load translations, therefore :
HttpLoaderFactory
functionHttpClientModule
from @angular/common/http
TranslateModule
to use the MultiTranslateHttpLoader
1import {NgModule} from '@angular/core'; 2import {BrowserModule} from '@angular/platform-browser'; 3import {HttpClientModule, HttpBackend} from '@angular/common/http'; 4import {TranslateModule, TranslateLoader} from '@ngx-translate/core'; 5import {MultiTranslateHttpLoader} from 'ngx-translate-multi-http-loader'; 6import {AppComponent} from './app'; 7 8// AoT requires an exported function for factories 9export function HttpLoaderFactory(_httpBackend: HttpBackend) { 10 return new MultiTranslateHttpLoader(_httpBackend, ['/assets/i18n/core/', '/assets/i18n/vendors/']); 11} 12 13@NgModule({ 14 imports: [ 15 BrowserModule, 16 HttpClientModule, 17 TranslateModule.forRoot({ 18 loader: { 19 provide: TranslateLoader, 20 useFactory: HttpLoaderFactory, 21 deps: [HttpBackend] 22 } 23 }) 24 ], 25 bootstrap: [AppComponent] 26}) 27export class AppModule { }
The MultiTranslateHttpLoader
takes a list of string[]
or ITranslationResource[]
.
For example ['/assets/i18n/core/', '/assets/i18n/vendors/']
,
will load your translations files for the lang "en" from : /assets/i18n/core/en.json
and /assets/i18n/vendors/en.json
For now this loader only support the json
format.
Instead of an array of string[]
,
you may pass a list of parameters:
prefix: string = '/assets/i18n/'
suffix: string = '.json'
optional: boolean = true
1export function HttpLoaderFactory(_httpBackend: HttpBackend) { 2 return new MultiTranslateHttpLoader(_httpBackend, [ 3 {prefix: './assets/i18n/core/', suffix: '.json'}, 4 {prefix: './assets/i18n/vendors/'}, // , "suffix: '.json'" being the default value 5 {prefix: './assets/i18n/non-existent/', optional: true}, // Wont create any log 6 ]); 7}
The loader will merge all translation files from the server using deepmerge-ts.
No vulnerabilities found.
No security vulnerabilities found.