UNPKG

@ngx-translate/http-loader

Version:

http loader for dynamically loading translation files for @ngx-translate/core

70 lines • 3.15 kB
import * as i0 from "@angular/core"; import { InjectionToken, Provider } from "@angular/core"; import { TranslateLoader, TranslationObject } from "@ngx-translate/core"; import { Observable } from "rxjs"; export interface TranslateHttpLoaderConfig { prefix?: string; suffix?: string; enforceLoading: boolean; useHttpBackend: boolean; /** * If true, a failed HTTP fetch (e.g. 404) propagates the error and fails * the whole language load (v17 behaviour). If false (default), each * resource failure is caught and replaced with an empty object, with a * `console.warn` per failure; remaining resources still contribute their * keys. Set this to `true` if you want deploys to fail loudly on a * missing translation file rather than serve partial translations. * Must be `true` for the translation service's `retry` option to retry HTTP failures. */ failOnError?: boolean; /** * Flatten each resource's nested objects into dotted keys before merging (default false). * Later resources then override equivalent flat or nested keys. Arrays and null stay intact. * Within one resource, the last encountered equivalent key wins. */ flatten?: boolean; /** * Reports each failed resource attempt instead of the loader's default warning. * Called in both failure modes; failOnError still controls error propagation. * Exceptions from this callback are warned about without replacing the loading error. * Does not suppress separate TranslateService warnings after a terminal loading failure. */ onLoadError?: (failure: TranslateHttpLoaderError) => void; } export interface TranslateHttpLoaderResource { prefix: string; suffix?: string; } export interface TranslateHttpLoaderError { lang: string; resource: string | TranslateHttpLoaderResource; /** The request URL, or undefined if language encoding failed before URL construction. */ url: string | undefined; error: unknown; } export interface TranslateMultiHttpLoaderConfig { resources: (string | TranslateHttpLoaderResource)[]; enforceLoading: boolean; useHttpBackend: boolean; /** See {@link TranslateHttpLoaderConfig.failOnError}. */ failOnError?: boolean; /** See {@link TranslateHttpLoaderConfig.flatten}. */ flatten?: boolean; /** See {@link TranslateHttpLoaderConfig.onLoadError}. */ onLoadError?: (failure: TranslateHttpLoaderError) => void; } export declare const TRANSLATE_HTTP_LOADER_CONFIG: InjectionToken<Partial<TranslateMultiHttpLoaderConfig>>; export declare class TranslateHttpLoader implements TranslateLoader { private http; private config; constructor(); /** * Gets the translations from the server */ getTranslation(lang: string): Observable<TranslationObject>; private reportError; static ɵfac: i0.ɵɵFactoryDeclaration<TranslateHttpLoader, never>; static ɵprov: i0.ɵɵInjectableDeclaration<any>; } export declare function provideTranslateHttpLoader(config?: Partial<TranslateHttpLoaderConfig | TranslateMultiHttpLoaderConfig>): Provider[]; export declare function provideTranslateMultiHttpLoader(config?: Partial<TranslateMultiHttpLoaderConfig>): Provider[];