@hug/ngx-g11n
Version:
Angular helpers for internationalizing and localizing your application
65 lines (60 loc) • 2.71 kB
JavaScript
import * as i0 from '@angular/core';
import { inject, LOCALE_ID, Injectable, NgModule } from '@angular/core';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { LOCALES, DEFAULT_OPTIONS, G11N_OPTIONS, init } from '@hug/ngx-g11n/internal';
export { G11nDebug, currentLanguage, setLanguage } from '@hug/ngx-g11n/internal';
class G11nInterceptor {
constructor() {
this.localeId = inject(LOCALE_ID);
}
intercept(request, next) {
const headers = request.headers.set('Accept-Language', this.localeId);
return next.handle(request.clone({ headers }));
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.7", ngImport: i0, type: G11nInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.7", ngImport: i0, type: G11nInterceptor }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.7", ngImport: i0, type: G11nInterceptor, decorators: [{
type: Injectable
}] });
const withInterceptor = () => ({
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: G11nInterceptor, multi: true, deps: [LOCALE_ID] }
]
});
const withLocales = (locales) => ({
providers: [
{ provide: LOCALES, useValue: locales }
]
});
const withOptions = (options) => ({
providers: [
{ provide: G11N_OPTIONS, useValue: { ...DEFAULT_OPTIONS, translationsPath: '/assets/translations', ...options } }
]
});
const provideG11n = (...features) => [
init(),
withOptions({ translationsPath: '/assets/translations' }).providers,
features.map(feature => feature.providers)
];
class G11nModule {
static forRoot(...features) {
return {
ngModule: G11nModule,
providers: [
provideG11n(...features)
]
};
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.7", ngImport: i0, type: G11nModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.7", ngImport: i0, type: G11nModule }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.7", ngImport: i0, type: G11nModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.7", ngImport: i0, type: G11nModule, decorators: [{
type: NgModule
}] });
/**
* Generated bundle index. Do not edit.
*/
export { G11nModule, provideG11n, withInterceptor, withLocales, withOptions };
//# sourceMappingURL=hug-ngx-g11n-legacy.mjs.map