From 7d276cf76a1cc379f5748a35c831f733aedfb47f Mon Sep 17 00:00:00 2001 From: deptyped Date: Sun, 29 Jan 2023 14:46:04 +0200 Subject: [PATCH] Make ctx.i18n non-enumerable --- src/i18n.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/i18n.ts b/src/i18n.ts index d239d3e5..a06fd9eb 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -193,13 +193,18 @@ should either enable sessions or use `ctx.i18n.useLocale()` instead.", }); } - ctx.i18n = { - fluent, - renegotiateLocale: negotiateLocale, - useLocale, - getLocale: getNegotiatedLocale, - setLocale, - }; + Object.defineProperty(ctx, "i18n", { + value: { + fluent, + renegotiateLocale: negotiateLocale, + useLocale, + getLocale: getNegotiatedLocale, + setLocale, + }, + // Allow redefine property. This is necessary to be able to install the plugin + // inside the conversation even if the plugin is already installed globally. + writable: true, + }); ctx.t = translateWrapper; ctx.translate = translateWrapper;