From ec255dabf64785f3454037eda641d62e3276efe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Moreau?= Date: Fri, 13 Dec 2024 13:57:06 +0100 Subject: [PATCH] Reintroduced Symbol (#301) --- bun.lockb | Bin 84100 -> 84100 bytes src/i18next.ts | 18 +++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bun.lockb b/bun.lockb index 8b899fc5712ad3cf535e742637197c100aa38815..77cb0820617c34387279a3c4190e87a6729d73ab 100755 GIT binary patch delta 127 zcmZpf$l5ZIbwkFT$vJmq7_`!Fx>zE delta 128 zcmZpf$l5ZIbwkD-MyAQBcjPB`+>v3L$1r)(9iz!N?vx15XJBBM1H?0dcoh(@-W+?^ znTaJI$eg_7z6xXh=9BmDv#=WL8R!{IUi;)fl(q4xjv^CK4Hzr~k`fFI4SLVFu^sEE Ozrg{O+5GQmTM__Y5h_*y diff --git a/src/i18next.ts b/src/i18next.ts index 912cc92..5f012cf 100644 --- a/src/i18next.ts +++ b/src/i18next.ts @@ -4,12 +4,16 @@ import type { FlatNamespace, TFunction } from "i18next"; import type { RemixI18NextOption } from "remix-i18next/server"; import { RemixI18Next } from "remix-i18next/server"; -const i18nSymbol = Symbol().toString(); -const LocaleSymbol = Symbol().toString(); -const TSymbol = Symbol().toString(); +type Env = { + Variables: Record; +}; + +const i18nSymbol = Symbol(); +const LocaleSymbol = Symbol(); +const TSymbol = Symbol(); export function i18next(options: RemixI18NextOption | RemixI18Next) { - return createMiddleware(async (c, next) => { + return createMiddleware(async (c, next) => { let i18n = options instanceof RemixI18Next ? options : new RemixI18Next(options); @@ -25,7 +29,7 @@ export function i18next(options: RemixI18NextOption | RemixI18Next) { }); } -i18next.get = function get(c: Context) { +i18next.get = function get(c: Context) { let i18n = c.get(i18nSymbol) as RemixI18Next | undefined; if (!i18n) { throw new Error( @@ -35,7 +39,7 @@ i18next.get = function get(c: Context) { return i18n; }; -i18next.getLocale = function getLocale(c: Context) { +i18next.getLocale = function getLocale(c: Context) { let locale = c.get(LocaleSymbol) as string | undefined; if (!locale) { throw new Error( @@ -47,7 +51,7 @@ i18next.getLocale = function getLocale(c: Context) { i18next.getFixedT = function getFixedT< Ns extends FlatNamespace = "translation", ->(c: Context, { namespace }: { namespace?: Ns } = {}) { +>(c: Context, { namespace }: { namespace?: Ns } = {}) { // If `namespace` is set, we return a new `t` function that is bound to the // given namespace. Otherwise, we return the default `t` function. if (namespace) {