NestJS module for adding translations to the application, with a pipe for translating validation errors

Overview

nestjs-translates

npm version monthly downloads

NestJS module for adding translations to the application, with a pipe for translating validation errors

Installation

npm i --save nestjs-translates class-validator-multi-lang class-transformer

Links

https://github.com/EndyKaufman/nestjs-translates - Source code

https://nestjs-translates.site15.ru/api - Demo application with nestjs-translates.

https://github.com/EndyKaufman/nestjs-translates-example - Example generated with nest cli

https://dev.to/endykaufman/nestjs-module-for-adding-translations-to-the-application-with-a-pipe-for-translating-validation-errors-2mf3 - Post in dev.to

https://twitter.com/KaufmanEndy/status/1498730314339954695?s=20&t=FwCcltTG-Vxut6M3JVPsCA - Twitter post

Usage

Update file in app.module.ts

import { HttpException, HttpStatus, Module } from '@nestjs/common';
import { ValidationError } from 'class-validator-multi-lang';
import {
  getDefaultTranslatesModuleOptions,
  TranslatesModule,
} from 'nestjs-translates';
import { join } from 'path';
import { AppController } from './app.controller';

@Module({
  imports: [
    TranslatesModule.forRoot(
      getDefaultTranslatesModuleOptions({
        localePaths: [
          join(__dirname, 'assets', 'i18n'),
          join(__dirname, 'assets', 'i18n', 'class-validator-messages'),
        ],
        locales: ['en', 'ru'],
        validationPipeOptions: {
          transform: true,
          validationError: {
            target: false,
            value: false,
          },
          transformOptions: {
            strategy: 'excludeAll',
          },
          exceptionFactory: (errors: ValidationError[]) =>
            new HttpException(errors, HttpStatus.BAD_REQUEST),
        },
      })
    ),
  ],
  controllers: [AppController],
})
export class AppModule {}

Create dictionaries ../assets/i18n/en.json

{
  "word": "word"
}

License

MIT

You might also like...

Travel Lovers - an application that allows a travel enthusiast to create an account to log past, upcoming, and bucket-list trips

Travel Lovers - an application that allows a travel enthusiast to create an account to log past, upcoming, and bucket-list trips

Travel Lovers Table of Contents Description Tools Used Installation Instructions Usage License Tests Questions Description Travel Lovers is an applica

Aug 31, 2022

A simple implementation of a task list application that can be used to add, remove, edit and check users tasks

A simple implementation of a task list application that can be used to add, remove, edit and check users tasks

"To-do list" is a tool that helps to organize daily activites. It simply lists the things which are needed to be done and allows user to mark them as complete. In this step of project, the CRUD (create, update, delete) methods are implemented. This simple web page is built using webpack and served by a webpack dev server.

Mar 28, 2022

API routes are great for APIs, but for small projects where you have to access server data or hide application logic, you can just call a server function from the client.

API routes are great for APIs, but for small projects where you have to access server data or hide application logic, you can just call a server function from the client.

Mar 6, 2022

A PHP Laravel web application that uses most of Laravel technologies to build that gym system

A PHP Laravel web application that uses most of Laravel technologies to build that gym system

A PHP Laravel web application that uses most of Laravel technologies to build that gym system.The System is based on rules. Admin, City Manager, Gym Manager. All Crud operations running using data tables.

Dec 29, 2022

This web application retrieves real live data from the SpaceX API

This web application retrieves real live data from the SpaceX API

This web application retrieves real live data from the SpaceX API. It provides commercial and scientific space travel services, by allowing users to book rockets and join selected space missions.

Aug 9, 2022

⚡️The Fullstack React Framework — built on Next.js

⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

Jan 4, 2023

CLI tool to add @ts-expect-errors to typescript type errors

suppress-ts-errors Cli tool to add comments to suppress typescript type errors. Add @ts-expect-error or @ts-ignore comments to all locations where err

Dec 8, 2022

Wrap zod validation errors in user-friendly readable messages

zod-validation-error Wrap zod validation errors in user-friendly readable messages. Features User-friendly readable messages, configurable via options

Dec 23, 2022

A pipe to browser utility

A pipe to browser utility

node-bcat Pipe to the browser utility, Very useful for log tail fun :) node-bcat features auto scrolling (with enable/disable), ansi to html coloring

