diff --git a/src/i18n.context.ts b/src/i18n.context.ts index aa205ade..05c3afca 100644 --- a/src/i18n.context.ts +++ b/src/i18n.context.ts @@ -16,7 +16,11 @@ export class I18nContext> return this; } - constructor(readonly lang: string, readonly service: I18nService, readonly i18nOptions: I18nOptions,) {} + constructor( + readonly lang: string, + readonly service: I18nService, + readonly i18nOptions: I18nOptions, + ) {} public translate

= any, R = PathValue>( key: P, @@ -64,7 +68,7 @@ export class I18nContext> const i18n = this.storage.getStore() as I18nContext | undefined; if (!i18n && !!context) { - return getContextObject(i18n.i18nOptions,context)?.i18nContext; + return getContextObject(i18n.i18nOptions, context)?.i18nContext; } return i18n; diff --git a/src/interceptors/i18n-language.interceptor.ts b/src/interceptors/i18n-language.interceptor.ts index b8186839..f2124c40 100644 --- a/src/interceptors/i18n-language.interceptor.ts +++ b/src/interceptors/i18n-language.interceptor.ts @@ -37,7 +37,7 @@ export class I18nLanguageInterceptor implements NestInterceptor { const i18nContext = I18nContext.current(); let language = null; - const ctx = getContextObject(this.i18nOptions,context); + const ctx = getContextObject(this.i18nOptions, context); // Skip interceptor if language is already resolved (in case of http middleware) or when ctx is undefined (unsupported context) if (ctx === undefined || !!ctx.i18nLang) { @@ -68,7 +68,11 @@ export class I18nLanguageInterceptor implements NestInterceptor { } if (!i18nContext) { - ctx.i18nContext = new I18nContext(ctx.i18nLang, this.i18nService, this.i18nOptions); + ctx.i18nContext = new I18nContext( + ctx.i18nLang, + this.i18nService, + this.i18nOptions, + ); if (!this.i18nOptions.skipAsyncHook) { return new Observable((observer) => { diff --git a/src/middlewares/i18n.middleware.ts b/src/middlewares/i18n.middleware.ts index de3449fe..f50ac79a 100644 --- a/src/middlewares/i18n.middleware.ts +++ b/src/middlewares/i18n.middleware.ts @@ -66,7 +66,11 @@ export class I18nMiddleware implements NestMiddleware { req.app.locals.i18nLang = req.i18nLang; } - req.i18nContext = new I18nContext(req.i18nLang, this.i18nService, this.i18nOptions); + req.i18nContext = new I18nContext( + req.i18nLang, + this.i18nService, + this.i18nOptions, + ); if (this.i18nOptions.skipAsyncHook) { next(); diff --git a/src/services/i18n.service.ts b/src/services/i18n.service.ts index 56b5071f..0ed23c7e 100644 --- a/src/services/i18n.service.ts +++ b/src/services/i18n.service.ts @@ -113,7 +113,6 @@ export class I18nService> }" in "${lang}" does not exist.`; if (lang !== this.i18nOptions.fallbackLanguage || !!defaultValue) { if (this.i18nOptions.logging && this.i18nOptions.throwOnMissingKey) { - this.logger.error(translationKeyMissing); throw new I18nError(translationKeyMissing); } @@ -127,7 +126,6 @@ export class I18nService> }); } } - } return (translation ?? key) as unknown as IfAnyOrNever; diff --git a/src/utils/context.ts b/src/utils/context.ts index 45f6075b..412a7f4a 100644 --- a/src/utils/context.ts +++ b/src/utils/context.ts @@ -19,7 +19,7 @@ export function getContextObject( case 'rmq': return context.getArgs()[1]; default: - if(i18nOptions.logging){ + if (i18nOptions.logging) { logger.warn(`context type: ${contextType} not supported`); } } diff --git a/tests/app/examples/example.functions.ts b/tests/app/examples/example.functions.ts index 5d20f205..bd8467a1 100644 --- a/tests/app/examples/example.functions.ts +++ b/tests/app/examples/example.functions.ts @@ -1,7 +1,6 @@ import { ArgumentsHost, ValidationError } from '@nestjs/common'; import { mapChildrenToValidationErrors } from '../../../src/utils/format'; -import {I18nValidationException} from "../../../src"; - +import { I18nValidationException } from '../../../src'; export const exampleErrorFormatter = (errors: ValidationError[]): object => { const errorMessages = {}; @@ -18,12 +17,15 @@ export const exampleErrorFormatter = (errors: ValidationError[]): object => { return errorMessages; }; - -export const exampleResponseBodyFormatter = (host: ArgumentsHost, exc: I18nValidationException, formattedErrors: object) => { +export const exampleResponseBodyFormatter = ( + host: ArgumentsHost, + exc: I18nValidationException, + formattedErrors: object, +) => { return { type: 'static', status: exc.getStatus(), message: exc.getResponse(), data: formattedErrors, }; -} +}; diff --git a/tests/i18n-dto.e2e.spec.ts b/tests/i18n-dto.e2e.spec.ts index aaed8a23..9df15bd9 100644 --- a/tests/i18n-dto.e2e.spec.ts +++ b/tests/i18n-dto.e2e.spec.ts @@ -256,7 +256,6 @@ describe('i18n module e2e dto', () => { }); }); - it(`should translate validation messages if a custom response body formatter specified`, async () => { await request(app.getHttpServer()) .post('/hello/validation-custom-response-body-formatter') @@ -345,7 +344,6 @@ describe('i18n module e2e dto', () => { }); }); - it(`should translate validation messages with detailed error`, async () => { await request(app.getHttpServer()) .post('/hello/validation') diff --git a/tests/i18n-ejs.e2e.spec.ts b/tests/i18n-ejs.e2e.spec.ts index fe236e25..75f87462 100644 --- a/tests/i18n-ejs.e2e.spec.ts +++ b/tests/i18n-ejs.e2e.spec.ts @@ -23,7 +23,7 @@ import { Global, Module } from '@nestjs/common'; ], exports: ['OPTIONS'], }) -export class OptionsModule { } +export class OptionsModule {} describe('i18n module e2e ejs', () => { let app: NestExpressApplication; diff --git a/tests/i18n-express.e2e.spec.ts b/tests/i18n-express.e2e.spec.ts index 6d95c451..779a7fb7 100644 --- a/tests/i18n-express.e2e.spec.ts +++ b/tests/i18n-express.e2e.spec.ts @@ -633,7 +633,7 @@ describe('i18n module e2e express', () => { it(`/GET hello/no-lang-for-service should return translation when providing x-custom-lang`, () => { return request(app.getHttpServer()) - .get('/hello/no-lang-for-service') + .get('/hello/no-lang-for-service') .set('x-custom-lang', 'nl') .expect(200) .expect('Hallo'); @@ -671,7 +671,7 @@ describe('i18n module e2e express', () => { it(`/GET hello/short/no-lang-for-service should return translation when providing x-custom-lang`, () => { return request(app.getHttpServer()) - .get('/hello/short/no-lang-for-service') + .get('/hello/short/no-lang-for-service') .set('x-custom-lang', 'nl') .expect(200) .expect('Hallo'); diff --git a/tests/i18n-fastify.e2e.spec.ts b/tests/i18n-fastify.e2e.spec.ts index ff8e53d7..6d13aef3 100644 --- a/tests/i18n-fastify.e2e.spec.ts +++ b/tests/i18n-fastify.e2e.spec.ts @@ -637,7 +637,7 @@ describe('i18n module e2e fastify', () => { it(`/GET hello/no-lang-for-service should return translation when providing x-custom-lang`, () => { return request(app.getHttpServer()) - .get('/hello/no-lang-for-service') + .get('/hello/no-lang-for-service') .set('x-custom-lang', 'nl') .expect(200) .expect('Hallo'); @@ -675,7 +675,7 @@ describe('i18n module e2e fastify', () => { it(`/GET hello/short/no-lang-for-service should return translation when providing x-custom-lang`, () => { return request(app.getHttpServer()) - .get('/hello/short/no-lang-for-service') + .get('/hello/short/no-lang-for-service') .set('x-custom-lang', 'nl') .expect(200) .expect('Hallo'); @@ -696,7 +696,7 @@ describe('i18n module e2e fastify', () => { .expect(200) .expect('Hallo'); }); - + it('/POST cats with age 2 should error', async () => { await request(app.getHttpServer()) .post('/cats')