express-intlayer 3.1.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,16 +33,23 @@ const { middleware, internationalization } = (0, import_config.getConfiguration)
33
33
  const { headerName, cookieName } = middleware;
34
34
  const appNamespace = (0, import_cls_hooked.createNamespace)("app");
35
35
  (0, import_chokidar.createModuleAugmentation)();
36
- const translateFunction = (_req, res, _next) => (content) => {
37
- const { locale, defaultLocale } = res.locals;
38
- if (typeof content[locale] === "undefined") {
39
- if (typeof content[defaultLocale] === "undefined") {
36
+ const translateFunction = (_req, res, _next) => (content, locale) => {
37
+ const { locale: currentLocale, defaultLocale } = res.locals;
38
+ const targetLocale = locale ?? currentLocale;
39
+ if (typeof content === "undefined") {
40
+ return "";
41
+ }
42
+ if (typeof content === "string") {
43
+ return content;
44
+ }
45
+ if (typeof content?.[targetLocale] === "undefined") {
46
+ if (typeof content?.[defaultLocale] === "undefined") {
40
47
  return content;
41
48
  } else {
42
49
  return (0, import_core.getTranslationContent)(content, defaultLocale);
43
50
  }
44
51
  }
45
- return (0, import_core.getTranslationContent)(content, locale);
52
+ return (0, import_core.getTranslationContent)(content, targetLocale);
46
53
  };
47
54
  const intlayer = () => (req, res, next) => {
48
55
  const localeCookie = req.cookies?.[cookieName];
@@ -72,7 +79,7 @@ const intlayer = () => (req, res, next) => {
72
79
  next();
73
80
  });
74
81
  };
75
- const t = (content) => appNamespace.get("t")(content);
82
+ const t = (content, locale) => appNamespace.get("t")(content, locale);
76
83
  // Annotate the CommonJS export names for ESM import in node:
77
84
  0 && (module.exports = {
78
85
  intlayer,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { createModuleAugmentation } from '@intlayer/chokidar';\nimport { type Locales, getConfiguration } from '@intlayer/config';\nimport { getTranslationContent, localeDetector } from '@intlayer/core';\nimport { createNamespace } from 'cls-hooked';\nimport type { NextFunction, RequestHandler, Request, Response } from 'express';\nimport { type IConfigLocales } from 'intlayer';\n\nconst { middleware, internationalization } = getConfiguration({\n verbose: true,\n});\nconst { headerName, cookieName } = middleware;\n\nconst appNamespace = createNamespace('app');\n\ncreateModuleAugmentation();\n\nexport const translateFunction =\n (_req: Request, res: Response, _next?: NextFunction) =>\n <T extends string>(content: IConfigLocales<T>): T => {\n const { locale, defaultLocale } = res.locals as {\n locale: Locales;\n defaultLocale: Locales;\n };\n\n if (\n typeof content[locale as unknown as keyof IConfigLocales<T>] ===\n 'undefined'\n ) {\n if (\n typeof content[defaultLocale as unknown as keyof IConfigLocales<T>] ===\n 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslationContent(content, defaultLocale);\n }\n }\n\n return getTranslationContent(content, locale);\n };\n\n/**\n * Detect locale used by the user and load it into res locale storage\n *\n * @returns\n */\nexport const intlayer = (): RequestHandler => (req, res, next) => {\n // Detect if locale is set by intlayer frontend lib in the cookies\n const localeCookie = req.cookies?.[cookieName];\n // Detect if locale is set by intlayer frontend lib in the headers\n const localeHeader = req.headers?.[headerName];\n // Interpret browser locale\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // // Check if req.headers exists and is an object\n if (req && typeof req.headers === 'object') {\n // Copy all headers from the request to negotiatorHeaders\n for (const key in req.headers) {\n if (typeof req.headers[key] === 'string') {\n negotiatorHeaders[key] = req.headers[key];\n }\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n res.locals.locale_header = localeHeader;\n res.locals.locale_cookie = localeCookie;\n res.locals.locale_detected = localeDetected;\n res.locals.locale = localeCookie ?? localeHeader ?? localeDetected;\n res.locals.defaultLocale = internationalization.defaultLocale;\n\n const t = translateFunction(req, res, next);\n res.locals.t = t;\n\n appNamespace.run(() => {\n appNamespace.set('t', t);\n\n next();\n });\n};\n\ntype LanguageContent<Content = string> = IConfigLocales<Content>;\n\nexport const t = <Content = string>(content: LanguageContent<Content>) =>\n appNamespace.get('t')(content);\n\nexport { LanguageContent };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAyC;AACzC,oBAA+C;AAC/C,kBAAsD;AACtD,wBAAgC;AAIhC,MAAM,EAAE,YAAY,qBAAqB,QAAI,gCAAiB;AAAA,EAC5D,SAAS;AACX,CAAC;AACD,MAAM,EAAE,YAAY,WAAW,IAAI;AAEnC,MAAM,mBAAe,mCAAgB,KAAK;AAAA,IAE1C,0CAAyB;AAElB,MAAM,oBACX,CAAC,MAAe,KAAe,UAC/B,CAAmB,YAAkC;AACnD,QAAM,EAAE,QAAQ,cAAc,IAAI,IAAI;AAKtC,MACE,OAAO,QAAQ,MAA4C,MAC3D,aACA;AACA,QACE,OAAO,QAAQ,aAAmD,MAClE,aACA;AACA,aAAO;AAAA,IACT,OAAO;AACL,iBAAO,mCAAsB,SAAS,aAAa;AAAA,IACrD;AAAA,EACF;AAEA,aAAO,mCAAsB,SAAS,MAAM;AAC9C;AAOK,MAAM,WAAW,MAAsB,CAAC,KAAK,KAAK,SAAS;AAEhE,QAAM,eAAe,IAAI,UAAU,UAAU;AAE7C,QAAM,eAAe,IAAI,UAAU,UAAU;AAG7C,QAAM,oBAA4C,CAAC;AAGnD,MAAI,OAAO,OAAO,IAAI,YAAY,UAAU;AAE1C,eAAW,OAAO,IAAI,SAAS;AAC7B,UAAI,OAAO,IAAI,QAAQ,GAAG,MAAM,UAAU;AACxC,0BAAkB,GAAG,IAAI,IAAI,QAAQ,GAAG;AAAA,MAC1C;AAAA,IACF;AAAA,EACF;AAEA,QAAM,qBAAiB;AAAA,IACrB;AAAA,IACA,qBAAqB;AAAA,IACrB,qBAAqB;AAAA,EACvB;AAEA,MAAI,OAAO,gBAAgB;AAC3B,MAAI,OAAO,gBAAgB;AAC3B,MAAI,OAAO,kBAAkB;AAC7B,MAAI,OAAO,SAAS,gBAAgB,gBAAgB;AACpD,MAAI,OAAO,gBAAgB,qBAAqB;AAEhD,QAAMA,KAAI,kBAAkB,KAAK,KAAK,IAAI;AAC1C,MAAI,OAAO,IAAIA;AAEf,eAAa,IAAI,MAAM;AACrB,iBAAa,IAAI,KAAKA,EAAC;AAEvB,SAAK;AAAA,EACP,CAAC;AACH;AAIO,MAAM,IAAI,CAAmB,YAClC,aAAa,IAAI,GAAG,EAAE,OAAO;","names":["t"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { createModuleAugmentation } from '@intlayer/chokidar';\nimport { type Locales, getConfiguration } from '@intlayer/config';\nimport { getTranslationContent, localeDetector } from '@intlayer/core';\nimport { createNamespace } from 'cls-hooked';\nimport type { NextFunction, RequestHandler, Request, Response } from 'express';\nimport { type IConfigLocales } from 'intlayer';\n\nconst { middleware, internationalization } = getConfiguration({\n verbose: true,\n});\nconst { headerName, cookieName } = middleware;\n\nconst appNamespace = createNamespace('app');\n\ncreateModuleAugmentation();\n\nexport const translateFunction =\n (_req: Request, res: Response, _next?: NextFunction) =>\n <T extends string>(\n content: IConfigLocales<T> | string,\n locale?: Locales\n ): T => {\n const { locale: currentLocale, defaultLocale } = res.locals as {\n locale: Locales;\n defaultLocale: Locales;\n };\n\n const targetLocale = locale ?? currentLocale;\n\n if (typeof content === 'undefined') {\n return '' as unknown as T;\n }\n\n if (typeof content === 'string') {\n return content as unknown as T;\n }\n\n if (\n typeof content?.[targetLocale as unknown as keyof IConfigLocales<T>] ===\n 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof IConfigLocales<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslationContent(content, defaultLocale);\n }\n }\n\n return getTranslationContent(content, targetLocale);\n };\n\n/**\n * Detect locale used by the user and load it into res locale storage\n *\n * @returns\n */\nexport const intlayer = (): RequestHandler => (req, res, next) => {\n // Detect if locale is set by intlayer frontend lib in the cookies\n const localeCookie = req.cookies?.[cookieName];\n // Detect if locale is set by intlayer frontend lib in the headers\n const localeHeader = req.headers?.[headerName];\n // Interpret browser locale\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // // Check if req.headers exists and is an object\n if (req && typeof req.headers === 'object') {\n // Copy all headers from the request to negotiatorHeaders\n for (const key in req.headers) {\n if (typeof req.headers[key] === 'string') {\n negotiatorHeaders[key] = req.headers[key];\n }\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n res.locals.locale_header = localeHeader;\n res.locals.locale_cookie = localeCookie;\n res.locals.locale_detected = localeDetected;\n res.locals.locale = localeCookie ?? localeHeader ?? localeDetected;\n res.locals.defaultLocale = internationalization.defaultLocale;\n\n const t = translateFunction(req, res, next);\n res.locals.t = t;\n\n appNamespace.run(() => {\n appNamespace.set('t', t);\n\n next();\n });\n};\n\ntype LanguageContent<Content = string> = IConfigLocales<Content>;\n\nexport const t = <Content = string>(\n content: LanguageContent<Content>,\n locale?: Locales\n): Content => appNamespace.get('t')(content, locale);\n\nexport { LanguageContent };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAyC;AACzC,oBAA+C;AAC/C,kBAAsD;AACtD,wBAAgC;AAIhC,MAAM,EAAE,YAAY,qBAAqB,QAAI,gCAAiB;AAAA,EAC5D,SAAS;AACX,CAAC;AACD,MAAM,EAAE,YAAY,WAAW,IAAI;AAEnC,MAAM,mBAAe,mCAAgB,KAAK;AAAA,IAE1C,0CAAyB;AAElB,MAAM,oBACX,CAAC,MAAe,KAAe,UAC/B,CACE,SACA,WACM;AACN,QAAM,EAAE,QAAQ,eAAe,cAAc,IAAI,IAAI;AAKrD,QAAM,eAAe,UAAU;AAE/B,MAAI,OAAO,YAAY,aAAa;AAClC,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AAEA,MACE,OAAO,UAAU,YAAkD,MACnE,aACA;AACA,QACE,OAAO,UACL,aACF,MAAM,aACN;AACA,aAAO;AAAA,IACT,OAAO;AACL,iBAAO,mCAAsB,SAAS,aAAa;AAAA,IACrD;AAAA,EACF;AAEA,aAAO,mCAAsB,SAAS,YAAY;AACpD;AAOK,MAAM,WAAW,MAAsB,CAAC,KAAK,KAAK,SAAS;AAEhE,QAAM,eAAe,IAAI,UAAU,UAAU;AAE7C,QAAM,eAAe,IAAI,UAAU,UAAU;AAG7C,QAAM,oBAA4C,CAAC;AAGnD,MAAI,OAAO,OAAO,IAAI,YAAY,UAAU;AAE1C,eAAW,OAAO,IAAI,SAAS;AAC7B,UAAI,OAAO,IAAI,QAAQ,GAAG,MAAM,UAAU;AACxC,0BAAkB,GAAG,IAAI,IAAI,QAAQ,GAAG;AAAA,MAC1C;AAAA,IACF;AAAA,EACF;AAEA,QAAM,qBAAiB;AAAA,IACrB;AAAA,IACA,qBAAqB;AAAA,IACrB,qBAAqB;AAAA,EACvB;AAEA,MAAI,OAAO,gBAAgB;AAC3B,MAAI,OAAO,gBAAgB;AAC3B,MAAI,OAAO,kBAAkB;AAC7B,MAAI,OAAO,SAAS,gBAAgB,gBAAgB;AACpD,MAAI,OAAO,gBAAgB,qBAAqB;AAEhD,QAAMA,KAAI,kBAAkB,KAAK,KAAK,IAAI;AAC1C,MAAI,OAAO,IAAIA;AAEf,eAAa,IAAI,MAAM;AACrB,iBAAa,IAAI,KAAKA,EAAC;AAEvB,SAAK;AAAA,EACP,CAAC;AACH;AAIO,MAAM,IAAI,CACf,SACA,WACY,aAAa,IAAI,GAAG,EAAE,SAAS,MAAM;","names":["t"]}
@@ -8,16 +8,23 @@ const { middleware, internationalization } = getConfiguration({
8
8
  const { headerName, cookieName } = middleware;
9
9
  const appNamespace = createNamespace("app");
10
10
  createModuleAugmentation();
11
- const translateFunction = (_req, res, _next) => (content) => {
12
- const { locale, defaultLocale } = res.locals;
13
- if (typeof content[locale] === "undefined") {
14
- if (typeof content[defaultLocale] === "undefined") {
11
+ const translateFunction = (_req, res, _next) => (content, locale) => {
12
+ const { locale: currentLocale, defaultLocale } = res.locals;
13
+ const targetLocale = locale ?? currentLocale;
14
+ if (typeof content === "undefined") {
15
+ return "";
16
+ }
17
+ if (typeof content === "string") {
18
+ return content;
19
+ }
20
+ if (typeof content?.[targetLocale] === "undefined") {
21
+ if (typeof content?.[defaultLocale] === "undefined") {
15
22
  return content;
16
23
  } else {
17
24
  return getTranslationContent(content, defaultLocale);
18
25
  }
19
26
  }
20
- return getTranslationContent(content, locale);
27
+ return getTranslationContent(content, targetLocale);
21
28
  };
22
29
  const intlayer = () => (req, res, next) => {
23
30
  const localeCookie = req.cookies?.[cookieName];
@@ -47,7 +54,7 @@ const intlayer = () => (req, res, next) => {
47
54
  next();
48
55
  });
49
56
  };
50
- const t = (content) => appNamespace.get("t")(content);
57
+ const t = (content, locale) => appNamespace.get("t")(content, locale);
51
58
  export {
52
59
  intlayer,
53
60
  t,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { createModuleAugmentation } from '@intlayer/chokidar';\nimport { type Locales, getConfiguration } from '@intlayer/config';\nimport { getTranslationContent, localeDetector } from '@intlayer/core';\nimport { createNamespace } from 'cls-hooked';\nimport type { NextFunction, RequestHandler, Request, Response } from 'express';\nimport { type IConfigLocales } from 'intlayer';\n\nconst { middleware, internationalization } = getConfiguration({\n verbose: true,\n});\nconst { headerName, cookieName } = middleware;\n\nconst appNamespace = createNamespace('app');\n\ncreateModuleAugmentation();\n\nexport const translateFunction =\n (_req: Request, res: Response, _next?: NextFunction) =>\n <T extends string>(content: IConfigLocales<T>): T => {\n const { locale, defaultLocale } = res.locals as {\n locale: Locales;\n defaultLocale: Locales;\n };\n\n if (\n typeof content[locale as unknown as keyof IConfigLocales<T>] ===\n 'undefined'\n ) {\n if (\n typeof content[defaultLocale as unknown as keyof IConfigLocales<T>] ===\n 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslationContent(content, defaultLocale);\n }\n }\n\n return getTranslationContent(content, locale);\n };\n\n/**\n * Detect locale used by the user and load it into res locale storage\n *\n * @returns\n */\nexport const intlayer = (): RequestHandler => (req, res, next) => {\n // Detect if locale is set by intlayer frontend lib in the cookies\n const localeCookie = req.cookies?.[cookieName];\n // Detect if locale is set by intlayer frontend lib in the headers\n const localeHeader = req.headers?.[headerName];\n // Interpret browser locale\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // // Check if req.headers exists and is an object\n if (req && typeof req.headers === 'object') {\n // Copy all headers from the request to negotiatorHeaders\n for (const key in req.headers) {\n if (typeof req.headers[key] === 'string') {\n negotiatorHeaders[key] = req.headers[key];\n }\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n res.locals.locale_header = localeHeader;\n res.locals.locale_cookie = localeCookie;\n res.locals.locale_detected = localeDetected;\n res.locals.locale = localeCookie ?? localeHeader ?? localeDetected;\n res.locals.defaultLocale = internationalization.defaultLocale;\n\n const t = translateFunction(req, res, next);\n res.locals.t = t;\n\n appNamespace.run(() => {\n appNamespace.set('t', t);\n\n next();\n });\n};\n\ntype LanguageContent<Content = string> = IConfigLocales<Content>;\n\nexport const t = <Content = string>(content: LanguageContent<Content>) =>\n appNamespace.get('t')(content);\n\nexport { LanguageContent };\n"],"mappings":"AAAA,SAAS,gCAAgC;AACzC,SAAuB,wBAAwB;AAC/C,SAAS,uBAAuB,sBAAsB;AACtD,SAAS,uBAAuB;AAIhC,MAAM,EAAE,YAAY,qBAAqB,IAAI,iBAAiB;AAAA,EAC5D,SAAS;AACX,CAAC;AACD,MAAM,EAAE,YAAY,WAAW,IAAI;AAEnC,MAAM,eAAe,gBAAgB,KAAK;AAE1C,yBAAyB;AAElB,MAAM,oBACX,CAAC,MAAe,KAAe,UAC/B,CAAmB,YAAkC;AACnD,QAAM,EAAE,QAAQ,cAAc,IAAI,IAAI;AAKtC,MACE,OAAO,QAAQ,MAA4C,MAC3D,aACA;AACA,QACE,OAAO,QAAQ,aAAmD,MAClE,aACA;AACA,aAAO;AAAA,IACT,OAAO;AACL,aAAO,sBAAsB,SAAS,aAAa;AAAA,IACrD;AAAA,EACF;AAEA,SAAO,sBAAsB,SAAS,MAAM;AAC9C;AAOK,MAAM,WAAW,MAAsB,CAAC,KAAK,KAAK,SAAS;AAEhE,QAAM,eAAe,IAAI,UAAU,UAAU;AAE7C,QAAM,eAAe,IAAI,UAAU,UAAU;AAG7C,QAAM,oBAA4C,CAAC;AAGnD,MAAI,OAAO,OAAO,IAAI,YAAY,UAAU;AAE1C,eAAW,OAAO,IAAI,SAAS;AAC7B,UAAI,OAAO,IAAI,QAAQ,GAAG,MAAM,UAAU;AACxC,0BAAkB,GAAG,IAAI,IAAI,QAAQ,GAAG;AAAA,MAC1C;AAAA,IACF;AAAA,EACF;AAEA,QAAM,iBAAiB;AAAA,IACrB;AAAA,IACA,qBAAqB;AAAA,IACrB,qBAAqB;AAAA,EACvB;AAEA,MAAI,OAAO,gBAAgB;AAC3B,MAAI,OAAO,gBAAgB;AAC3B,MAAI,OAAO,kBAAkB;AAC7B,MAAI,OAAO,SAAS,gBAAgB,gBAAgB;AACpD,MAAI,OAAO,gBAAgB,qBAAqB;AAEhD,QAAMA,KAAI,kBAAkB,KAAK,KAAK,IAAI;AAC1C,MAAI,OAAO,IAAIA;AAEf,eAAa,IAAI,MAAM;AACrB,iBAAa,IAAI,KAAKA,EAAC;AAEvB,SAAK;AAAA,EACP,CAAC;AACH;AAIO,MAAM,IAAI,CAAmB,YAClC,aAAa,IAAI,GAAG,EAAE,OAAO;","names":["t"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { createModuleAugmentation } from '@intlayer/chokidar';\nimport { type Locales, getConfiguration } from '@intlayer/config';\nimport { getTranslationContent, localeDetector } from '@intlayer/core';\nimport { createNamespace } from 'cls-hooked';\nimport type { NextFunction, RequestHandler, Request, Response } from 'express';\nimport { type IConfigLocales } from 'intlayer';\n\nconst { middleware, internationalization } = getConfiguration({\n verbose: true,\n});\nconst { headerName, cookieName } = middleware;\n\nconst appNamespace = createNamespace('app');\n\ncreateModuleAugmentation();\n\nexport const translateFunction =\n (_req: Request, res: Response, _next?: NextFunction) =>\n <T extends string>(\n content: IConfigLocales<T> | string,\n locale?: Locales\n ): T => {\n const { locale: currentLocale, defaultLocale } = res.locals as {\n locale: Locales;\n defaultLocale: Locales;\n };\n\n const targetLocale = locale ?? currentLocale;\n\n if (typeof content === 'undefined') {\n return '' as unknown as T;\n }\n\n if (typeof content === 'string') {\n return content as unknown as T;\n }\n\n if (\n typeof content?.[targetLocale as unknown as keyof IConfigLocales<T>] ===\n 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof IConfigLocales<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslationContent(content, defaultLocale);\n }\n }\n\n return getTranslationContent(content, targetLocale);\n };\n\n/**\n * Detect locale used by the user and load it into res locale storage\n *\n * @returns\n */\nexport const intlayer = (): RequestHandler => (req, res, next) => {\n // Detect if locale is set by intlayer frontend lib in the cookies\n const localeCookie = req.cookies?.[cookieName];\n // Detect if locale is set by intlayer frontend lib in the headers\n const localeHeader = req.headers?.[headerName];\n // Interpret browser locale\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // // Check if req.headers exists and is an object\n if (req && typeof req.headers === 'object') {\n // Copy all headers from the request to negotiatorHeaders\n for (const key in req.headers) {\n if (typeof req.headers[key] === 'string') {\n negotiatorHeaders[key] = req.headers[key];\n }\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n res.locals.locale_header = localeHeader;\n res.locals.locale_cookie = localeCookie;\n res.locals.locale_detected = localeDetected;\n res.locals.locale = localeCookie ?? localeHeader ?? localeDetected;\n res.locals.defaultLocale = internationalization.defaultLocale;\n\n const t = translateFunction(req, res, next);\n res.locals.t = t;\n\n appNamespace.run(() => {\n appNamespace.set('t', t);\n\n next();\n });\n};\n\ntype LanguageContent<Content = string> = IConfigLocales<Content>;\n\nexport const t = <Content = string>(\n content: LanguageContent<Content>,\n locale?: Locales\n): Content => appNamespace.get('t')(content, locale);\n\nexport { LanguageContent };\n"],"mappings":"AAAA,SAAS,gCAAgC;AACzC,SAAuB,wBAAwB;AAC/C,SAAS,uBAAuB,sBAAsB;AACtD,SAAS,uBAAuB;AAIhC,MAAM,EAAE,YAAY,qBAAqB,IAAI,iBAAiB;AAAA,EAC5D,SAAS;AACX,CAAC;AACD,MAAM,EAAE,YAAY,WAAW,IAAI;AAEnC,MAAM,eAAe,gBAAgB,KAAK;AAE1C,yBAAyB;AAElB,MAAM,oBACX,CAAC,MAAe,KAAe,UAC/B,CACE,SACA,WACM;AACN,QAAM,EAAE,QAAQ,eAAe,cAAc,IAAI,IAAI;AAKrD,QAAM,eAAe,UAAU;AAE/B,MAAI,OAAO,YAAY,aAAa;AAClC,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AAEA,MACE,OAAO,UAAU,YAAkD,MACnE,aACA;AACA,QACE,OAAO,UACL,aACF,MAAM,aACN;AACA,aAAO;AAAA,IACT,OAAO;AACL,aAAO,sBAAsB,SAAS,aAAa;AAAA,IACrD;AAAA,EACF;AAEA,SAAO,sBAAsB,SAAS,YAAY;AACpD;AAOK,MAAM,WAAW,MAAsB,CAAC,KAAK,KAAK,SAAS;AAEhE,QAAM,eAAe,IAAI,UAAU,UAAU;AAE7C,QAAM,eAAe,IAAI,UAAU,UAAU;AAG7C,QAAM,oBAA4C,CAAC;AAGnD,MAAI,OAAO,OAAO,IAAI,YAAY,UAAU;AAE1C,eAAW,OAAO,IAAI,SAAS;AAC7B,UAAI,OAAO,IAAI,QAAQ,GAAG,MAAM,UAAU;AACxC,0BAAkB,GAAG,IAAI,IAAI,QAAQ,GAAG;AAAA,MAC1C;AAAA,IACF;AAAA,EACF;AAEA,QAAM,iBAAiB;AAAA,IACrB;AAAA,IACA,qBAAqB;AAAA,IACrB,qBAAqB;AAAA,EACvB;AAEA,MAAI,OAAO,gBAAgB;AAC3B,MAAI,OAAO,gBAAgB;AAC3B,MAAI,OAAO,kBAAkB;AAC7B,MAAI,OAAO,SAAS,gBAAgB,gBAAgB;AACpD,MAAI,OAAO,gBAAgB,qBAAqB;AAEhD,QAAMA,KAAI,kBAAkB,KAAK,KAAK,IAAI;AAC1C,MAAI,OAAO,IAAIA;AAEf,eAAa,IAAI,MAAM;AACrB,iBAAa,IAAI,KAAKA,EAAC;AAEvB,SAAK;AAAA,EACP,CAAC;AACH;AAIO,MAAM,IAAI,CACf,SACA,WACY,aAAa,IAAI,GAAG,EAAE,SAAS,MAAM;","names":["t"]}
@@ -1,6 +1,7 @@
1
+ import { type Locales } from '@intlayer/config';
1
2
  import type { NextFunction, RequestHandler, Request, Response } from 'express';
2
3
  import { type IConfigLocales } from 'intlayer';
3
- export declare const translateFunction: (_req: Request, res: Response, _next?: NextFunction) => <T extends string>(content: IConfigLocales<T>) => T;
4
+ export declare const translateFunction: (_req: Request, res: Response, _next?: NextFunction) => <T extends string>(content: IConfigLocales<T> | string, locale?: Locales) => T;
4
5
  /**
5
6
  * Detect locale used by the user and load it into res locale storage
6
7
  *
@@ -8,6 +9,6 @@ export declare const translateFunction: (_req: Request, res: Response, _next?: N
8
9
  */
9
10
  export declare const intlayer: () => RequestHandler;
10
11
  type LanguageContent<Content = string> = IConfigLocales<Content>;
11
- export declare const t: <Content = string>(content: LanguageContent<Content>) => any;
12
+ export declare const t: <Content = string>(content: LanguageContent<Content>, locale?: Locales) => Content;
12
13
  export { LanguageContent };
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAW/C,eAAO,MAAM,iBAAiB,SACrB,OAAO,OAAO,QAAQ,UAAU,YAAY,MAClD,CAAC,SAAS,MAAM,WAAW,cAAc,CAAC,CAAC,CAAC,KAAG,CAqB/C,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,QAAQ,QAAO,cAuC3B,CAAC;AAEF,KAAK,eAAe,CAAC,OAAO,GAAG,MAAM,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;AAEjE,eAAO,MAAM,CAAC,GAAI,OAAO,oBAAoB,eAAe,CAAC,OAAO,CAAC,QACrC,CAAC;AAEjC,OAAO,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,OAAO,EAAoB,MAAM,kBAAkB,CAAC;AAGlE,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAW/C,eAAO,MAAM,iBAAiB,SACrB,OAAO,OAAO,QAAQ,UAAU,YAAY,MAClD,CAAC,SAAS,MAAM,WACN,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,WAC1B,OAAO,KACf,CAgCF,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,QAAQ,QAAO,cAuC3B,CAAC;AAEF,KAAK,eAAe,CAAC,OAAO,GAAG,MAAM,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;AAEjE,eAAO,MAAM,CAAC,GAAI,OAAO,oBACd,eAAe,CAAC,OAAO,CAAC,WACxB,OAAO,KACf,OAAiD,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-intlayer",
3
- "version": "3.1.0",
3
+ "version": "3.2.1",
4
4
  "private": false,
5
5
  "description": "Manage internationalization in a simple way for express application.",
6
6
  "keywords": [
@@ -62,10 +62,10 @@
62
62
  "dependencies": {
63
63
  "cls-hooked": "^4.2.2",
64
64
  "webpack": "^5.96.1",
65
- "@intlayer/core": "^3.1.0",
66
- "@intlayer/config": "^3.1.0",
67
- "intlayer": "^3.1.0",
68
- "@intlayer/chokidar": "^3.1.0"
65
+ "@intlayer/core": "^3.2.1",
66
+ "intlayer": "^3.2.1",
67
+ "@intlayer/config": "^3.2.1",
68
+ "@intlayer/chokidar": "^3.2.1"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@changesets/changelog-github": "0.5.0",
@@ -82,9 +82,15 @@
82
82
  "tsup": "^8.3.5",
83
83
  "typescript": "^5.6.3",
84
84
  "@utils/eslint-config": "^1.0.4",
85
- "@utils/ts-config": "^1.0.4",
85
+ "@utils/tsup-config": "^1.0.4",
86
86
  "@utils/ts-config-types": "^1.0.4",
87
- "@utils/tsup-config": "^1.0.4"
87
+ "@utils/ts-config": "^1.0.4"
88
+ },
89
+ "peerDependencies": {
90
+ "@intlayer/chokidar": "^3.2.1",
91
+ "@intlayer/config": "^3.2.1",
92
+ "intlayer": "^3.2.1",
93
+ "@intlayer/core": "^3.2.1"
88
94
  },
89
95
  "engines": {
90
96
  "node": ">=14.18"