UNPKG

@hug/ngx-g11n

Version:

Angular helpers for internationalizing and localizing your application

1 lines 3.39 kB
{"version":3,"file":"hug-ngx-g11n.mjs","sources":["../../../projects/lib/new/ngx-g11n.provider.ts","../../../projects/lib/new/ngx-g11n.module.ts","../../../projects/lib/new/hug-ngx-g11n.ts"],"sourcesContent":["import {\n type HttpEvent, type HttpHandlerFn, type HttpRequest, provideHttpClient, withInterceptors\n} from '@angular/common/http';\nimport { type EnvironmentProviders, inject, LOCALE_ID, makeEnvironmentProviders, type Provider } from '@angular/core';\nimport {\n DEFAULT_OPTIONS, G11N_OPTIONS, type G11nFeature, type G11nLocale, type G11nOptions, init, LOCALES\n} from '@hug/ngx-g11n/internal';\nimport type { Observable } from 'rxjs';\n\nexport const withInterceptor = (): G11nFeature<EnvironmentProviders> => ({\n providers: [\n provideHttpClient(withInterceptors([\n (req: HttpRequest<unknown>, next: HttpHandlerFn): Observable<HttpEvent<unknown>> => {\n const headers = req.headers.set('Accept-Language', inject(LOCALE_ID));\n return next(req.clone({ headers }));\n }\n ]))\n ]\n});\n\nexport const withLocales = (locales: Record<string, G11nLocale>): G11nFeature => ({\n providers: [\n { provide: LOCALES, useValue: locales }\n ]\n});\n\nexport const withOptions = (options: G11nOptions): G11nFeature => ({\n providers: [\n { provide: G11N_OPTIONS, useValue: { ...DEFAULT_OPTIONS, ...options } }\n ]\n});\n\nexport const provideG11n = (...features: G11nFeature<Provider | EnvironmentProviders>[]): EnvironmentProviders =>\n makeEnvironmentProviders([\n init(),\n features.map(feature => feature.providers)\n ]);\n","import { type EnvironmentProviders, type ModuleWithProviders, NgModule, type Provider } from '@angular/core';\nimport type { G11nFeature } from '@hug/ngx-g11n/internal';\n\nimport { provideG11n } from './ngx-g11n.provider';\n\n@NgModule()\nexport class G11nModule {\n public static forRoot(...features: G11nFeature<Provider | EnvironmentProviders>[]): ModuleWithProviders<G11nModule> {\n return {\n ngModule: G11nModule,\n providers: [\n provideG11n(...features)\n ]\n };\n }\n}\n","/**\n *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