nestjs-i18n
Advanced tools
Comparing version 10.4.5 to 10.4.6
import { ArgumentsHost } from '@nestjs/common'; | ||
import { I18nTranslator, I18nValidationError } from './interfaces'; | ||
import { I18nOptions, I18nTranslator, I18nValidationError } from './interfaces'; | ||
import { I18nService, TranslateOptions } from './services/i18n.service'; | ||
@@ -8,2 +8,3 @@ import { Path, PathValue } from './types'; | ||
readonly service: I18nService<K>; | ||
readonly i18nOptions: I18nOptions; | ||
private static storage; | ||
@@ -13,3 +14,3 @@ private static counter; | ||
get i18n(): I18nContext<K> | undefined; | ||
constructor(lang: string, service: I18nService<K>); | ||
constructor(lang: string, service: I18nService<K>, i18nOptions: I18nOptions); | ||
translate<P extends Path<K> = any, R = PathValue<K, P>>(key: P, options?: TranslateOptions): import("./types").IfAnyOrNever<R, string, R>; | ||
@@ -16,0 +17,0 @@ t<P extends Path<K> = any, R = PathValue<K, P>>(key: P, options?: TranslateOptions): import("./types").IfAnyOrNever<R, string, R>; |
@@ -10,5 +10,6 @@ "use strict"; | ||
} | ||
constructor(lang, service) { | ||
constructor(lang, service, i18nOptions) { | ||
this.lang = lang; | ||
this.service = service; | ||
this.i18nOptions = i18nOptions; | ||
this.id = I18nContext.counter++; | ||
@@ -42,3 +43,3 @@ } | ||
if (!i18n && !!context) { | ||
return (0, utils_1.getContextObject)(context)?.i18nContext; | ||
return (0, utils_1.getContextObject)(i18n.i18nOptions, context)?.i18nContext; | ||
} | ||
@@ -45,0 +46,0 @@ return i18n; |
@@ -33,3 +33,3 @@ "use strict"; | ||
let language = null; | ||
const ctx = (0, utils_1.getContextObject)(context); | ||
const ctx = (0, utils_1.getContextObject)(this.i18nOptions, context); | ||
if (ctx === undefined || !!ctx.i18nLang) { | ||
@@ -54,3 +54,3 @@ return next.handle(); | ||
if (!i18nContext) { | ||
ctx.i18nContext = new index_1.I18nContext(ctx.i18nLang, this.i18nService); | ||
ctx.i18nContext = new index_1.I18nContext(ctx.i18nLang, this.i18nService, this.i18nOptions); | ||
if (!this.i18nOptions.skipAsyncHook) { | ||
@@ -57,0 +57,0 @@ return new rxjs_1.Observable((observer) => { |
@@ -51,3 +51,3 @@ "use strict"; | ||
} | ||
req.i18nContext = new index_1.I18nContext(req.i18nLang, this.i18nService); | ||
req.i18nContext = new index_1.I18nContext(req.i18nLang, this.i18nService, this.i18nOptions); | ||
if (this.i18nOptions.skipAsyncHook) { | ||
@@ -54,0 +54,0 @@ next(); |
@@ -19,2 +19,3 @@ "use strict"; | ||
const rxjs_1 = require("rxjs"); | ||
const __1 = require(".."); | ||
const i18n_constants_1 = require("../i18n.constants"); | ||
@@ -56,3 +57,3 @@ const i18n_loader_1 = require("../loaders/i18n.loader"); | ||
options = { | ||
lang: this.i18nOptions.fallbackLanguage, | ||
lang: __1.I18nContext.current()?.lang || this.i18nOptions.fallbackLanguage, | ||
...options, | ||
@@ -59,0 +60,0 @@ }; |
import { ArgumentsHost, ExecutionContext } from '@nestjs/common'; | ||
export declare function getContextObject(context?: ExecutionContext | ArgumentsHost): any; | ||
import { I18nOptions } from '..'; | ||
export declare function getContextObject(i18nOptions: I18nOptions, context?: ExecutionContext | ArgumentsHost): any; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const logger = new common_1.Logger('I18nService'); | ||
function getContextObject(context) { | ||
function getContextObject(i18nOptions, context) { | ||
const contextType = context?.getType() ?? 'undefined'; | ||
@@ -19,3 +19,5 @@ switch (contextType) { | ||
default: | ||
logger.warn(`context type: ${contextType} not supported`); | ||
if (i18nOptions.logging) { | ||
logger.warn(`context type: ${contextType} not supported`); | ||
} | ||
} | ||
@@ -22,0 +24,0 @@ } |
{ | ||
"name": "nestjs-i18n", | ||
"version": "10.4.5", | ||
"version": "10.4.6", | ||
"homepage": "https://nestjs-i18n.com", | ||
@@ -5,0 +5,0 @@ "description": "The i18n module for Nest.", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
338940
2446