Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nestjs-i18n

Package Overview
Dependencies
Maintainers
2
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-i18n - npm Package Compare versions

Comparing version 10.4.5 to 11.0.0-beta

dist/cli.d.ts

4

dist/filters/i18n-validation-exception.filter.d.ts

@@ -8,7 +8,7 @@ import { ArgumentsHost, ExceptionFilter, ValidationError } from '@nestjs/common';

catch(exception: I18nValidationException, host: ArgumentsHost): I18nValidationException;
private isWithErrorFormatter;
protected buildResponseBody(host: ArgumentsHost, exc: I18nValidationException, errors: string[] | I18nValidationError[] | object): Record<string, unknown>;
protected normalizeValidationErrors(validationErrors: ValidationError[]): string[] | I18nValidationError[] | object;
protected flattenValidationErrors(validationErrors: ValidationError[]): string[];
protected buildResponseBody(host: ArgumentsHost, exc: I18nValidationException, errors: string[] | I18nValidationError[] | object): Record<string, unknown>;
private isWithErrorFormatter;
}
export {};

@@ -11,6 +11,9 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.I18nValidationExceptionFilter = void 0;
const common_1 = require("@nestjs/common");
const iterare_1 = require("iterare");
const iterare_1 = __importDefault(require("iterare"));
const i18n_context_1 = require("../i18n.context");

@@ -44,4 +47,15 @@ const interfaces_1 = require("../interfaces");

}
isWithErrorFormatter(options) {
return 'errorFormatter' in options;
buildResponseBody(host, exc, errors) {
if ('responseBodyFormatter' in this.options) {
return this.options.responseBodyFormatter(host, exc, errors);
}
else {
return {
statusCode: this.options.errorHttpStatusCode === undefined
? exc.getStatus()
: this.options.errorHttpStatusCode,
message: exc.getResponse(),
errors,
};
}
}

@@ -66,15 +80,4 @@ normalizeValidationErrors(validationErrors) {

}
buildResponseBody(host, exc, errors) {
if ('responseBodyFormatter' in this.options) {
return this.options.responseBodyFormatter(host, exc, errors);
}
else {
return {
statusCode: this.options.errorHttpStatusCode === undefined
? exc.getStatus()
: this.options.errorHttpStatusCode,
message: exc.getResponse(),
errors,
};
}
isWithErrorFormatter(options) {
return 'errorFormatter' in options;
}

@@ -81,0 +84,0 @@ };

@@ -6,4 +6,2 @@ export declare const I18N_OPTIONS = "I18nOptions";

export declare const I18N_RESOLVERS = "I18nResolvers";
export declare const I18N_LOADER_OPTIONS = "I18nLoaderOptions";
export declare const I18N_LANGUAGES_SUBJECT = "I18nLanguagesSubject";
export declare const I18N_TRANSLATIONS_SUBJECT = "I18nTranslationsSubject";
export declare const I18N_LOADERS = "I18N_LOADERS";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.I18N_TRANSLATIONS_SUBJECT = exports.I18N_LANGUAGES_SUBJECT = exports.I18N_LOADER_OPTIONS = exports.I18N_RESOLVERS = exports.I18N_RESOLVER_OPTIONS = exports.I18N_LANGUAGES = exports.I18N_TRANSLATIONS = exports.I18N_OPTIONS = void 0;
exports.I18N_LOADERS = exports.I18N_RESOLVERS = exports.I18N_RESOLVER_OPTIONS = exports.I18N_LANGUAGES = exports.I18N_TRANSLATIONS = exports.I18N_OPTIONS = void 0;
exports.I18N_OPTIONS = 'I18nOptions';

@@ -9,5 +9,3 @@ exports.I18N_TRANSLATIONS = 'I18nTranslations';

exports.I18N_RESOLVERS = 'I18nResolvers';
exports.I18N_LOADER_OPTIONS = 'I18nLoaderOptions';
exports.I18N_LANGUAGES_SUBJECT = 'I18nLanguagesSubject';
exports.I18N_TRANSLATIONS_SUBJECT = 'I18nTranslationsSubject';
exports.I18N_LOADERS = 'I18N_LOADERS';
//# sourceMappingURL=i18n.constants.js.map

@@ -11,10 +11,10 @@ import { ArgumentsHost } from '@nestjs/common';

readonly id: number;
constructor(lang: string, service: I18nService<K>);
get i18n(): I18nContext<K> | undefined;
constructor(lang: string, service: I18nService<K>);
static create(ctx: I18nContext, next: (...args: any[]) => void): void;
static createAsync<T>(ctx: I18nContext, next: (...args: any[]) => Promise<T>): Promise<T>;
static current<K = Record<string, unknown>>(context?: ArgumentsHost): I18nContext<K> | undefined;
translate<P extends Path<K> = any, R = PathValue<K, P>>(key: P, options?: TranslateOptions): import("./types").IfAnyOrNever<R, string, R>;
t<P extends Path<K> = any, R = PathValue<K, P>>(key: P, options?: TranslateOptions): import("./types").IfAnyOrNever<R, string, R>;
validate(value: any, options?: TranslateOptions): Promise<I18nValidationError[]>;
static create(ctx: I18nContext, next: (...args: any[]) => void): void;
static createAsync<T>(ctx: I18nContext, next: (...args: any[]) => Promise<T>): Promise<T>;
static current<K = Record<string, unknown>>(context?: ArgumentsHost): I18nContext<K> | undefined;
}

@@ -7,5 +7,2 @@ "use strict";

