@dumanargeyazilim/i18n-library
TypeScript icon, indicating that this package has built-in type declarations

1.3.17 • Public • Published

Xenon-Smart Xiot Backend Applications

Description

This library localize the custom error messages and validation error messages that thrown from application.

Installation and Setup

$ npm install @dumanargeyazilim/i18n-library

Additionally, ensure you have the following peer dependencies installed in your project:

$ npm install @nestjs/common class-validator  class-transformer

Usage

Getting Started

This custom i18n library makes localization for custom error messages defined in Xiot Project and makes localization for validation errors that thrown by class-validator.

How it works?

It takes language as parameter from the header for every request made and returns the translated errors in that language. It supports 3 languages :

  • tr
  • en
  • fr

4 languages will be added in future: arabic, chineese, italian and espanol

## Using I18nValidationPipe for Validation Errors

Step 1: Import the I18nErrorHandlingModule

  • Import 'I18nErrorHandlingModule' to your root module. (AppModule)

Step 2: Use the I18nValidationPipe Globally

  • Use the I18nValidationPipe globally via APP_PIPE as provider in root module.

Step 3: Define DTOs with Custom Messages

  • Must use the message property in decorators for localization support for validation errors:

  • Static Translation Key (e.g., 'validation.isEmail') @IsEmail({}, { message: 'validation.isEmail' })

  • Dynamic Constraint Values (e.g., 'validation.length{3,15}') @Length(3, 8, { message: 'validation.length{3,8}' })

## Using Custom Error Messages for Application Add CustomErrorMessageService from the library to your service as readonly. You can call the defined error methods for spesific error and it returns localizaed error message with it's status code.

  • this.i18nErrorService.getWrongPasswordOrEmailMessage();

Readme

Keywords

none

Package Sidebar

Install

npm i @dumanargeyazilim/i18n-library

Weekly Downloads

624

Version

1.3.17

License

ISC

Unpacked Size

219 kB

Total Files

81

Last publish

Collaborators

  • zeynep-goksoy
  • meryem_gul
  • dumanargebilisim