- run
npm i backend-error-translations
- import
ErrorTranslationsModule
to your@NgModule
imports[] this should import it as follow:import { ErrorTranslationsModule } from "error-translations";
- to use
translateError
pipe:<p [innerHTML]="errorKey | translateError:locale"></p>"
make sure thatlocale
is a validLocale
value that you can import from your component as well should be imported from:import { Locale } from "error-translations";
-
errorKey
should be Uppercase, dot separated key path like'INVALID.CREDENTIALS_PROVIDED'
, you can find locales files in langs/.json - to use
humanize()
function: injectErrorTranslationsService
also fromerror-translations
and use the function as follow:.humanize(errorKey: string, locale: Locale)
with the specified types
- add a json file in projects/error-translations/src/lib/translations like:
fr.json
- re-run the script
npm run build:lib
-
npm run publish
it builds the lib and publish its dist folder