class I18nContext {
get i18n() {
return this;
}
constructor(lang, service) {

@@ -16,2 +13,18 @@ this.lang = lang;

}
get i18n() {
return this;
}
static create(ctx, next) {
this.storage.run(ctx, next);
}
static async createAsync(ctx, next) {
return this.storage.run(ctx, next);
}
static current(context) {
const i18n = this.storage.getStore();
if (!i18n && !!context) {
return (0, utils_1.getContextObject)(context)?.i18nContext;
}
return i18n;
}
translate(key, options) {

@@ -34,15 +47,2 @@ options = {

}
static create(ctx, next) {
this.storage.run(ctx, next);
}
static async createAsync(ctx, next) {
return this.storage.run(ctx, next);
}
static current(context) {
const i18n = this.storage.getStore();
if (!i18n && !!context) {
return (0, utils_1.getContextObject)(context)?.i18nContext;
}
return i18n;
}
}

@@ -49,0 +49,0 @@ exports.I18nContext = I18nContext;

@@ -1,23 +0,15 @@

import { DynamicModule, Logger, MiddlewareConsumer, OnModuleDestroy } from '@nestjs/common';
import { DynamicModule, Logger, MiddlewareConsumer, NestModule, OnModuleInit } from '@nestjs/common';
import { I18nService } from './services/i18n.service';
import { I18nAsyncOptions, I18nOptions } from './interfaces/i18n-options.interface';
import { OnModuleInit, NestModule } from '@nestjs/common';
import { HttpAdapterHost } from '@nestjs/core';
import { I18nTranslation } from './interfaces/i18n-translation.interface';
import { Observable } from 'rxjs';
export declare const logger: Logger;
export declare class I18nModule implements OnModuleInit, OnModuleDestroy, NestModule {
export declare class I18nModule implements OnModuleInit, NestModule {
private readonly i18n;
private translations;
private readonly i18nOptions;
private adapter;
private unsubscribe;
constructor(i18n: I18nService, translations: Observable<I18nTranslation>, i18nOptions: I18nOptions, adapter: HttpAdapterHost);
onModuleInit(): Promise<void>;
onModuleDestroy(): void;
configure(consumer: MiddlewareConsumer): void;
constructor(i18n: I18nService, i18nOptions: I18nOptions, adapter: HttpAdapterHost);
static forRoot(options: I18nOptions): DynamicModule;
static forRootAsync(options: I18nAsyncOptions): DynamicModule;
private static createAsyncLoadersProvider;
private static createAsyncOptionsProvider;
private static createAsyncLoaderOptionsProvider;
private static createAsyncTranslationProvider;

@@ -27,2 +19,4 @@ private static createAsyncLanguagesProvider;

private static createResolverProviders;
onModuleInit(): Promise<void>;
configure(consumer: MiddlewareConsumer): void;
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

@@ -8,2 +24,9 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __metadata = (this && this.__metadata) || function (k, v) {

@@ -15,2 +38,5 @@ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var I18nModule_1;

@@ -24,97 +50,22 @@ Object.defineProperty(exports, "__esModule", { value: true });

const core_1 = require("@nestjs/core");
const decorators_1 = require("./decorators");
const utils_1 = require("./utils");
const i18n_loader_1 = require("./loaders/i18n.loader");
const rxjs_1 = require("rxjs");
const format = require("string-format");
const loaders_1 = require("./loaders");
const i18n_resolver_options_decorator_1 = require("./decorators/i18n-resolver-options.decorator");
const util_1 = require("./utils/util");
const string_format_1 = __importDefault(require("string-format"));
const i18n_middleware_1 = require("./middlewares/i18n.middleware");
const fs = require("fs");
const path = require("path");
const loaders_utils_1 = require("./utils/loaders-utils");
exports.logger = new common_1.Logger('I18nService');
const defaultOptions = {
resolvers: [],
formatter: format,
formatter: string_format_1.default,
logging: true,
throwOnMissingKey: false,
loader: loaders_1.I18nJsonLoader,
};
let I18nModule = I18nModule_1 = class I18nModule {
constructor(i18n, translations, i18nOptions, adapter) {
constructor(i18n, i18nOptions, adapter) {
this.i18n = i18n;
this.translations = translations;
this.i18nOptions = i18nOptions;
this.adapter = adapter;
this.unsubscribe = new rxjs_1.Subject();
}
async onModuleInit() {
await this.i18n.refresh();
if (this.i18nOptions.viewEngine == 'hbs') {
try {
const hbs = await Promise.resolve().then(() => require('hbs'));
hbs.registerHelper('t', this.i18n.hbsHelper);
exports.logger.log('Handlebars helper registered');
}
catch (e) {
exports.logger.error('hbs module failed to load', e);
}
}
if (['pug', 'ejs'].includes(this.i18nOptions.viewEngine)) {
const app = this.adapter.httpAdapter.getInstance();
app.locals['t'] = (key, lang, args) => {
return this.i18n.t(key, { lang, args });
};
}
if (!!this.i18nOptions.typesOutputPath) {
try {
const ts = await Promise.resolve().then(() => require('./utils/typescript'));
this.translations
.pipe((0, rxjs_1.takeUntil)(this.unsubscribe))
.subscribe(async (t) => {
exports.logger.log('Checking translation changes');
const object = Object.keys(t).reduce((result, key) => (0, utils_1.mergeDeep)(result, t[key]), {});
const rawContent = await ts.createTypesFile(object);
if (!rawContent) {
return;
}
const outputFile = ts.annotateSourceCode(rawContent);
fs.mkdirSync(path.dirname(this.i18nOptions.typesOutputPath), {
recursive: true,
});
let currentFileContent = null;
try {
currentFileContent = fs.readFileSync(this.i18nOptions.typesOutputPath, 'utf8');
}
catch (err) {
exports.logger.error(err);
}
if (currentFileContent != outputFile) {
fs.writeFileSync(this.i18nOptions.typesOutputPath, outputFile);
exports.logger.log(`Types generated in: ${this.i18nOptions.typesOutputPath}.
Please also add it to your eslintignore file to avoid linting errors
`);
}
else {
exports.logger.log('No changes detected');
}
});
}
catch (_) {
}
}
}
onModuleDestroy() {
this.unsubscribe.complete();
}
configure(consumer) {
if (this.i18nOptions.disableMiddleware)
return;
consumer
.apply(i18n_middleware_1.I18nMiddleware)
.forRoutes((0, utils_1.isNestMiddleware)(consumer) && (0, utils_1.usingFastify)(consumer) ? '(.*)' : '*');
}
static forRoot(options) {
options = this.sanitizeI18nOptions(options);
const i18nLanguagesSubject = new rxjs_1.BehaviorSubject([]);
const i18nTranslationSubject = new rxjs_1.BehaviorSubject({});
const i18nOptions = {

@@ -125,54 +76,18 @@ provide: i18n_constants_1.I18N_OPTIONS,

const i18nLoaderProvider = {
provide: i18n_loader_1.I18nLoader,
useClass: options.loader,
provide: i18n_constants_1.I18N_LOADERS,
useValue: options.loaders,
};
const i18nLoaderOptionsProvider = {
provide: i18n_constants_1.I18N_LOADER_OPTIONS,
useValue: options.loaderOptions,
};
const i18nLanguagesSubjectProvider = {
provide: i18n_constants_1.I18N_LANGUAGES_SUBJECT,
useValue: i18nLanguagesSubject,
};
const i18nTranslationSubjectProvider = {
provide: i18n_constants_1.I18N_TRANSLATIONS_SUBJECT,
useValue: i18nTranslationSubject,
};
const translationsProvider = {
provide: i18n_constants_1.I18N_TRANSLATIONS,
useFactory: async (loader) => {
try {
const translation = await loader.load();
if (translation instanceof rxjs_1.Observable) {
translation.subscribe(i18nTranslationSubject);
}
else {
i18nTranslationSubject.next(translation);
}
}
catch (e) {
exports.logger.error('parsing translation error', e);
}
return i18nTranslationSubject.asObservable();
useFactory: async (loaders) => {
return (0, loaders_utils_1.processTranslations)(loaders);
},
inject: [i18n_loader_1.I18nLoader],
inject: [i18n_constants_1.I18N_LOADERS],
};
const languagesProvider = {
provide: i18n_constants_1.I18N_LANGUAGES,
useFactory: async (loader) => {
try {
const languages = await loader.languages();
if (languages instanceof rxjs_1.Observable) {
languages.subscribe(i18nLanguagesSubject);
}
else {
i18nLanguagesSubject.next(languages);
}
}
catch (e) {
exports.logger.error('parsing translation error', e);
}
return i18nLanguagesSubject.asObservable();
useFactory: async (loaders) => {
return (0, loaders_utils_1.processLanguages)(loaders);
},
inject: [i18n_loader_1.I18nLoader],
inject: [i18n_constants_1.I18N_LOADERS],
};

@@ -197,5 +112,2 @@ const resolversProvider = {

i18nLoaderProvider,
i18nLoaderOptionsProvider,
i18nLanguagesSubjectProvider,
i18nTranslationSubjectProvider,
...this.createResolverProviders(options.resolvers),

@@ -211,5 +123,3 @@ ],

const asyncLanguagesProvider = this.createAsyncLanguagesProvider();
const asyncLoaderOptionsProvider = this.createAsyncLoaderOptionsProvider();
const i18nLanguagesSubject = new rxjs_1.BehaviorSubject([]);
const i18nTranslationSubject = new rxjs_1.BehaviorSubject({});
const asyncLoadersProvider = this.createAsyncLoadersProvider();
const resolversProvider = {

@@ -219,14 +129,2 @@ provide: i18n_constants_1.I18N_RESOLVERS,

};
const i18nLoaderProvider = {
provide: i18n_loader_1.I18nLoader,
useClass: options.loader,
};
const i18nLanguagesSubjectProvider = {
provide: i18n_constants_1.I18N_LANGUAGES_SUBJECT,
useValue: i18nLanguagesSubject,
};
const i18nTranslationSubjectProvider = {
provide: i18n_constants_1.I18N_TRANSLATIONS_SUBJECT,
useValue: i18nTranslationSubject,
};
return {

@@ -244,8 +142,5 @@ module: I18nModule_1,

asyncLanguagesProvider,
asyncLoaderOptionsProvider,
i18n_service_1.I18nService,
resolversProvider,
i18nLoaderProvider,
i18nLanguagesSubjectProvider,
i18nTranslationSubjectProvider,
asyncLoadersProvider,
...this.createResolverProviders(options.resolvers),

@@ -256,2 +151,3 @@ ],

i18n_constants_1.I18N_RESOLVERS,
i18n_constants_1.I18N_LOADERS,
i18n_service_1.I18nService,

@@ -262,2 +158,11 @@ asyncLanguagesProvider,

}
static createAsyncLoadersProvider() {
return {
provide: i18n_constants_1.I18N_LOADERS,
useFactory: async (options) => {
return options.loaders;
},
inject: [i18n_constants_1.I18N_OPTIONS],
};
}
static createAsyncOptionsProvider(options) {

@@ -279,30 +184,9 @@ if (options.useFactory) {

}
static createAsyncLoaderOptionsProvider() {
return {
provide: i18n_constants_1.I18N_LOADER_OPTIONS,
useFactory: async (options) => {
return this.sanitizeI18nOptions(options.loaderOptions);
},
inject: [i18n_constants_1.I18N_OPTIONS],
};
}
static createAsyncTranslationProvider() {
return {
provide: i18n_constants_1.I18N_TRANSLATIONS,
useFactory: async (loader, translationsSubject) => {
try {
const translation = await loader.load();
if (translation instanceof rxjs_1.Observable) {
translation.subscribe(translationsSubject);
}
else {
translationsSubject.next(translation);
}
}
catch (e) {
exports.logger.error('parsing translation error', e);
}
return translationsSubject.asObservable();
useFactory: async (loaders) => {
return (0, loaders_utils_1.processTranslations)(loaders);
},
inject: [i18n_loader_1.I18nLoader, i18n_constants_1.I18N_TRANSLATIONS_SUBJECT],
inject: [i18n_constants_1.I18N_LOADERS],
};

@@ -313,18 +197,6 @@ }

provide: i18n_constants_1.I18N_LANGUAGES,
useFactory: async (loader, languagesSubject) => {
try {
const languages = await loader.languages();
if (languages instanceof rxjs_1.Observable) {
languages.subscribe(languagesSubject);
}
else {
languagesSubject.next(languages);
}
}
catch (e) {
exports.logger.error('parsing translation error', e);
}
return languagesSubject.asObservable();
useFactory: async (loaders) => {
return (0, loaders_utils_1.processLanguages)(loaders);
},
inject: [i18n_loader_1.I18nLoader, i18n_constants_1.I18N_LANGUAGES_SUBJECT],
inject: [i18n_constants_1.I18N_LOADERS],
};

@@ -341,7 +213,7 @@ }

return (resolvers || [])
.filter(utils_1.shouldResolve)
.filter(util_1.shouldResolve)
.reduce((providers, r) => {
if (r['use']) {
const { use: resolver, options, ...rest } = r;
const optionsToken = (0, decorators_1.getI18nResolverOptionsToken)(resolver);
const optionsToken = (0, i18n_resolver_options_decorator_1.getI18nResolverOptionsToken)(resolver);
providers.push({

@@ -360,3 +232,3 @@ provide: resolver,

else {
const optionsToken = (0, decorators_1.getI18nResolverOptionsToken)(r);
const optionsToken = (0, i18n_resolver_options_decorator_1.getI18nResolverOptionsToken)(r);
providers.push({

@@ -375,2 +247,28 @@ provide: r,

}
async onModuleInit() {
await this.i18n.refresh();
if (this.i18nOptions.viewEngine == 'hbs') {
try {
const hbs = (await Promise.resolve().then(() => __importStar(require('hbs')))).default;
hbs.registerHelper('t', this.i18n.hbsHelper);
exports.logger.log('Handlebars helper registered');
}
catch (e) {
exports.logger.error('hbs module failed to load', e);
}
}
if (['pug', 'ejs'].includes(this.i18nOptions.viewEngine)) {
const app = this.adapter.httpAdapter.getInstance();
app.locals['t'] = (key, lang, args) => {
return this.i18n.t(key, { lang, args });
};
}
}
configure(consumer) {
if (this.i18nOptions.disableMiddleware)
return;
consumer
.apply(i18n_middleware_1.I18nMiddleware)
.forRoutes((0, util_1.isNestMiddleware)(consumer) && (0, util_1.usingFastify)(consumer) ? '(.*)' : '*');
}
};

@@ -380,8 +278,6 @@ I18nModule = I18nModule_1 = __decorate([

(0, common_1.Module)({}),
__param(1, (0, common_1.Inject)(i18n_constants_1.I18N_TRANSLATIONS)),
__param(2, (0, common_1.Inject)(i18n_constants_1.I18N_OPTIONS)),
__metadata("design:paramtypes", [i18n_service_1.I18nService,
rxjs_1.Observable, Object, core_1.HttpAdapterHost])
__param(1, (0, common_1.Inject)(i18n_constants_1.I18N_OPTIONS)),
__metadata("design:paramtypes", [i18n_service_1.I18nService, Object, core_1.HttpAdapterHost])
], I18nModule);
exports.I18nModule = I18nModule;
//# sourceMappingURL=i18n.module.js.map
export * from './i18n.module';
export { I18N_OPTIONS, I18N_TRANSLATIONS, I18N_LANGUAGES, I18N_RESOLVER_OPTIONS, I18N_RESOLVERS, I18N_LOADER_OPTIONS, } from './i18n.constants';
export { I18N_OPTIONS, I18N_TRANSLATIONS, I18N_LANGUAGES, I18N_RESOLVER_OPTIONS, I18N_RESOLVERS, I18N_LOADERS, } from './i18n.constants';
export * from './i18n.context';

@@ -4,0 +4,0 @@ export * from './services/i18n.service';

@@ -17,3 +17,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getContextObject = exports.i18nValidationMessage = exports.i18nValidationErrorFactory = exports.I18nMiddleware = exports.I18N_LOADER_OPTIONS = exports.I18N_RESOLVERS = exports.I18N_RESOLVER_OPTIONS = exports.I18N_LANGUAGES = exports.I18N_TRANSLATIONS = exports.I18N_OPTIONS = void 0;
exports.getContextObject = exports.i18nValidationMessage = exports.i18nValidationErrorFactory = exports.I18nMiddleware = exports.I18N_LOADERS = exports.I18N_RESOLVERS = exports.I18N_RESOLVER_OPTIONS = exports.I18N_LANGUAGES = exports.I18N_TRANSLATIONS = exports.I18N_OPTIONS = void 0;
__exportStar(require("./i18n.module"), exports);

@@ -26,3 +26,3 @@ var i18n_constants_1 = require("./i18n.constants");

Object.defineProperty(exports, "I18N_RESOLVERS", { enumerable: true, get: function () { return i18n_constants_1.I18N_RESOLVERS; } });
Object.defineProperty(exports, "I18N_LOADER_OPTIONS", { enumerable: true, get: function () { return i18n_constants_1.I18N_LOADER_OPTIONS; } });
Object.defineProperty(exports, "I18N_LOADERS", { enumerable: true, get: function () { return i18n_constants_1.I18N_LOADERS; } });
__exportStar(require("./i18n.context"), exports);

@@ -29,0 +29,0 @@ __exportStar(require("./services/i18n.service"), exports);

@@ -1,2 +0,2 @@

import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
import { I18nOptions } from '../index';

@@ -3,0 +3,0 @@ import { I18nService } from '../services/i18n.service';

@@ -22,4 +22,3 @@ import { Type } from '@nestjs/common';

resolvers?: I18nOptionResolver[];
loader?: Type<I18nLoader>;
loaderOptions: any;
loaders: I18nLoader<unknown>[];
formatter?: Formatter;

@@ -43,3 +42,3 @@ logging?: boolean;

resolvers?: I18nOptionResolver[];
loader?: Type<I18nLoader>;
loaders?: I18nLoader<unknown>[];
inject?: any[];

@@ -46,0 +45,0 @@ logging?: boolean;

@@ -1,5 +0,6 @@

import { I18nAbstractLoader, I18nAbstractLoaderOptions } from './i18n.abstract.loader';
export declare class I18nJsonLoader extends I18nAbstractLoader {
getDefaultOptions(): Partial<I18nAbstractLoaderOptions>;
import { I18nAbstractFileLoader, I18nAbstractFileLoaderOptions } from './i18n.abstract-file.loader';
export declare class I18nJsonLoader extends I18nAbstractFileLoader {
constructor(options: I18nAbstractFileLoaderOptions);
getDefaultOptions(): Partial<I18nAbstractFileLoaderOptions>;
formatData(data: any): any;
}

@@ -5,8 +5,10 @@ "use strict";

const i18n_error_1 = require("../i18n.error");
const i18n_abstract_loader_1 = require("./i18n.abstract.loader");
class I18nJsonLoader extends i18n_abstract_loader_1.I18nAbstractLoader {
const i18n_abstract_file_loader_1 = require("./i18n.abstract-file.loader");
class I18nJsonLoader extends i18n_abstract_file_loader_1.I18nAbstractFileLoader {
constructor(options) {
super(options);
}
getDefaultOptions() {
return {
filePattern: '*.json',
watch: false,
};

@@ -13,0 +15,0 @@ }

@@ -1,6 +0,7 @@

import { I18nTranslation } from '../interfaces';
import { Observable } from 'rxjs';
export declare abstract class I18nLoader {
abstract languages(): Promise<string[] | Observable<string[]>>;
abstract load(): Promise<I18nTranslation | Observable<I18nTranslation>>;
import { I18nTranslation } from '../interfaces/i18n-translation.interface';
export declare abstract class I18nLoader<T> {
protected options: T;
constructor(options: T);
abstract languages(): Promise<string[]>;
abstract load(): Promise<I18nTranslation>;
}

@@ -5,4 +5,7 @@ "use strict";

class I18nLoader {
constructor(options) {
this.options = options;
}
}
exports.I18nLoader = I18nLoader;
//# sourceMappingURL=i18n.loader.js.map

@@ -1,5 +0,5 @@

import { I18nAbstractLoader, I18nAbstractLoaderOptions } from './i18n.abstract.loader';
export declare class I18nYamlLoader extends I18nAbstractLoader {
getDefaultOptions(): Partial<I18nAbstractLoaderOptions>;
formatData(data: any): unknown;
import { I18nAbstractFileLoader, I18nAbstractFileLoaderOptions } from './i18n.abstract-file.loader';
export declare class I18nYamlLoader extends I18nAbstractFileLoader {
getDefaultOptions(): Partial<I18nAbstractFileLoaderOptions>;
formatData(data: any, sourceFileName: string): unknown;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.I18nYamlLoader = void 0;
const i18n_error_1 = require("../i18n.error");
const i18n_abstract_loader_1 = require("./i18n.abstract.loader");
const yaml = require("js-yaml");
class I18nYamlLoader extends i18n_abstract_loader_1.I18nAbstractLoader {
const i18n_abstract_file_loader_1 = require("./i18n.abstract-file.loader");
const js_yaml_1 = __importDefault(require("js-yaml"));
class I18nYamlLoader extends i18n_abstract_file_loader_1.I18nAbstractFileLoader {
getDefaultOptions() {
return {
filePattern: '*.yml',
watch: false,
};
}
formatData(data) {
formatData(data, sourceFileName) {
try {
return yaml.load(data, { json: true });
return js_yaml_1.default.load(data, { json: true });
}
catch (e) {
if (e instanceof yaml.YAMLException) {
if (e instanceof js_yaml_1.default.YAMLException) {
throw new i18n_error_1.I18nError('Invalid YAML file. Please check your YAML syntax.');

@@ -21,0 +23,0 @@ }

@@ -1,4 +0,4 @@

export * from './i18n.abstract.loader';
export * from './i18n.abstract-file.loader';
export * from './i18n.json.loader';
export * from './i18n.loader';
export * from './i18n.yaml.loader';

@@ -17,3 +17,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./i18n.abstract.loader"), exports);
__exportStar(require("./i18n.abstract-file.loader"), exports);
__exportStar(require("./i18n.json.loader"), exports);

@@ -20,0 +20,0 @@ __exportStar(require("./i18n.loader"), exports);

@@ -14,5 +14,8 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CookieResolver = void 0;
const cookie = require("cookie");
const cookie_1 = __importDefault(require("cookie"));
const common_1 = require("@nestjs/common");

@@ -37,3 +40,3 @@ const decorators_1 = require("../decorators");

if (!req.cookies && req.headers.cookie) {
req.cookies = cookie.parse(req.headers.cookie);
req.cookies = cookie_1.default.parse(req.headers.cookie);
}

@@ -40,0 +43,0 @@ if (req.cookies) {

@@ -17,3 +17,3 @@ "use strict";

const common_1 = require("@nestjs/common");
const decorators_1 = require("../decorators");
const i18n_resolver_options_decorator_1 = require("../decorators/i18n-resolver-options.decorator");
let HeaderResolver = class HeaderResolver {

@@ -51,3 +51,3 @@ constructor(keys = []) {

(0, common_1.Injectable)(),
__param(0, (0, decorators_1.I18nResolverOptions)()),
__param(0, (0, i18n_resolver_options_decorator_1.I18nResolverOptions)()),
__metadata("design:paramtypes", [Array])

@@ -54,0 +54,0 @@ ], HeaderResolver);

@@ -17,3 +17,3 @@ "use strict";

const common_1 = require("@nestjs/common");
const decorators_1 = require("../decorators");
const i18n_resolver_options_decorator_1 = require("../decorators/i18n-resolver-options.decorator");
let QueryResolver = class QueryResolver {

@@ -47,3 +47,3 @@ constructor(keys = []) {

(0, common_1.Injectable)(),
__param(0, (0, decorators_1.I18nResolverOptions)()),
__param(0, (0, i18n_resolver_options_decorator_1.I18nResolverOptions)()),
__metadata("design:paramtypes", [Array])

@@ -50,0 +50,0 @@ ], QueryResolver);

@@ -1,4 +0,4 @@

import { Logger, OnModuleDestroy } from '@nestjs/common';
import { BehaviorSubject, Observable } from 'rxjs';
import { I18nOptions, I18nTranslation, I18nValidationError } from '..';
import { Logger } from '@nestjs/common';
import { I18nOptions, I18nValidationError } from '..';
import { I18nTranslation } from '../interfaces/i18n-translation.interface';
import { I18nLoader } from '../loaders/i18n.loader';

@@ -17,26 +17,22 @@ import { IfAnyOrNever, Path, PathValue } from '../types';

};
export declare class I18nService<K = Record<string, unknown>> implements I18nTranslator<K>, OnModuleDestroy {
export declare class I18nService<K = Record<string, unknown>> implements I18nTranslator<K> {
protected readonly i18nOptions: I18nOptions;
protected translations: I18nTranslation;
protected supportedLanguages: string[];
private readonly logger;
private readonly loader;
private readonly languagesSubject;
private readonly translationsSubject;
private supportedLanguages;
private translations;
private readonly loaders;
private pluralRules;
private unsubscribe;
constructor(i18nOptions: I18nOptions, translations: Observable<I18nTranslation>, supportedLanguages: Observable<string[]>, logger: Logger, loader: I18nLoader, languagesSubject: BehaviorSubject<string[]>, translationsSubject: BehaviorSubject<I18nTranslation>);
onModuleDestroy(): void;
constructor(i18nOptions: I18nOptions, translations: I18nTranslation, supportedLanguages: string[], logger: Logger, loaders: I18nLoader<unknown>[]);
translate<P extends Path<K> = any, R = PathValue<K, P>>(key: P, options?: TranslateOptions): IfAnyOrNever<R, string, R>;
private getFallbackLanguage;
t<P extends Path<K> = any, R = PathValue<K, P>>(key: P, options?: TranslateOptions): IfAnyOrNever<R, string, R>;
getSupportedLanguages(): string[];
getTranslations(): I18nTranslation;
refresh(translations?: I18nTranslation | Observable<I18nTranslation>, languages?: string[] | Observable<string[]>): Promise<void>;
refresh(): Promise<void>;
hbsHelper: <P extends Path<K> = any>(key: P, args: any, options: any) => IfAnyOrNever<PathValue<K, P>, string, PathValue<K, P>>;
resolveLanguage(lang: string): string;
validate(value: any, options?: TranslateOptions): Promise<I18nValidationError[]>;
private getFallbackLanguage;
private translateObject;
resolveLanguage(lang: string): string;
private getPluralObject;
private getNestedTranslations;
validate(value: any, options?: TranslateOptions): Promise<I18nValidationError[]>;
}

@@ -17,18 +17,16 @@ "use strict";

const common_1 = require("@nestjs/common");
const i18n_constants_1 = require("../i18n.constants");
const class_validator_1 = require("class-validator");
const rxjs_1 = require("rxjs");
const i18n_constants_1 = require("../i18n.constants");
const i18n_loader_1 = require("../loaders/i18n.loader");
const utils_1 = require("../utils");
const loaders_utils_1 = require("../utils/loaders-utils");
const i18n_error_1 = require("../i18n.error");
const pluralKeys = ['zero', 'one', 'two', 'few', 'many', 'other'];
let I18nService = class I18nService {
constructor(i18nOptions, translations, supportedLanguages, logger, loader, languagesSubject, translationsSubject) {
constructor(i18nOptions, translations, supportedLanguages, logger, loaders) {
this.i18nOptions = i18nOptions;
this.translations = translations;
this.supportedLanguages = supportedLanguages;
this.logger = logger;
this.loader = loader;
this.languagesSubject = languagesSubject;
this.translationsSubject = translationsSubject;
this.loaders = loaders;
this.pluralRules = new Map();
this.unsubscribe = new rxjs_1.Subject();
this.hbsHelper = (key, args, options) => {

@@ -41,15 +39,3 @@ if (!options) {

};
supportedLanguages
.pipe((0, rxjs_1.takeUntil)(this.unsubscribe))
.subscribe((languages) => {
this.supportedLanguages = languages;
});
translations.pipe((0, rxjs_1.takeUntil)(this.unsubscribe)).subscribe((t) => {
this.translations = t;
});
}
onModuleDestroy() {
this.unsubscribe.next(null);
this.unsubscribe.complete();
}
translate(key, options) {

@@ -88,14 +74,2 @@ options = {

}
getFallbackLanguage(lang) {
let regionSepIndex = -1;
if (lang.includes('-')) {
regionSepIndex = lang.lastIndexOf('-');
}
if (lang.includes('_')) {
regionSepIndex = lang.lastIndexOf('_');
}
return regionSepIndex !== -1
? lang.slice(0, regionSepIndex)
: this.i18nOptions.fallbackLanguage;
}
t(key, options) {

@@ -110,21 +84,39 @@ return this.translate(key, options);

}
async refresh(translations, languages) {
if (!translations) {
translations = await this.loader.load();
async refresh() {
if (Object.keys(this.translations).length === 0) {
this.translations = await (0, loaders_utils_1.processTranslations)(this.loaders);
}
if (translations instanceof rxjs_1.Observable) {
this.translationsSubject.next(await (0, rxjs_1.lastValueFrom)(translations.pipe((0, rxjs_1.take)(1))));
if (this.supportedLanguages.length === 0) {
this.supportedLanguages = await (0, loaders_utils_1.processLanguages)(this.loaders);
}
else {
this.translationsSubject.next(translations);
}
resolveLanguage(lang) {
if (this.i18nOptions.fallbacks && !this.supportedLanguages.includes(lang)) {
const sanitizedLang = lang.includes('-')
? lang.substring(0, lang.indexOf('-')).concat('-*')
: lang;
for (const key in this.i18nOptions.fallbacks) {
if (key === lang || key === sanitizedLang) {
lang = this.i18nOptions.fallbacks[key];
break;
}
}
}
if (!languages) {
languages = await this.loader.languages();
return lang;
}
async validate(value, options) {
const errors = await (0, class_validator_1.validate)(value, this.i18nOptions.validatorOptions);
return (0, utils_1.formatI18nErrors)(errors, this, options);
}
getFallbackLanguage(lang) {
let regionSepIndex = -1;
if (lang.includes('-')) {
regionSepIndex = lang.lastIndexOf('-');
}
if (languages instanceof rxjs_1.Observable) {
this.languagesSubject.next(await (0, rxjs_1.lastValueFrom)(languages.pipe((0, rxjs_1.take)(1))));
if (lang.includes('_')) {
regionSepIndex = lang.lastIndexOf('_');
}
else {
this.languagesSubject.next(languages);
}
return regionSepIndex !== -1
? lang.slice(0, regionSepIndex)
: this.i18nOptions.fallbackLanguage;
}

@@ -191,16 +183,2 @@ translateObject(key, translations, lang, options, rootTranslations) {

}
resolveLanguage(lang) {
if (this.i18nOptions.fallbacks && !this.supportedLanguages.includes(lang)) {
const sanitizedLang = lang.includes('-')
? lang.substring(0, lang.indexOf('-')).concat('-*')
: lang;
for (const key in this.i18nOptions.fallbacks) {
if (key === lang || key === sanitizedLang) {
lang = this.i18nOptions.fallbacks[key];
break;
}
}
}
return lang;
}
getPluralObject(translation) {

@@ -243,6 +221,2 @@ for (const k of pluralKeys) {

}
async validate(value, options) {
const errors = await (0, class_validator_1.validate)(value, this.i18nOptions.validatorOptions);
return (0, utils_1.formatI18nErrors)(errors, this, options);
}
};

@@ -254,12 +228,6 @@ I18nService = __decorate([

__param(2, (0, common_1.Inject)(i18n_constants_1.I18N_LANGUAGES)),
__param(5, (0, common_1.Inject)(i18n_constants_1.I18N_LANGUAGES_SUBJECT)),
__param(6, (0, common_1.Inject)(i18n_constants_1.I18N_TRANSLATIONS_SUBJECT)),
__metadata("design:paramtypes", [Object, rxjs_1.Observable,
rxjs_1.Observable,
common_1.Logger,
i18n_loader_1.I18nLoader,
rxjs_1.BehaviorSubject,
rxjs_1.BehaviorSubject])
__param(4, (0, common_1.Inject)(i18n_constants_1.I18N_LOADERS)),
__metadata("design:paramtypes", [Object, Object, Array, common_1.Logger, Array])
], I18nService);
exports.I18nService = I18nService;
//# sourceMappingURL=i18n.service.js.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFiles = exports.getDirectories = exports.isDirectory = exports.filterAsync = exports.mapAsync = exports.exists = void 0;
const promises_1 = require("fs/promises");
const path = require("path");
const path_1 = __importDefault(require("path"));
const exists = async (path) => {

@@ -23,3 +26,3 @@ return !!(await (0, promises_1.stat)(path));

const dirs = await (0, promises_1.readdir)(source);
return filterAsync(dirs.map((name) => path.join(source, name)), exports.isDirectory);
return filterAsync(dirs.map((name) => path_1.default.join(source, name)), exports.isDirectory);
};

@@ -36,3 +39,3 @@ exports.getDirectories = getDirectories;

if (typeof f === 'string') {
if ((await (0, exports.exists)(path.join(dirPath, f))) && pattern.test(f)) {
if ((await (0, exports.exists)(path_1.default.join(dirPath, f))) && pattern.test(f)) {
files.push(f);

@@ -45,11 +48,9 @@ }

else if (includeSubfolders && f.isDirectory()) {
deepFiles.push(...(await (0, exports.getFiles)(path.join(dirPath, f.name), pattern, includeSubfolders)));
deepFiles.push(...(await (0, exports.getFiles)(path_1.default.join(dirPath, f.name), pattern, includeSubfolders)));
}
}
catch {
continue;
}
catch { }
}
return files
.map((f) => path.join(dirPath, typeof f === 'string' ? f : f.name))
.map((f) => path_1.default.join(dirPath, typeof f === 'string' ? f : f.name))
.concat(deepFiles);

@@ -56,0 +57,0 @@ };

@@ -6,1 +6,2 @@ export * from './context';

export * from './util';
export * from './typescript';

@@ -22,2 +22,3 @@ "use strict";

__exportStar(require("./util"), exports);
__exportStar(require("./typescript"), exports);
//# sourceMappingURL=index.js.map
import { I18nTranslation } from '../interfaces';
export declare function mergeDeep(target: I18nTranslation, ...sources: any): any;
export declare function mergeTranslations(first: I18nTranslation, second: I18nTranslation): I18nTranslation;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeDeep = void 0;
exports.mergeTranslations = exports.mergeDeep = void 0;
const mergician_1 = __importDefault(require("mergician"));
function isObject(item) {

@@ -26,2 +30,6 @@ return item && typeof item === 'object' && !Array.isArray(item);

exports.mergeDeep = mergeDeep;
function mergeTranslations(first, second) {
return (0, mergician_1.default)(first, second);
}
exports.mergeTranslations = mergeTranslations;
//# sourceMappingURL=merge.js.map

@@ -1,4 +0,4 @@

import * as ts from 'typescript';
import ts from 'typescript';
export declare const convertObjectToTypeDefinition: (object: any) => Promise<ts.TypeElement[]>;
export declare const createTypesFile: (object: any) => Promise<string>;
export declare const annotateSourceCode: (code: string) => string;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.annotateSourceCode = exports.createTypesFile = exports.convertObjectToTypeDefinition = void 0;
const ts = require("typescript");
const typescript_1 = __importDefault(require("typescript"));
const convertObjectToTypeDefinition = async (object) => {

@@ -10,8 +13,8 @@ switch (typeof object) {

if (typeof object[key] === 'string') {
return ts.factory.createPropertySignature(undefined, ts.factory.createStringLiteral(key), undefined, ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
return typescript_1.default.factory.createPropertySignature(undefined, typescript_1.default.factory.createStringLiteral(key), undefined, typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword));
}
if (Array.isArray(object[key])) {
return ts.factory.createPropertySignature(undefined, ts.factory.createStringLiteral(key), undefined, ts.factory.createTupleTypeNode(Array(object[key].length).fill(ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword))));
return typescript_1.default.factory.createPropertySignature(undefined, typescript_1.default.factory.createStringLiteral(key), undefined, typescript_1.default.factory.createTupleTypeNode(Array(object[key].length).fill(typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword))));
}
return ts.factory.createPropertySignature(undefined, ts.factory.createStringLiteral(key), undefined, ts.factory.createTypeLiteralNode(await (0, exports.convertObjectToTypeDefinition)(object[key])));
return typescript_1.default.factory.createPropertySignature(undefined, typescript_1.default.factory.createStringLiteral(key), undefined, typescript_1.default.factory.createTypeLiteralNode(await (0, exports.convertObjectToTypeDefinition)(object[key])));
}));

@@ -22,19 +25,19 @@ }

exports.convertObjectToTypeDefinition = convertObjectToTypeDefinition;
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed, });
const printer = typescript_1.default.createPrinter({ newLine: typescript_1.default.NewLineKind.LineFeed, });
const createTypesFile = async (object) => {
const sourceFile = ts.createSourceFile('placeholder.ts', '', ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
const i18nTranslationsType = ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createIdentifier('I18nTranslations'), undefined, ts.factory.createTypeLiteralNode(await (0, exports.convertObjectToTypeDefinition)(object)));
const nodes = ts.factory.createNodeArray([
ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('Path')),
])), ts.factory.createStringLiteral('nestjs-i18n'), undefined),
const sourceFile = typescript_1.default.createSourceFile('placeholder.ts', '', typescript_1.default.ScriptTarget.ESNext, true, typescript_1.default.ScriptKind.TS);
const i18nTranslationsType = typescript_1.default.factory.createTypeAliasDeclaration([typescript_1.default.factory.createModifier(typescript_1.default.SyntaxKind.ExportKeyword)], typescript_1.default.factory.createIdentifier('I18nTranslations'), undefined, typescript_1.default.factory.createTypeLiteralNode(await (0, exports.convertObjectToTypeDefinition)(object)));
const nodes = typescript_1.default.factory.createNodeArray([
typescript_1.default.factory.createImportDeclaration(undefined, typescript_1.default.factory.createImportClause(false, undefined, typescript_1.default.factory.createNamedImports([
typescript_1.default.factory.createImportSpecifier(false, undefined, typescript_1.default.factory.createIdentifier('Path')),
])), typescript_1.default.factory.createStringLiteral('nestjs-i18n'), undefined),
i18nTranslationsType,
ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createIdentifier('I18nPath'), undefined, ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('Path'), [
ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('I18nTranslations'), undefined),
typescript_1.default.factory.createTypeAliasDeclaration([typescript_1.default.factory.createModifier(typescript_1.default.SyntaxKind.ExportKeyword)], typescript_1.default.factory.createIdentifier('I18nPath'), undefined, typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier('Path'), [
typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier('I18nTranslations'), undefined),
])),
]);
nodes.forEach((node) => {
ts.addSyntheticLeadingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, ' prettier-ignore ', true);
typescript_1.default.addSyntheticLeadingComment(node, typescript_1.default.SyntaxKind.MultiLineCommentTrivia, ' prettier-ignore ', true);
});
return printer.printList(ts.ListFormat.MultiLine, nodes, sourceFile);
return printer.printList(typescript_1.default.ListFormat.MultiLine, nodes, sourceFile);
};

@@ -44,3 +47,3 @@ exports.createTypesFile = createTypesFile;

return `/* DO NOT EDIT, file generated by nestjs-i18n */
/* eslint-disable */

@@ -47,0 +50,0 @@ ${code}`;

@@ -9,4 +9,5 @@ import { I18nOptionResolver, I18nValidationError, I18nValidationException } from '../interfaces';

export declare function i18nValidationMessage<K = Record<string, unknown>>(key: Path<K>, args?: any): (a: ValidationArguments) => string;
export declare function i18nValidationMessageString<K = Record<string, unknown>>(key: Path<K>): string;
export declare function formatI18nErrors<K = Record<string, unknown>>(errors: I18nValidationError[], i18n: I18nService<K>, options?: TranslateOptions): I18nValidationError[];
export declare const isNestMiddleware: (consumer: MiddlewareConsumer) => consumer is NestMiddlewareConsumer;
export declare const usingFastify: (consumer: NestMiddlewareConsumer) => boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.usingFastify = exports.isNestMiddleware = exports.formatI18nErrors = exports.i18nValidationMessage = exports.i18nValidationErrorFactory = exports.shouldResolve = void 0;
exports.usingFastify = exports.isNestMiddleware = exports.formatI18nErrors = exports.i18nValidationMessageString = exports.i18nValidationMessage = exports.i18nValidationErrorFactory = exports.shouldResolve = void 0;
const interfaces_1 = require("../interfaces");

@@ -42,2 +42,6 @@ const class_validator_1 = require("class-validator");

exports.i18nValidationMessage = i18nValidationMessage;
function i18nValidationMessageString(key) {
return key;
}
exports.i18nValidationMessageString = i18nValidationMessageString;
function formatI18nErrors(errors, i18n, options) {

@@ -44,0 +48,0 @@ return errors.map((error) => {

{
"name": "nestjs-i18n",
"version": "10.4.5",
"version": "11.0.0-beta",
"homepage": "https://nestjs-i18n.com",

@@ -26,2 +26,5 @@ "description": "The i18n module for Nest.",

},
"bin": {
"nestjs-i18n": "./dist/cli.js"
},
"main": "./dist/index.js",

@@ -34,2 +37,3 @@ "types": "./dist/index.d.ts",

"prepare": "npm run build",
"postbuild": "chmod +x ./dist/cli.js",
"build": "npm run build:lib",

@@ -113,7 +117,11 @@ "build:lib": "npx rimraf dist && tsc -p tsconfig.build.json",

"accept-language-parser": "^1.5.0",
"chalk": "^4.1.2",
"chokidar": "^3.5.3",
"cookie": "^0.5.0",
"fs-extra": "^11.1.1",
"iterare": "^1.2.1",
"js-yaml": "^4.1.0",
"string-format": "^2.0.0"
"mergician": "^1.1.0",
"string-format": "^2.0.0",
"yargs": "^17.7.2"
},

@@ -120,0 +128,0 @@ "peerDependencies": {

@@ -34,3 +34,3 @@ <p align="center">

To get started follow the [**quickstart**](https://nestjs-i18n.com/quick-start), or take a look at the [**docs**](https://nestjs-i18n.com/).
To get started follow the [**quickstart**](https://nestjs-i18n.com/quick-start), or take a look at the [**docs**](https://nestjs-i18n.com/).

@@ -37,0 +37,0 @@ ## License

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc