0.0.8 • Published 2 years ago
backend-error-translations v0.0.8
to use error-translations library:
- run
npm i backend-error-translations - import
ErrorTranslationsModuleto your@NgModuleimports[] this should import it as follow:import { ErrorTranslationsModule } from "error-translations"; - to use
translateErrorpipe:<p [innerHTML]="errorKey | translateError:locale"></p>"make sure thatlocaleis a validLocalevalue that you can import from your component as well should be imported from:import { Locale } from "error-translations"; errorKeyshould be Uppercase, dot separated key path like'INVALID.CREDENTIALS_PROVIDED', you can find locales files in langs/.json- to use
humanize()function: injectErrorTranslationsServicealso fromerror-translationsand use the function as follow:.humanize(errorKey: string, locale: Locale)with the specified types
to add language support
- add a json file in projects/error-translations/src/lib/translations like:
fr.json - re-run the script
npm run build:lib
to publish the library
npm run publishit builds the lib and publish its dist folder