Dec 30, 2022

Translations with speech synthesis in your terminal as a node package

Normit Normit is an easy way to translate stuff in your terminal. You can check out its Ruby gem version termit. Installation npm install normit -g Us

Jan 1, 2023

Mad science p2p pipe across the web using webrtc that uses your Github private/public key for authentication and a signalhub for discovery

webcat Mad science p2p pipe across the web using webrtc that uses your Github private/public key for authentication and a signalhub for discovery We a

Dec 30, 2022

A jQuery plugin for doing client-side translations in javascript.

About jQuery-i18n is a jQuery plugin for doing client-side translations in javascript. It is based heavily on javascript i18n that almost doesn't suck

May 19, 2021

Offer a translation system to your users! a plugin capable of translating your website, simply and efficiently!

Offer a translation system to your users! a plugin capable of translating your website, simply and efficiently!

TranslateForMe Offer a translation system to your users, a plugin capable of translating your website, simply and efficiently! View Demo · Report Bug

Jan 12, 2022

Help Ukrainian people find jobs in the EU, navigate visas and translating CVs.

We invite Ukrainians to Europe Since the beginning of war in Ukraine, more than 3.7 million people have left Ukraine, while an estimated seven (7) mil

Nov 12, 2022

Utilities for auto-translating the Tera DataCenter based on XML files

xml-dc-translator Requires latest version of node.js, download here: https://nodejs.org/. Utility for auto-translating the Tera DataCenter based on XM

Sep 6, 2022

Ecommerce-backend-nestjs - Ecommerce app with Nestjs + Prisma ORM + GraphQL + SQLite

ECOMMERCE BACKEND NESTJS APP Nestjs + Prisma ORM + GraphQL + SQLite USER Create Account Login Product Create Product Get Products Get Product Search P

Apr 6, 2022

Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

May 18, 2022

Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

May 3, 2022

Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

Jan 3, 2023
Releases(v1.1.0)
The perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on existing HTML.

List.js Perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on

Jonny Strömberg 10.9k Jan 1, 2023
Web app for adding EU Digital COVID Certificates to your wallet apps

Web app for adding EU Digital COVID Certificates to your wallet apps

CovidPass 1.2k Dec 31, 2022
Solid.js library adding signaling to built-in non-primitives

This package provides signaled versions of Javascript's built-in objects. Thanks to it, all theirs properties will be automatically tracked while using standard API.

Maciej Kwaśniak 40 Dec 29, 2022
This is my To-do-list project for my Javascript module at Microverse.

To do List This is a To do list project built for learning purposes. Built With HTML Bootstrap Javascript CSS HTML Webpack How to use it Clone the rep

Jonathas Tavares 4 Oct 8, 2021
TrackIt - Single Page Application that helps the user track their habits.

TrackIt - Single Page Application that helps the user track their habits. Implemented with JavaScript/React and an API server which enables the user to sign-in or sign-up in the app.

Lucas Azzolini Vieira 7 Apr 13, 2022
Insider Unlocked is an ongoing web application

Insider Unlocked is an ongoing web application we have been co-developing for the past few months which aggregates stock trading data of US senators and presents it in a digestible manner for the average retail investor

null 3 Feb 13, 2022
NodeJS application to upload an image to a S3 Bucket on AWS.

node-upload-image-to-s3-bucket NodeJS application to upload an image to a S3 Bucket on AWS. How it works: You must make a POST request to /upload-imag

Rafael Silva de Lima 6 Sep 28, 2022
💬 Real-time chat application prototype that can summarise the entire chat log

Chat summarizer ?? Disclaimer! This is a prototype and a fun project that I've been working on and it is not ready for production. It was done in a fe

null 5 Jan 22, 2022
RANDM - a dating application that helps users find matches through randomization

RANDM - The Random Dating App RANDM is a dating application that helps users find matches through randomization. While other dating apps on the market

Jennifer Cole 9 Oct 31, 2022
A simple server application that allows you to perform Wake-on-LAN remotely with a web interface

WoL Helper A simple server application that allows you to perform Wake-on-LAN remotely with a web interface. Usage Install: npm install -g wol-helper

Hongbo 5 Jul 27, 2022