UNPKG

1.35 kBPlain TextView Raw
1import {Injectable} from "@angular/core";
2import {TranslateService} from "./translate.service";
3
4export interface MissingTranslationHandlerParams {
5 /**
6 * the key that's missing in translation files
7 */
8 key: string;
9
10 /**
11 * an instance of the service that was unable to translate the key.
12 */
13 translateService: TranslateService;
14
15 /**
16 * interpolation params that were passed along for translating the given key.
17 */
18 interpolateParams?: Object;
19}
20
21export abstract class MissingTranslationHandler {
22 /**
23 * A function that handles missing translations.
24 *
25 * @param params context for resolving a missing translation
26 * @returns a value or an observable
27 * If it returns a value, then this value is used.
28 * If it return an observable, the value returned by this observable will be used (except if the method was "instant").
29 * If it doesn't return then the key will be used as a value
30 */
31 abstract handle(params: MissingTranslationHandlerParams): any;
32}
33
34/**
35 * This handler is just a placeholder that does nothing, in case you don't need a missing translation handler at all
36 */
37@Injectable()
38export class FakeMissingTranslationHandler implements MissingTranslationHandler {
39 handle(params: MissingTranslationHandlerParams): string {
40 return params.key;
41 }
42}