MissingTranslationHandler API
This content is for v15. 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.
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 currentTranslateService
objectinterpolateParams
- 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
undefined
the key will be used as a value