adonis-intlayer 8.4.4 → 8.4.5

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.
@@ -1 +1,105 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./src-Bv4HbqwH.cjs`);exports.IntlayerMiddleware=e.c,exports.appNamespace=e.t,exports.getDictionary=e.n,exports.getIntlayer=e.r,exports.getLocale=e.i,exports.getStorageLocale=e.a,exports.t=e.o,exports.translateFunction=e.s;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_middleware = require('./middleware.cjs');
3
+ let _intlayer_chokidar_build = require("@intlayer/chokidar/build");
4
+ let _intlayer_config_node = require("@intlayer/config/node");
5
+ let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
6
+ let _intlayer_core_utils = require("@intlayer/core/utils");
7
+ let cls_hooked = require("cls-hooked");
8
+
9
+ //#region src/index.ts
10
+ const configuration = (0, _intlayer_config_node.getConfiguration)();
11
+ const { internationalization } = configuration;
12
+ const appNamespace = (0, cls_hooked.createNamespace)("app");
13
+ (0, _intlayer_chokidar_build.prepareIntlayer)(configuration);
14
+ /**
15
+ * Retrieves the locale from storage (cookies, headers).
16
+ */
17
+ const getStorageLocale = (ctx) => (0, _intlayer_core_utils.getLocaleFromStorage)({
18
+ getCookie: (name) => ctx.request.cookie(name),
19
+ getHeader: (name) => ctx.request.header(name)
20
+ });
21
+ /**
22
+ * Translation function for context
23
+ */
24
+ const translateFunction = (ctx) => (content, locale) => {
25
+ const { locale: currentLocale, defaultLocale } = ctx;
26
+ const targetLocale = locale ?? currentLocale;
27
+ if (typeof content === "undefined") return "";
28
+ if (typeof content === "string") return content;
29
+ if (typeof content?.[targetLocale] === "undefined") if (typeof content?.[defaultLocale] === "undefined") return content;
30
+ else return (0, _intlayer_core_interpreter.getTranslation)(content, defaultLocale);
31
+ return (0, _intlayer_core_interpreter.getTranslation)(content, targetLocale);
32
+ };
33
+ /**
34
+ * Translation function to retrieve content for the current locale.
35
+ *
36
+ * This function works within the request lifecycle managed by the `intlayer` middleware.
37
+ *
38
+ * @param content - A map of locales to content.
39
+ * @param locale - Optional locale override.
40
+ * @returns The translated content.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { t } from 'adonis-intlayer';
45
+ *
46
+ * router.get('/', async () => {
47
+ * const greeting = t({
48
+ * en: 'Hello',
49
+ * fr: 'Bonjour',
50
+ * });
51
+ * return greeting;
52
+ * });
53
+ * ```
54
+ */
55
+ const t = (content, locale) => {
56
+ try {
57
+ if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");
58
+ if (typeof appNamespace.get("t") !== "function") throw new Error("Using the import { t } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.");
59
+ return appNamespace.get("t")(content, locale);
60
+ } catch (error) {
61
+ if (process.env.NODE_ENV === "development") console.error(error.message);
62
+ return (0, _intlayer_core_interpreter.getTranslation)(content, locale ?? internationalization.defaultLocale);
63
+ }
64
+ };
65
+ const getIntlayer = ((key, localeArg, ...props) => {
66
+ try {
67
+ if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");
68
+ const getIntlayerWrapped = appNamespace.get("getIntlayer");
69
+ if (typeof getIntlayerWrapped !== "function") throw new Error("Using the import { getIntlayer } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.");
70
+ return getIntlayerWrapped(key, localeArg, ...props);
71
+ } catch (error) {
72
+ if (process.env.NODE_ENV === "development") console.error(error.message);
73
+ return getIntlayerFunction(key, localeArg, ...props);
74
+ }
75
+ });
76
+ const getDictionary = ((key, localeArg, ...props) => {
77
+ try {
78
+ if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");
79
+ const getDictionaryWrapped = appNamespace.get("getDictionary");
80
+ if (typeof getDictionaryWrapped !== "function") throw new Error("Using the import { getDictionary } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.");
81
+ return getDictionaryWrapped(key, localeArg, ...props);
82
+ } catch (error) {
83
+ if (process.env.NODE_ENV === "development") console.error(error.message);
84
+ return (0, _intlayer_core_interpreter.getDictionary)(key, localeArg, ...props);
85
+ }
86
+ });
87
+ const getLocale = (locale) => {
88
+ try {
89
+ if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");
90
+ return appNamespace.get("locale") ?? locale ?? internationalization.defaultLocale;
91
+ } catch (_error) {
92
+ return locale ?? internationalization.defaultLocale;
93
+ }
94
+ };
95
+
96
+ //#endregion
97
+ exports.IntlayerMiddleware = require_middleware;
98
+ exports.appNamespace = appNamespace;
99
+ exports.getDictionary = getDictionary;
100
+ exports.getIntlayer = getIntlayer;
101
+ exports.getLocale = getLocale;
102
+ exports.getStorageLocale = getStorageLocale;
103
+ exports.t = t;
104
+ exports.translateFunction = translateFunction;
105
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import type { HttpContext } from '@adonisjs/core/http';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { getIntlayer as getIntlayerFunction } from '@intlayer/core/interpreter';\nimport {\n getDictionary as getDictionaryFunction,\n getTranslation,\n} from '@intlayer/core/interpreter';\nimport { getLocaleFromStorage } from '@intlayer/core/utils';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { createNamespace } from 'cls-hooked';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\nexport const appNamespace = createNamespace('app');\n\nprepareIntlayer(configuration);\n\n/**\n * Retrieves the locale from storage (cookies, headers).\n */\nexport const getStorageLocale = (ctx: HttpContext): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => ctx.request.cookie(name),\n getHeader: (name: string) => ctx.request.header(name),\n });\n\n/**\n * Translation function for context\n */\nexport const translateFunction =\n (ctx: HttpContext) =>\n <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ): T => {\n const { locale: currentLocale, defaultLocale } = ctx as unknown as {\n locale: Locale;\n defaultLocale: Locale;\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?.[\n targetLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslation(content, defaultLocale);\n }\n }\n\n return getTranslation(content, targetLocale);\n };\n\n/**\n * Translation function to retrieve content for the current locale.\n *\n * This function works within the request lifecycle managed by the `intlayer` middleware.\n *\n * @param content - A map of locales to content.\n * @param locale - Optional locale override.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * import { t } from 'adonis-intlayer';\n *\n * router.get('/', async () => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * });\n * return greeting;\n * });\n * ```\n */\nexport const t = <Content = string>(\n content: StrictModeLocaleMap<Content>,\n locale?: Locale\n): Content => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n if (typeof appNamespace.get('t') !== 'function') {\n throw new Error(\n 'Using the import { t } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return appNamespace.get('t')(content, locale);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n\n return getTranslation(\n content,\n locale ?? internationalization.defaultLocale\n );\n }\n};\n\nexport const getIntlayer: typeof getIntlayerFunction = ((\n key: any,\n localeArg?: any,\n ...props: any[]\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n const getIntlayerWrapped = appNamespace.get('getIntlayer');\n\n if (typeof getIntlayerWrapped !== 'function') {\n throw new Error(\n 'Using the import { getIntlayer } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return getIntlayerWrapped(key, localeArg, ...props);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getIntlayerFunction(key, localeArg, ...props);\n }\n}) as typeof getIntlayerFunction;\n\nexport const getDictionary: typeof getDictionaryFunction = ((\n key: any,\n localeArg?: any,\n ...props: any[]\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n const getDictionaryWrapped = appNamespace.get('getDictionary');\n\n if (typeof getDictionaryWrapped !== 'function') {\n throw new Error(\n 'Using the import { getDictionary } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return getDictionaryWrapped(key, localeArg, ...props);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getDictionaryFunction(key, localeArg, ...props);\n }\n}) as typeof getDictionaryFunction;\n\nexport const getLocale = (locale?: Locale): Locale => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n return (\n appNamespace.get('locale') ?? locale ?? internationalization.defaultLocale\n );\n } catch (_error) {\n return locale ?? internationalization.defaultLocale;\n }\n};\n\nexport { default as IntlayerMiddleware } from './middleware';\n"],"mappings":";;;;;;;;;AAaA,MAAM,6DAAkC;AACxC,MAAM,EAAE,yBAAyB;AAEjC,MAAa,+CAA+B,MAAM;8CAElC,cAAc;;;;AAK9B,MAAa,oBAAoB,uD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,wGACD;EAGH,MAAM,uBAAuB,aAAa,IAAI,gBAAgB;AAE9D,MAAI,OAAO,yBAAyB,WAClC,OAAM,IAAI,MACR,6IACD;AAGH,SAAO,qBAAqB,KAAK,WAAW,GAAG,MAAM;UAC9C,OAAO;AACd,MAAI,QAAQ,IAAI,aAAa,cAC3B,SAAQ,MAAO,MAAgB,QAAQ;AAEzC,uDAA6B,KAAK,WAAW,GAAG,MAAM;;;AAI1D,MAAa,aAAa,WAA4B;AACpD,KAAI;AACF,MAAI,OAAO,iBAAiB,YAC1B,OAAM,IAAI,MACR,wGACD;AAGH,SACE,aAAa,IAAI,SAAS,IAAI,UAAU,qBAAqB;UAExD,QAAQ;AACf,SAAO,UAAU,qBAAqB"}
@@ -1 +1,39 @@
1
- const e=require(`./src-Bv4HbqwH.cjs`);module.exports=e.c;
1
+ const require_index = require('./index.cjs');
2
+ let _intlayer_config_node = require("@intlayer/config/node");
3
+ let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
4
+
5
+ //#region src/middleware.ts
6
+ const { internationalization } = (0, _intlayer_config_node.getConfiguration)();
7
+ /**
8
+ * AdonisJS middleware that detects the user's locale and populates the context with Intlayer data.
9
+ */
10
+ var IntlayerMiddleware = class {
11
+ async handle(ctx, next) {
12
+ const localeFromStorage = require_index.getStorageLocale(ctx);
13
+ const negotiatorHeaders = {};
14
+ const headers = ctx.request.headers();
15
+ for (const key in headers) {
16
+ const val = headers[key];
17
+ if (typeof val === "string") negotiatorHeaders[key] = val;
18
+ else if (Array.isArray(val)) negotiatorHeaders[key] = val.join(",");
19
+ }
20
+ const localeDetected = localeDetector(negotiatorHeaders, internationalization.locales, internationalization.defaultLocale);
21
+ const locale = localeFromStorage ?? localeDetected;
22
+ ctx.locale = locale;
23
+ ctx.defaultLocale = internationalization.defaultLocale;
24
+ const t = require_index.translateFunction(ctx);
25
+ const getIntlayer = (key, localeArg = locale, ...props) => (0, _intlayer_core_interpreter.getIntlayer)(key, localeArg, ...props);
26
+ const getDictionary = (key, localeArg = locale, ...props) => (0, _intlayer_core_interpreter.getDictionary)(key, localeArg, ...props);
27
+ await require_index.appNamespace.runPromise(async () => {
28
+ require_index.appNamespace.set("locale", locale);
29
+ require_index.appNamespace.set("t", t);
30
+ require_index.appNamespace.set("getIntlayer", getIntlayer);
31
+ require_index.appNamespace.set("getDictionary", getDictionary);
32
+ await next();
33
+ });
34
+ }
35
+ };
36
+
37
+ //#endregion
38
+ module.exports = IntlayerMiddleware;
39
+ //# sourceMappingURL=middleware.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.cjs","names":["getStorageLocale","translateFunction","appNamespace"],"sources":["../../src/middleware.ts"],"sourcesContent":["import type { HttpContext } from '@adonisjs/core/http';\nimport type { NextFn } from '@adonisjs/core/types/http';\nimport { getConfiguration } from '@intlayer/config/node';\nimport {\n getDictionary as getDictionaryFunction,\n getIntlayer as getIntlayerFunction,\n} from '@intlayer/core/interpreter';\nimport { appNamespace, getStorageLocale, translateFunction } from './index';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\n/**\n * AdonisJS middleware that detects the user's locale and populates the context with Intlayer data.\n */\nexport default class IntlayerMiddleware {\n async handle(ctx: HttpContext, next: NextFn) {\n // Detect if locale is set by intlayer frontend lib in the headers or cookies\n const localeFromStorage = getStorageLocale(ctx);\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // Copy all headers from the request to negotiatorHeaders\n const headers = ctx.request.headers();\n for (const key in headers) {\n const val = headers[key];\n if (typeof val === 'string') {\n negotiatorHeaders[key] = val;\n } else if (Array.isArray(val)) {\n negotiatorHeaders[key] = val.join(',');\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n const locale = localeFromStorage ?? localeDetected;\n\n // Decorate context\n (ctx as any).locale = locale;\n (ctx as any).defaultLocale = internationalization.defaultLocale;\n\n const t = translateFunction(ctx);\n\n const getIntlayer: typeof getIntlayerFunction = (\n key,\n localeArg = locale as Parameters<typeof getIntlayerFunction>[1],\n ...props\n ) => getIntlayerFunction(key, localeArg, ...props);\n\n const getDictionary: typeof getDictionaryFunction = (\n key,\n localeArg = locale as Parameters<typeof getDictionaryFunction>[1],\n ...props\n ) => getDictionaryFunction(key, localeArg, ...props);\n\n // Make functions available via CLS\n await appNamespace.runPromise(async () => {\n appNamespace.set('locale', locale);\n appNamespace.set('t', t);\n appNamespace.set('getIntlayer', getIntlayer);\n appNamespace.set('getDictionary', getDictionary);\n\n await next();\n });\n }\n}\n"],"mappings":";;;;;AAUA,MAAM,EAAE,sEADgC;;;;AAMxC,IAAqB,qBAArB,MAAwC;CACtC,MAAM,OAAO,KAAkB,MAAc;EAE3C,MAAM,oBAAoBA,+BAAiB,IAAI;EAE/C,MAAM,oBAA4C,EAAE;EAGpD,MAAM,UAAU,IAAI,QAAQ,SAAS;AACrC,OAAK,MAAM,OAAO,SAAS;GACzB,MAAM,MAAM,QAAQ;AACpB,OAAI,OAAO,QAAQ,SACjB,mBAAkB,OAAO;YAChB,MAAM,QAAQ,IAAI,CAC3B,mBAAkB,OAAO,IAAI,KAAK,IAAI;;EAI1C,MAAM,iBAAiB,eACrB,mBACA,qBAAqB,SACrB,qBAAqB,cACtB;EAED,MAAM,SAAS,qBAAqB;AAGpC,EAAC,IAAY,SAAS;AACtB,EAAC,IAAY,gBAAgB,qBAAqB;EAElD,MAAM,IAAIC,gCAAkB,IAAI;EAEhC,MAAM,eACJ,KACA,YAAY,QACZ,GAAG,sDACoB,KAAK,WAAW,GAAG,MAAM;EAElD,MAAM,iBACJ,KACA,YAAY,QACZ,GAAG,wDACsB,KAAK,WAAW,GAAG,MAAM;AAGpD,QAAMC,2BAAa,WAAW,YAAY;AACxC,8BAAa,IAAI,UAAU,OAAO;AAClC,8BAAa,IAAI,KAAK,EAAE;AACxB,8BAAa,IAAI,eAAe,YAAY;AAC5C,8BAAa,IAAI,iBAAiB,cAAc;AAEhD,SAAM,MAAM;IACZ"}
@@ -1 +1,97 @@
1
- import{a as e,c as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./src-BuVkT2g5.mjs";export{t as IntlayerMiddleware,s as appNamespace,r as getDictionary,a as getIntlayer,n as getLocale,e as getStorageLocale,i as t,o as translateFunction};
1
+ import IntlayerMiddleware from "./middleware.mjs";
2
+ import { prepareIntlayer } from "@intlayer/chokidar/build";
3
+ import { getConfiguration } from "@intlayer/config/node";
4
+ import { getDictionary as getDictionary$1, getTranslation } from "@intlayer/core/interpreter";
5
+ import { getLocaleFromStorage } from "@intlayer/core/utils";
6
+ import { createNamespace } from "cls-hooked";
7
+
8
+ //#region src/index.ts
9
+ const configuration = getConfiguration();
10
+ const { internationalization } = configuration;
11
+ const appNamespace = createNamespace("app");
12
+ prepareIntlayer(configuration);
13
+ /**
14
+ * Retrieves the locale from storage (cookies, headers).
15
+ */
16
+ const getStorageLocale = (ctx) => getLocaleFromStorage({
17
+ getCookie: (name) => ctx.request.cookie(name),
18
+ getHeader: (name) => ctx.request.header(name)
19
+ });
20
+ /**
21
+ * Translation function for context
22
+ */
23
+ const translateFunction = (ctx) => (content, locale) => {
24
+ const { locale: currentLocale, defaultLocale } = ctx;
25
+ const targetLocale = locale ?? currentLocale;
26
+ if (typeof content === "undefined") return "";
27
+ if (typeof content === "string") return content;
28
+ if (typeof content?.[targetLocale] === "undefined") if (typeof content?.[defaultLocale] === "undefined") return content;
29
+ else return getTranslation(content, defaultLocale);
30
+ return getTranslation(content, targetLocale);
31
+ };
32
+ /**
33
+ * Translation function to retrieve content for the current locale.
34
+ *
35
+ * This function works within the request lifecycle managed by the `intlayer` middleware.
36
+ *
37
+ * @param content - A map of locales to content.
38
+ * @param locale - Optional locale override.
39
+ * @returns The translated content.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import { t } from 'adonis-intlayer';
44
+ *
45
+ * router.get('/', async () => {
46
+ * const greeting = t({
47
+ * en: 'Hello',
48
+ * fr: 'Bonjour',
49
+ * });
50
+ * return greeting;
51
+ * });
52
+ * ```
53
+ */
54
+ const t = (content, locale) => {
55
+ try {
56
+ if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");
57
+ if (typeof appNamespace.get("t") !== "function") throw new Error("Using the import { t } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.");
58
+ return appNamespace.get("t")(content, locale);
59
+ } catch (error) {
60
+ console.error(error.message);
61
+ return getTranslation(content, locale ?? internationalization.defaultLocale);
62
+ }
63
+ };
64
+ const getIntlayer = ((key, localeArg, ...props) => {
65
+ try {
66
+ if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");
67
+ const getIntlayerWrapped = appNamespace.get("getIntlayer");
68
+ if (typeof getIntlayerWrapped !== "function") throw new Error("Using the import { getIntlayer } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.");
69
+ return getIntlayerWrapped(key, localeArg, ...props);
70
+ } catch (error) {
71
+ console.error(error.message);
72
+ return getIntlayerFunction(key, localeArg, ...props);
73
+ }
74
+ });
75
+ const getDictionary = ((key, localeArg, ...props) => {
76
+ try {
77
+ if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");
78
+ const getDictionaryWrapped = appNamespace.get("getDictionary");
79
+ if (typeof getDictionaryWrapped !== "function") throw new Error("Using the import { getDictionary } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.");
80
+ return getDictionaryWrapped(key, localeArg, ...props);
81
+ } catch (error) {
82
+ console.error(error.message);
83
+ return getDictionary$1(key, localeArg, ...props);
84
+ }
85
+ });
86
+ const getLocale = (locale) => {
87
+ try {
88
+ if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");
89
+ return appNamespace.get("locale") ?? locale ?? internationalization.defaultLocale;
90
+ } catch (_error) {
91
+ return locale ?? internationalization.defaultLocale;
92
+ }
93
+ };
94
+
95
+ //#endregion
96
+ export { IntlayerMiddleware, appNamespace, getDictionary, getIntlayer, getLocale, getStorageLocale, t, translateFunction };
97
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["getDictionaryFunction"],"sources":["../../src/index.ts"],"sourcesContent":["import type { HttpContext } from '@adonisjs/core/http';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { getIntlayer as getIntlayerFunction } from '@intlayer/core/interpreter';\nimport {\n getDictionary as getDictionaryFunction,\n getTranslation,\n} from '@intlayer/core/interpreter';\nimport { getLocaleFromStorage } from '@intlayer/core/utils';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { createNamespace } from 'cls-hooked';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\nexport const appNamespace = createNamespace('app');\n\nprepareIntlayer(configuration);\n\n/**\n * Retrieves the locale from storage (cookies, headers).\n */\nexport const getStorageLocale = (ctx: HttpContext): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => ctx.request.cookie(name),\n getHeader: (name: string) => ctx.request.header(name),\n });\n\n/**\n * Translation function for context\n */\nexport const translateFunction =\n (ctx: HttpContext) =>\n <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ): T => {\n const { locale: currentLocale, defaultLocale } = ctx as unknown as {\n locale: Locale;\n defaultLocale: Locale;\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?.[\n targetLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslation(content, defaultLocale);\n }\n }\n\n return getTranslation(content, targetLocale);\n };\n\n/**\n * Translation function to retrieve content for the current locale.\n *\n * This function works within the request lifecycle managed by the `intlayer` middleware.\n *\n * @param content - A map of locales to content.\n * @param locale - Optional locale override.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * import { t } from 'adonis-intlayer';\n *\n * router.get('/', async () => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * });\n * return greeting;\n * });\n * ```\n */\nexport const t = <Content = string>(\n content: StrictModeLocaleMap<Content>,\n locale?: Locale\n): Content => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n if (typeof appNamespace.get('t') !== 'function') {\n throw new Error(\n 'Using the import { t } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return appNamespace.get('t')(content, locale);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n\n return getTranslation(\n content,\n locale ?? internationalization.defaultLocale\n );\n }\n};\n\nexport const getIntlayer: typeof getIntlayerFunction = ((\n key: any,\n localeArg?: any,\n ...props: any[]\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n const getIntlayerWrapped = appNamespace.get('getIntlayer');\n\n if (typeof getIntlayerWrapped !== 'function') {\n throw new Error(\n 'Using the import { getIntlayer } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return getIntlayerWrapped(key, localeArg, ...props);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getIntlayerFunction(key, localeArg, ...props);\n }\n}) as typeof getIntlayerFunction;\n\nexport const getDictionary: typeof getDictionaryFunction = ((\n key: any,\n localeArg?: any,\n ...props: any[]\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n const getDictionaryWrapped = appNamespace.get('getDictionary');\n\n if (typeof getDictionaryWrapped !== 'function') {\n throw new Error(\n 'Using the import { getDictionary } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return getDictionaryWrapped(key, localeArg, ...props);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getDictionaryFunction(key, localeArg, ...props);\n }\n}) as typeof getDictionaryFunction;\n\nexport const getLocale = (locale?: Locale): Locale => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n return (\n appNamespace.get('locale') ?? locale ?? internationalization.defaultLocale\n );\n } catch (_error) {\n return locale ?? internationalization.defaultLocale;\n }\n};\n\nexport { default as IntlayerMiddleware } from './middleware';\n"],"mappings":";;;;;;;;AAaA,MAAM,gBAAgB,kBAAkB;AACxC,MAAM,EAAE,yBAAyB;AAEjC,MAAa,eAAe,gBAAgB,MAAM;AAElD,gBAAgB,cAAc;;;;AAK9B,MAAa,oBAAoB,QAC/B,qBAAqB;CACnB,YAAY,SAAiB,IAAI,QAAQ,OAAO,KAAK;CACrD,YAAY,SAAiB,IAAI,QAAQ,OAAO,KAAK;CACtD,CAAC;;;;AAKJ,MAAa,qBACV,SAEC,SACA,WACM;CACN,MAAM,EAAE,QAAQ,eAAe,kBAAkB;CAKjD,MAAM,eAAe,UAAU;AAE/B,KAAI,OAAO,YAAY,YACrB,QAAO;AAGT,KAAI,OAAO,YAAY,SACrB,QAAO;AAGT,KACE,OAAO,UACL,kBACI,YAEN,KACE,OAAO,UACL,mBACI,YAEN,QAAO;KAEP,QAAO,eAAe,SAAS,cAAc;AAIjD,QAAO,eAAe,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;AAyBhD,MAAa,KACX,SACA,WACY;AACZ,KAAI;AACF,MAAI,OAAO,iBAAiB,YAC1B,OAAM,IAAI,MACR,wGACD;AAGH,MAAI,OAAO,aAAa,IAAI,IAAI,KAAK,WACnC,OAAM,IAAI,MACR,iIACD;AAGH,SAAO,aAAa,IAAI,IAAI,CAAC,SAAS,OAAO;UACtC,OAAO;AAEZ,UAAQ,MAAO,MAAgB,QAAQ;AAGzC,SAAO,eACL,SACA,UAAU,qBAAqB,cAChC;;;AAIL,MAAa,gBACX,KACA,WACA,GAAG,UACA;AACH,KAAI;AACF,MAAI,OAAO,iBAAiB,YAC1B,OAAM,IAAI,MACR,wGACD;EAGH,MAAM,qBAAqB,aAAa,IAAI,cAAc;AAE1D,MAAI,OAAO,uBAAuB,WAChC,OAAM,IAAI,MACR,2IACD;AAGH,SAAO,mBAAmB,KAAK,WAAW,GAAG,MAAM;UAC5C,OAAO;AAEZ,UAAQ,MAAO,MAAgB,QAAQ;AAEzC,SAAO,oBAAoB,KAAK,WAAW,GAAG,MAAM;;;AAIxD,MAAa,kBACX,KACA,WACA,GAAG,UACA;AACH,KAAI;AACF,MAAI,OAAO,iBAAiB,YAC1B,OAAM,IAAI,MACR,wGACD;EAGH,MAAM,uBAAuB,aAAa,IAAI,gBAAgB;AAE9D,MAAI,OAAO,yBAAyB,WAClC,OAAM,IAAI,MACR,6IACD;AAGH,SAAO,qBAAqB,KAAK,WAAW,GAAG,MAAM;UAC9C,OAAO;AAEZ,UAAQ,MAAO,MAAgB,QAAQ;AAEzC,SAAOA,gBAAsB,KAAK,WAAW,GAAG,MAAM;;;AAI1D,MAAa,aAAa,WAA4B;AACpD,KAAI;AACF,MAAI,OAAO,iBAAiB,YAC1B,OAAM,IAAI,MACR,wGACD;AAGH,SACE,aAAa,IAAI,SAAS,IAAI,UAAU,qBAAqB;UAExD,QAAQ;AACf,SAAO,UAAU,qBAAqB"}
@@ -1 +1,39 @@
1
- import{c as e}from"./src-BuVkT2g5.mjs";export{e as default};
1
+ import { appNamespace, getStorageLocale, translateFunction } from "./index.mjs";
2
+ import { getConfiguration } from "@intlayer/config/node";
3
+ import { getDictionary, getIntlayer } from "@intlayer/core/interpreter";
4
+
5
+ //#region src/middleware.ts
6
+ const { internationalization } = getConfiguration();
7
+ /**
8
+ * AdonisJS middleware that detects the user's locale and populates the context with Intlayer data.
9
+ */
10
+ var IntlayerMiddleware = class {
11
+ async handle(ctx, next) {
12
+ const localeFromStorage = getStorageLocale(ctx);
13
+ const negotiatorHeaders = {};
14
+ const headers = ctx.request.headers();
15
+ for (const key in headers) {
16
+ const val = headers[key];
17
+ if (typeof val === "string") negotiatorHeaders[key] = val;
18
+ else if (Array.isArray(val)) negotiatorHeaders[key] = val.join(",");
19
+ }
20
+ const localeDetected = localeDetector(negotiatorHeaders, internationalization.locales, internationalization.defaultLocale);
21
+ const locale = localeFromStorage ?? localeDetected;
22
+ ctx.locale = locale;
23
+ ctx.defaultLocale = internationalization.defaultLocale;
24
+ const t = translateFunction(ctx);
25
+ const getIntlayer$1 = (key, localeArg = locale, ...props) => getIntlayer(key, localeArg, ...props);
26
+ const getDictionary$1 = (key, localeArg = locale, ...props) => getDictionary(key, localeArg, ...props);
27
+ await appNamespace.runPromise(async () => {
28
+ appNamespace.set("locale", locale);
29
+ appNamespace.set("t", t);
30
+ appNamespace.set("getIntlayer", getIntlayer$1);
31
+ appNamespace.set("getDictionary", getDictionary$1);
32
+ await next();
33
+ });
34
+ }
35
+ };
36
+
37
+ //#endregion
38
+ export { IntlayerMiddleware as default };
39
+ //# sourceMappingURL=middleware.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.mjs","names":["getIntlayer","getIntlayerFunction","getDictionary","getDictionaryFunction"],"sources":["../../src/middleware.ts"],"sourcesContent":["import type { HttpContext } from '@adonisjs/core/http';\nimport type { NextFn } from '@adonisjs/core/types/http';\nimport { getConfiguration } from '@intlayer/config/node';\nimport {\n getDictionary as getDictionaryFunction,\n getIntlayer as getIntlayerFunction,\n} from '@intlayer/core/interpreter';\nimport { appNamespace, getStorageLocale, translateFunction } from './index';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\n/**\n * AdonisJS middleware that detects the user's locale and populates the context with Intlayer data.\n */\nexport default class IntlayerMiddleware {\n async handle(ctx: HttpContext, next: NextFn) {\n // Detect if locale is set by intlayer frontend lib in the headers or cookies\n const localeFromStorage = getStorageLocale(ctx);\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // Copy all headers from the request to negotiatorHeaders\n const headers = ctx.request.headers();\n for (const key in headers) {\n const val = headers[key];\n if (typeof val === 'string') {\n negotiatorHeaders[key] = val;\n } else if (Array.isArray(val)) {\n negotiatorHeaders[key] = val.join(',');\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n const locale = localeFromStorage ?? localeDetected;\n\n // Decorate context\n (ctx as any).locale = locale;\n (ctx as any).defaultLocale = internationalization.defaultLocale;\n\n const t = translateFunction(ctx);\n\n const getIntlayer: typeof getIntlayerFunction = (\n key,\n localeArg = locale as Parameters<typeof getIntlayerFunction>[1],\n ...props\n ) => getIntlayerFunction(key, localeArg, ...props);\n\n const getDictionary: typeof getDictionaryFunction = (\n key,\n localeArg = locale as Parameters<typeof getDictionaryFunction>[1],\n ...props\n ) => getDictionaryFunction(key, localeArg, ...props);\n\n // Make functions available via CLS\n await appNamespace.runPromise(async () => {\n appNamespace.set('locale', locale);\n appNamespace.set('t', t);\n appNamespace.set('getIntlayer', getIntlayer);\n appNamespace.set('getDictionary', getDictionary);\n\n await next();\n });\n }\n}\n"],"mappings":";;;;;AAUA,MAAM,EAAE,yBADc,kBAAkB;;;;AAMxC,IAAqB,qBAArB,MAAwC;CACtC,MAAM,OAAO,KAAkB,MAAc;EAE3C,MAAM,oBAAoB,iBAAiB,IAAI;EAE/C,MAAM,oBAA4C,EAAE;EAGpD,MAAM,UAAU,IAAI,QAAQ,SAAS;AACrC,OAAK,MAAM,OAAO,SAAS;GACzB,MAAM,MAAM,QAAQ;AACpB,OAAI,OAAO,QAAQ,SACjB,mBAAkB,OAAO;YAChB,MAAM,QAAQ,IAAI,CAC3B,mBAAkB,OAAO,IAAI,KAAK,IAAI;;EAI1C,MAAM,iBAAiB,eACrB,mBACA,qBAAqB,SACrB,qBAAqB,cACtB;EAED,MAAM,SAAS,qBAAqB;AAGpC,EAAC,IAAY,SAAS;AACtB,EAAC,IAAY,gBAAgB,qBAAqB;EAElD,MAAM,IAAI,kBAAkB,IAAI;EAEhC,MAAMA,iBACJ,KACA,YAAY,QACZ,GAAG,UACAC,YAAoB,KAAK,WAAW,GAAG,MAAM;EAElD,MAAMC,mBACJ,KACA,YAAY,QACZ,GAAG,UACAC,cAAsB,KAAK,WAAW,GAAG,MAAM;AAGpD,QAAM,aAAa,WAAW,YAAY;AACxC,gBAAa,IAAI,UAAU,OAAO;AAClC,gBAAa,IAAI,KAAK,EAAE;AACxB,gBAAa,IAAI,eAAeH,cAAY;AAC5C,gBAAa,IAAI,iBAAiBE,gBAAc;AAEhD,SAAM,MAAM;IACZ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adonis-intlayer",
3
- "version": "8.4.4",
3
+ "version": "8.4.5",
4
4
  "private": false,
5
5
  "description": "Manage internationalization i18n in a simple way for AdonisJS application.",
6
6
  "keywords": [
@@ -80,12 +80,12 @@
80
80
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
81
81
  },
82
82
  "dependencies": {
83
- "@intlayer/chokidar": "8.4.4",
84
- "@intlayer/config": "8.4.4",
85
- "@intlayer/core": "8.4.4",
86
- "@intlayer/types": "8.4.4",
83
+ "@intlayer/chokidar": "8.4.5",
84
+ "@intlayer/config": "8.4.5",
85
+ "@intlayer/core": "8.4.5",
86
+ "@intlayer/types": "8.4.5",
87
87
  "cls-hooked": "4.2.2",
88
- "intlayer": "8.4.4"
88
+ "intlayer": "8.4.5"
89
89
  },
90
90
  "devDependencies": {
91
91
  "@adonisjs/core": "6.17.1",
@@ -1,2 +0,0 @@
1
- let e=require(`@intlayer/chokidar/build`),t=require(`@intlayer/config/node`),n=require(`@intlayer/core/interpreter`),r=require(`@intlayer/core/utils`),i=require(`cls-hooked`);const{internationalization:a}=(0,t.getConfiguration)();var o=class{async handle(e,t){let r=u(e),i={},o=e.request.headers();for(let e in o){let t=o[e];typeof t==`string`?i[e]=t:Array.isArray(t)&&(i[e]=t.join(`,`))}let s=localeDetector(i,a.locales,a.defaultLocale),c=r??s;e.locale=c,e.defaultLocale=a.defaultLocale;let f=d(e),p=(e,t=c,...r)=>(0,n.getIntlayer)(e,t,...r),m=(e,t=c,...r)=>(0,n.getDictionary)(e,t,...r);await l.runPromise(async()=>{l.set(`locale`,c),l.set(`t`,f),l.set(`getIntlayer`,p),l.set(`getDictionary`,m),await t()})}};const s=(0,t.getConfiguration)(),{internationalization:c}=s,l=(0,i.createNamespace)(`app`);(0,e.prepareIntlayer)(s);const u=e=>(0,r.getLocaleFromStorage)({getCookie:t=>e.request.cookie(t),getHeader:t=>e.request.header(t)}),d=e=>(t,r)=>{let{locale:i,defaultLocale:a}=e,o=r??i;return t===void 0?``:typeof t==`string`?t:t?.[o]===void 0?t?.[a]===void 0?t:(0,n.getTranslation)(t,a):(0,n.getTranslation)(t,o)},f=(e,t)=>{try{if(l===void 0)throw Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");if(typeof l.get(`t`)!=`function`)throw Error(`Using the import { t } from "adonis-intlayer" is not supported in your environment. Ensure you are within a request context.`);return l.get(`t`)(e,t)}catch(r){return process.env.NODE_ENV===`development`&&console.error(r.message),(0,n.getTranslation)(e,t??c.defaultLocale)}},p=((e,t,...n)=>{try{if(l===void 0)throw Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");let r=l.get(`getIntlayer`);if(typeof r!=`function`)throw Error(`Using the import { getIntlayer } from "adonis-intlayer" is not supported in your environment. Ensure you are within a request context.`);return r(e,t,...n)}catch(r){return process.env.NODE_ENV===`development`&&console.error(r.message),getIntlayerFunction(e,t,...n)}}),m=((e,t,...r)=>{try{if(l===void 0)throw Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");let n=l.get(`getDictionary`);if(typeof n!=`function`)throw Error(`Using the import { getDictionary } from "adonis-intlayer" is not supported in your environment. Ensure you are within a request context.`);return n(e,t,...r)}catch(i){return process.env.NODE_ENV===`development`&&console.error(i.message),(0,n.getDictionary)(e,t,...r)}}),h=e=>{try{if(l===void 0)throw Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");return l.get(`locale`)??e??c.defaultLocale}catch{return e??c.defaultLocale}};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return l}});
2
- //# sourceMappingURL=src-Bv4HbqwH.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"src-Bv4HbqwH.cjs","names":["internationalization"],"sources":["../../src/middleware.ts","../../src/index.ts"],"sourcesContent":["import type { HttpContext } from '@adonisjs/core/http';\nimport type { NextFn } from '@adonisjs/core/types/http';\nimport { getConfiguration } from '@intlayer/config/node';\nimport {\n getDictionary as getDictionaryFunction,\n getIntlayer as getIntlayerFunction,\n} from '@intlayer/core/interpreter';\nimport { appNamespace, getStorageLocale, translateFunction } from './index';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\n/**\n * AdonisJS middleware that detects the user's locale and populates the context with Intlayer data.\n */\nexport default class IntlayerMiddleware {\n async handle(ctx: HttpContext, next: NextFn) {\n // Detect if locale is set by intlayer frontend lib in the headers or cookies\n const localeFromStorage = getStorageLocale(ctx);\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // Copy all headers from the request to negotiatorHeaders\n const headers = ctx.request.headers();\n for (const key in headers) {\n const val = headers[key];\n if (typeof val === 'string') {\n negotiatorHeaders[key] = val;\n } else if (Array.isArray(val)) {\n negotiatorHeaders[key] = val.join(',');\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n const locale = localeFromStorage ?? localeDetected;\n\n // Decorate context\n (ctx as any).locale = locale;\n (ctx as any).defaultLocale = internationalization.defaultLocale;\n\n const t = translateFunction(ctx);\n\n const getIntlayer: typeof getIntlayerFunction = (\n key,\n localeArg = locale as Parameters<typeof getIntlayerFunction>[1],\n ...props\n ) => getIntlayerFunction(key, localeArg, ...props);\n\n const getDictionary: typeof getDictionaryFunction = (\n key,\n localeArg = locale as Parameters<typeof getDictionaryFunction>[1],\n ...props\n ) => getDictionaryFunction(key, localeArg, ...props);\n\n // Make functions available via CLS\n await appNamespace.runPromise(async () => {\n appNamespace.set('locale', locale);\n appNamespace.set('t', t);\n appNamespace.set('getIntlayer', getIntlayer);\n appNamespace.set('getDictionary', getDictionary);\n\n await next();\n });\n }\n}\n","import type { HttpContext } from '@adonisjs/core/http';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { getIntlayer as getIntlayerFunction } from '@intlayer/core/interpreter';\nimport {\n getDictionary as getDictionaryFunction,\n getTranslation,\n} from '@intlayer/core/interpreter';\nimport { getLocaleFromStorage } from '@intlayer/core/utils';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { createNamespace } from 'cls-hooked';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\nexport const appNamespace = createNamespace('app');\n\nprepareIntlayer(configuration);\n\n/**\n * Retrieves the locale from storage (cookies, headers).\n */\nexport const getStorageLocale = (ctx: HttpContext): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => ctx.request.cookie(name),\n getHeader: (name: string) => ctx.request.header(name),\n });\n\n/**\n * Translation function for context\n */\nexport const translateFunction =\n (ctx: HttpContext) =>\n <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ): T => {\n const { locale: currentLocale, defaultLocale } = ctx as unknown as {\n locale: Locale;\n defaultLocale: Locale;\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?.[\n targetLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslation(content, defaultLocale);\n }\n }\n\n return getTranslation(content, targetLocale);\n };\n\n/**\n * Translation function to retrieve content for the current locale.\n *\n * This function works within the request lifecycle managed by the `intlayer` middleware.\n *\n * @param content - A map of locales to content.\n * @param locale - Optional locale override.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * import { t } from 'adonis-intlayer';\n *\n * router.get('/', async () => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * });\n * return greeting;\n * });\n * ```\n */\nexport const t = <Content = string>(\n content: StrictModeLocaleMap<Content>,\n locale?: Locale\n): Content => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n if (typeof appNamespace.get('t') !== 'function') {\n throw new Error(\n 'Using the import { t } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return appNamespace.get('t')(content, locale);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n\n return getTranslation(\n content,\n locale ?? internationalization.defaultLocale\n );\n }\n};\n\nexport const getIntlayer: typeof getIntlayerFunction = ((\n key: any,\n localeArg?: any,\n ...props: any[]\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n const getIntlayerWrapped = appNamespace.get('getIntlayer');\n\n if (typeof getIntlayerWrapped !== 'function') {\n throw new Error(\n 'Using the import { getIntlayer } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return getIntlayerWrapped(key, localeArg, ...props);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getIntlayerFunction(key, localeArg, ...props);\n }\n}) as typeof getIntlayerFunction;\n\nexport const getDictionary: typeof getDictionaryFunction = ((\n key: any,\n localeArg?: any,\n ...props: any[]\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n const getDictionaryWrapped = appNamespace.get('getDictionary');\n\n if (typeof getDictionaryWrapped !== 'function') {\n throw new Error(\n 'Using the import { getDictionary } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return getDictionaryWrapped(key, localeArg, ...props);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getDictionaryFunction(key, localeArg, ...props);\n }\n}) as typeof getDictionaryFunction;\n\nexport const getLocale = (locale?: Locale): Locale => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n return (\n appNamespace.get('locale') ?? locale ?? internationalization.defaultLocale\n );\n } catch (_error) {\n return locale ?? internationalization.defaultLocale;\n }\n};\n\nexport { default as IntlayerMiddleware } from './middleware';\n"],"mappings":"+KAUA,KAAM,CAAE,qBAAA,IAAA,EAAA,EAAA,mBADgC,CAMxC,IAAqB,EAArB,KAAwC,CACtC,MAAM,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ayer as e}from"@intlayer/chokidar/build";import{getConfiguration as t}from"@intlayer/config/node";import{getDictionary as n,getIntlayer as r,getTranslation as i}from"@intlayer/core/interpreter";import{getLocaleFromStorage as a}from"@intlayer/core/utils";import{createNamespace as o}from"cls-hooked";const{internationalization:s}=t();var c=class{async handle(e,t){let i=f(e),a={},o=e.request.headers();for(let e in o){let t=o[e];typeof t==`string`?a[e]=t:Array.isArray(t)&&(a[e]=t.join(`,`))}let c=localeDetector(a,s.locales,s.defaultLocale),l=i??c;e.locale=l,e.defaultLocale=s.defaultLocale;let u=p(e),m=(e,t=l,...n)=>r(e,t,...n),h=(e,t=l,...r)=>n(e,t,...r);await d.runPromise(async()=>{d.set(`locale`,l),d.set(`t`,u),d.set(`getIntlayer`,m),d.set(`getDictionary`,h),await t()})}};const l=t(),{internationalization:u}=l,d=o(`app`);e(l);const f=e=>a({getCookie:t=>e.request.cookie(t),getHeader:t=>e.request.header(t)}),p=e=>(t,n)=>{let{locale:r,defaultLocale:a}=e,o=n??r;return t===void 0?``:typeof t==`string`?t:t?.[o]===void 0?t?.[a]===void 0?t:i(t,a):i(t,o)},m=(e,t)=>{try{if(d===void 0)throw Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");if(typeof d.get(`t`)!=`function`)throw Error(`Using the import { t } from "adonis-intlayer" is not supported in your environment. Ensure you are within a request context.`);return d.get(`t`)(e,t)}catch{return i(e,t??u.defaultLocale)}},h=((e,t,...n)=>{try{if(d===void 0)throw Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");let r=d.get(`getIntlayer`);if(typeof r!=`function`)throw Error(`Using the import { getIntlayer } from "adonis-intlayer" is not supported in your environment. Ensure you are within a request context.`);return r(e,t,...n)}catch{return getIntlayerFunction(e,t,...n)}}),g=((e,t,...r)=>{try{if(d===void 0)throw Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");let n=d.get(`getDictionary`);if(typeof n!=`function`)throw Error(`Using the import { getDictionary } from "adonis-intlayer" is not supported in your environment. Ensure you are within a request context.`);return n(e,t,...r)}catch{return n(e,t,...r)}}),_=e=>{try{if(d===void 0)throw Error("Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.");return d.get(`locale`)??e??u.defaultLocale}catch{return e??u.defaultLocale}};export{f as a,c,_ as i,g as n,m as o,h as r,p as s,d as t};
2
- //# sourceMappingURL=src-BuVkT2g5.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"src-BuVkT2g5.mjs","names":["internationalization","getIntlayer","getIntlayerFunction","getDictionary","getDictionaryFunction","getIntlayer","getDictionary","getDictionaryFunction"],"sources":["../../src/middleware.ts","../../src/index.ts"],"sourcesContent":["import type { HttpContext } from '@adonisjs/core/http';\nimport type { NextFn } from '@adonisjs/core/types/http';\nimport { getConfiguration } from '@intlayer/config/node';\nimport {\n getDictionary as getDictionaryFunction,\n getIntlayer as getIntlayerFunction,\n} from '@intlayer/core/interpreter';\nimport { appNamespace, getStorageLocale, translateFunction } from './index';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\n/**\n * AdonisJS middleware that detects the user's locale and populates the context with Intlayer data.\n */\nexport default class IntlayerMiddleware {\n async handle(ctx: HttpContext, next: NextFn) {\n // Detect if locale is set by intlayer frontend lib in the headers or cookies\n const localeFromStorage = getStorageLocale(ctx);\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // Copy all headers from the request to negotiatorHeaders\n const headers = ctx.request.headers();\n for (const key in headers) {\n const val = headers[key];\n if (typeof val === 'string') {\n negotiatorHeaders[key] = val;\n } else if (Array.isArray(val)) {\n negotiatorHeaders[key] = val.join(',');\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n const locale = localeFromStorage ?? localeDetected;\n\n // Decorate context\n (ctx as any).locale = locale;\n (ctx as any).defaultLocale = internationalization.defaultLocale;\n\n const t = translateFunction(ctx);\n\n const getIntlayer: typeof getIntlayerFunction = (\n key,\n localeArg = locale as Parameters<typeof getIntlayerFunction>[1],\n ...props\n ) => getIntlayerFunction(key, localeArg, ...props);\n\n const getDictionary: typeof getDictionaryFunction = (\n key,\n localeArg = locale as Parameters<typeof getDictionaryFunction>[1],\n ...props\n ) => getDictionaryFunction(key, localeArg, ...props);\n\n // Make functions available via CLS\n await appNamespace.runPromise(async () => {\n appNamespace.set('locale', locale);\n appNamespace.set('t', t);\n appNamespace.set('getIntlayer', getIntlayer);\n appNamespace.set('getDictionary', getDictionary);\n\n await next();\n });\n }\n}\n","import type { HttpContext } from '@adonisjs/core/http';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { getIntlayer as getIntlayerFunction } from '@intlayer/core/interpreter';\nimport {\n getDictionary as getDictionaryFunction,\n getTranslation,\n} from '@intlayer/core/interpreter';\nimport { getLocaleFromStorage } from '@intlayer/core/utils';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { createNamespace } from 'cls-hooked';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\nexport const appNamespace = createNamespace('app');\n\nprepareIntlayer(configuration);\n\n/**\n * Retrieves the locale from storage (cookies, headers).\n */\nexport const getStorageLocale = (ctx: HttpContext): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => ctx.request.cookie(name),\n getHeader: (name: string) => ctx.request.header(name),\n });\n\n/**\n * Translation function for context\n */\nexport const translateFunction =\n (ctx: HttpContext) =>\n <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ): T => {\n const { locale: currentLocale, defaultLocale } = ctx as unknown as {\n locale: Locale;\n defaultLocale: Locale;\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?.[\n targetLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslation(content, defaultLocale);\n }\n }\n\n return getTranslation(content, targetLocale);\n };\n\n/**\n * Translation function to retrieve content for the current locale.\n *\n * This function works within the request lifecycle managed by the `intlayer` middleware.\n *\n * @param content - A map of locales to content.\n * @param locale - Optional locale override.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * import { t } from 'adonis-intlayer';\n *\n * router.get('/', async () => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * });\n * return greeting;\n * });\n * ```\n */\nexport const t = <Content = string>(\n content: StrictModeLocaleMap<Content>,\n locale?: Locale\n): Content => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n if (typeof appNamespace.get('t') !== 'function') {\n throw new Error(\n 'Using the import { t } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return appNamespace.get('t')(content, locale);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n\n return getTranslation(\n content,\n locale ?? internationalization.defaultLocale\n );\n }\n};\n\nexport const getIntlayer: typeof getIntlayerFunction = ((\n key: any,\n localeArg?: any,\n ...props: any[]\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n const getIntlayerWrapped = appNamespace.get('getIntlayer');\n\n if (typeof getIntlayerWrapped !== 'function') {\n throw new Error(\n 'Using the import { getIntlayer } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return getIntlayerWrapped(key, localeArg, ...props);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getIntlayerFunction(key, localeArg, ...props);\n }\n}) as typeof getIntlayerFunction;\n\nexport const getDictionary: typeof getDictionaryFunction = ((\n key: any,\n localeArg?: any,\n ...props: any[]\n) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n const getDictionaryWrapped = appNamespace.get('getDictionary');\n\n if (typeof getDictionaryWrapped !== 'function') {\n throw new Error(\n 'Using the import { getDictionary } from \"adonis-intlayer\" is not supported in your environment. Ensure you are within a request context.'\n );\n }\n\n return getDictionaryWrapped(key, localeArg, ...props);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getDictionaryFunction(key, localeArg, ...props);\n }\n}) as typeof getDictionaryFunction;\n\nexport const getLocale = (locale?: Locale): Locale => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Add the `intlayer` middleware to your kernel before using this function.'\n );\n }\n\n return (\n appNamespace.get('locale') ?? locale ?? internationalization.defaultLocale\n );\n } catch (_error) {\n return locale ?? internationalization.defaultLocale;\n }\n};\n\nexport { default as IntlayerMiddleware } from './middleware';\n"],"mappings":"6TAUA,KAAM,CAAE,qBAAA,GADc,GAAkB,CAMxC,IAAqB,EAArB,KAAwC,CACtC,MAAM,OAAO,EAAkB,EAAc,CAE3C,IAAM,EAAoB,EAAiB,EAAI,CAEzC,EAA4C,EAAE,CAG9C,EAAU,EAAI,QAAQ,SAAS,CACrC,IAAK,IAAM,KAAO,EAAS,CACzB,IAAM,EAAM,EAAQ,GAChB,OAAO,GAAQ,SACjB,EAAkB,GAAO,EAChB,MAAM,QAAQ,EAAI,GAC3B,EAAkB,GAAO,EAAI,KAAK,IAAI,EAI1C,IAAM,EAAiB,eACrB,EACAA,EAAqB,QACrBA,EAAqB,cACtB,CAEK,EAAS,GAAqB,EAGnC,EAAY,OAAS,EACrB,EAAY,cAAgBA,EAAqB,cAElD,IAAM,EAAI,EAAkB,EAAI,CAE1BC,G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