MissingTranslationHandler API
This content is for v16. Switch to the latest version for up-to-date documentation.
Use the MissingTranslationHandler to customize what is happening in case
a translation is missing.
This is also influenced by the configuration value useDefaultLang.
If useDefaultLang=true, ngx-translate will first try to find the translation ID in the default language.
If this is not available, the MissingTranslationHandler is called. If useDefaultLang=false, the
handler is called immediately.
The default MissingTranslationHandler returns the ID of the translated message.
To implement your own handler, derive from MissingTranslationHandler and
pass the handler during the initialization of the TranslateModule.
An example is available from here: How to handle missing translations.
export interface MissingTranslationHandlerParams { key: string; translateService: TranslateService; interpolateParams?: Object;}
export abstract class MissingTranslationHandler { abstract handle(params: MissingTranslationHandlerParams): any;}The handle() function is called for each missing translation. It receives an object with the following values:
key- the ID of the translation that was not foundtranslateService- the currentTranslateServiceobjectinterpolateParams- an object containing all parameters passed for the translation string
Depending on the result, of the function:
- If it returns a value, then this value is used.
- If it returns an observable, the value returned by this observable will be used (except if the translation
was done using
instant()). - If the result is
undefinedthe key will be used as a value