@intlayer/next-intl 8.12.5-canary.0
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.
- package/README.md +330 -0
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/client/NextIntlClientProvider.cjs +28 -0
- package/dist/cjs/client/NextIntlClientProvider.cjs.map +1 -0
- package/dist/cjs/client/helpers.cjs +66 -0
- package/dist/cjs/client/helpers.cjs.map +1 -0
- package/dist/cjs/client/index.cjs +19 -0
- package/dist/cjs/client/useLocale.cjs +18 -0
- package/dist/cjs/client/useLocale.cjs.map +1 -0
- package/dist/cjs/client/useTranslations.cjs +39 -0
- package/dist/cjs/client/useTranslations.cjs.map +1 -0
- package/dist/cjs/createFormatter.cjs +59 -0
- package/dist/cjs/createFormatter.cjs.map +1 -0
- package/dist/cjs/createTranslator.cjs +111 -0
- package/dist/cjs/createTranslator.cjs.map +1 -0
- package/dist/cjs/getDictionary.cjs +45 -0
- package/dist/cjs/getDictionary.cjs.map +1 -0
- package/dist/cjs/getDictionaryDynamic.cjs +35 -0
- package/dist/cjs/getDictionaryDynamic.cjs.map +1 -0
- package/dist/cjs/getTranslationsDictionary.cjs +31 -0
- package/dist/cjs/getTranslationsDictionary.cjs.map +1 -0
- package/dist/cjs/getTranslationsDictionaryDynamic.cjs +27 -0
- package/dist/cjs/getTranslationsDictionaryDynamic.cjs.map +1 -0
- package/dist/cjs/hasLocale.cjs +25 -0
- package/dist/cjs/hasLocale.cjs.map +1 -0
- package/dist/cjs/index.cjs +23 -0
- package/dist/cjs/middleware.cjs +37 -0
- package/dist/cjs/middleware.cjs.map +1 -0
- package/dist/cjs/navigation/Link.cjs +30 -0
- package/dist/cjs/navigation/Link.cjs.map +1 -0
- package/dist/cjs/navigation/createNavigation.cjs +40 -0
- package/dist/cjs/navigation/createNavigation.cjs.map +1 -0
- package/dist/cjs/navigation/hooks.cjs +42 -0
- package/dist/cjs/navigation/hooks.cjs.map +1 -0
- package/dist/cjs/navigation/index.cjs +10 -0
- package/dist/cjs/navigation/localizeHref.cjs +26 -0
- package/dist/cjs/navigation/localizeHref.cjs.map +1 -0
- package/dist/cjs/package.cjs +122 -0
- package/dist/cjs/package.cjs.map +1 -0
- package/dist/cjs/plugin/index.cjs +163 -0
- package/dist/cjs/plugin/index.cjs.map +1 -0
- package/dist/cjs/routing.cjs +30 -0
- package/dist/cjs/routing.cjs.map +1 -0
- package/dist/cjs/server/getLocale.cjs +13 -0
- package/dist/cjs/server/getLocale.cjs.map +1 -0
- package/dist/cjs/server/getMessages.cjs +30 -0
- package/dist/cjs/server/getMessages.cjs.map +1 -0
- package/dist/cjs/server/getTranslations.cjs +45 -0
- package/dist/cjs/server/getTranslations.cjs.map +1 -0
- package/dist/cjs/server/helpers.cjs +28 -0
- package/dist/cjs/server/helpers.cjs.map +1 -0
- package/dist/cjs/server/index.cjs +18 -0
- package/dist/cjs/server/setLocale.cjs +38 -0
- package/dist/cjs/server/setLocale.cjs.map +1 -0
- package/dist/cjs/useDictionary.cjs +45 -0
- package/dist/cjs/useDictionary.cjs.map +1 -0
- package/dist/cjs/useDictionaryDynamic.cjs +37 -0
- package/dist/cjs/useDictionaryDynamic.cjs.map +1 -0
- package/dist/cjs/useTranslationsDictionary.cjs +37 -0
- package/dist/cjs/useTranslationsDictionary.cjs.map +1 -0
- package/dist/cjs/useTranslationsDictionaryDynamic.cjs +29 -0
- package/dist/cjs/useTranslationsDictionaryDynamic.cjs.map +1 -0
- package/dist/esm/_virtual/_rolldown/runtime.mjs +8 -0
- package/dist/esm/client/NextIntlClientProvider.mjs +26 -0
- package/dist/esm/client/NextIntlClientProvider.mjs.map +1 -0
- package/dist/esm/client/helpers.mjs +59 -0
- package/dist/esm/client/helpers.mjs.map +1 -0
- package/dist/esm/client/index.mjs +8 -0
- package/dist/esm/client/useLocale.mjs +16 -0
- package/dist/esm/client/useLocale.mjs.map +1 -0
- package/dist/esm/client/useTranslations.mjs +37 -0
- package/dist/esm/client/useTranslations.mjs.map +1 -0
- package/dist/esm/createFormatter.mjs +57 -0
- package/dist/esm/createFormatter.mjs.map +1 -0
- package/dist/esm/createTranslator.mjs +108 -0
- package/dist/esm/createTranslator.mjs.map +1 -0
- package/dist/esm/getDictionary.mjs +43 -0
- package/dist/esm/getDictionary.mjs.map +1 -0
- package/dist/esm/getDictionaryDynamic.mjs +33 -0
- package/dist/esm/getDictionaryDynamic.mjs.map +1 -0
- package/dist/esm/getTranslationsDictionary.mjs +29 -0
- package/dist/esm/getTranslationsDictionary.mjs.map +1 -0
- package/dist/esm/getTranslationsDictionaryDynamic.mjs +25 -0
- package/dist/esm/getTranslationsDictionaryDynamic.mjs.map +1 -0
- package/dist/esm/hasLocale.mjs +23 -0
- package/dist/esm/hasLocale.mjs.map +1 -0
- package/dist/esm/index.mjs +10 -0
- package/dist/esm/middleware.mjs +34 -0
- package/dist/esm/middleware.mjs.map +1 -0
- package/dist/esm/navigation/Link.mjs +27 -0
- package/dist/esm/navigation/Link.mjs.map +1 -0
- package/dist/esm/navigation/createNavigation.mjs +37 -0
- package/dist/esm/navigation/createNavigation.mjs.map +1 -0
- package/dist/esm/navigation/hooks.mjs +39 -0
- package/dist/esm/navigation/hooks.mjs.map +1 -0
- package/dist/esm/navigation/index.mjs +5 -0
- package/dist/esm/navigation/localizeHref.mjs +24 -0
- package/dist/esm/navigation/localizeHref.mjs.map +1 -0
- package/dist/esm/package.mjs +119 -0
- package/dist/esm/package.mjs.map +1 -0
- package/dist/esm/plugin/index.mjs +159 -0
- package/dist/esm/plugin/index.mjs.map +1 -0
- package/dist/esm/routing.mjs +28 -0
- package/dist/esm/routing.mjs.map +1 -0
- package/dist/esm/server/getLocale.mjs +11 -0
- package/dist/esm/server/getLocale.mjs.map +1 -0
- package/dist/esm/server/getMessages.mjs +28 -0
- package/dist/esm/server/getMessages.mjs.map +1 -0
- package/dist/esm/server/getTranslations.mjs +44 -0
- package/dist/esm/server/getTranslations.mjs.map +1 -0
- package/dist/esm/server/helpers.mjs +25 -0
- package/dist/esm/server/helpers.mjs.map +1 -0
- package/dist/esm/server/index.mjs +9 -0
- package/dist/esm/server/setLocale.mjs +36 -0
- package/dist/esm/server/setLocale.mjs.map +1 -0
- package/dist/esm/useDictionary.mjs +43 -0
- package/dist/esm/useDictionary.mjs.map +1 -0
- package/dist/esm/useDictionaryDynamic.mjs +35 -0
- package/dist/esm/useDictionaryDynamic.mjs.map +1 -0
- package/dist/esm/useTranslationsDictionary.mjs +35 -0
- package/dist/esm/useTranslationsDictionary.mjs.map +1 -0
- package/dist/esm/useTranslationsDictionaryDynamic.mjs +27 -0
- package/dist/esm/useTranslationsDictionaryDynamic.mjs.map +1 -0
- package/dist/types/client/NextIntlClientProvider.d.ts +28 -0
- package/dist/types/client/NextIntlClientProvider.d.ts.map +1 -0
- package/dist/types/client/helpers.d.ts +45 -0
- package/dist/types/client/helpers.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +7 -0
- package/dist/types/client/useLocale.d.ts +10 -0
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/client/useTranslations.d.ts +74 -0
- package/dist/types/client/useTranslations.d.ts.map +1 -0
- package/dist/types/createFormatter.d.ts +15 -0
- package/dist/types/createFormatter.d.ts.map +1 -0
- package/dist/types/createTranslator.d.ts +40 -0
- package/dist/types/createTranslator.d.ts.map +1 -0
- package/dist/types/getDictionary.d.ts +23 -0
- package/dist/types/getDictionary.d.ts.map +1 -0
- package/dist/types/getDictionaryDynamic.d.ts +15 -0
- package/dist/types/getDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/getTranslationsDictionary.d.ts +15 -0
- package/dist/types/getTranslationsDictionary.d.ts.map +1 -0
- package/dist/types/getTranslationsDictionaryDynamic.d.ts +12 -0
- package/dist/types/getTranslationsDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/hasLocale.d.ts +20 -0
- package/dist/types/hasLocale.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/middleware.d.ts +22 -0
- package/dist/types/middleware.d.ts.map +1 -0
- package/dist/types/navigation/Link.d.ts +29 -0
- package/dist/types/navigation/Link.d.ts.map +1 -0
- package/dist/types/navigation/createNavigation.d.ts +21 -0
- package/dist/types/navigation/createNavigation.d.ts.map +1 -0
- package/dist/types/navigation/hooks.d.ts +33 -0
- package/dist/types/navigation/hooks.d.ts.map +1 -0
- package/dist/types/navigation/index.d.ts +5 -0
- package/dist/types/navigation/localizeHref.d.ts +23 -0
- package/dist/types/navigation/localizeHref.d.ts.map +1 -0
- package/dist/types/plugin/index.d.ts +12 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/routing.d.ts +28 -0
- package/dist/types/routing.d.ts.map +1 -0
- package/dist/types/server/getLocale.d.ts +10 -0
- package/dist/types/server/getLocale.d.ts.map +1 -0
- package/dist/types/server/getMessages.d.ts +22 -0
- package/dist/types/server/getMessages.d.ts.map +1 -0
- package/dist/types/server/getTranslations.d.ts +85 -0
- package/dist/types/server/getTranslations.d.ts.map +1 -0
- package/dist/types/server/helpers.d.ts +21 -0
- package/dist/types/server/helpers.d.ts.map +1 -0
- package/dist/types/server/index.d.ts +8 -0
- package/dist/types/server/setLocale.d.ts +21 -0
- package/dist/types/server/setLocale.d.ts.map +1 -0
- package/dist/types/useDictionary.d.ts +22 -0
- package/dist/types/useDictionary.d.ts.map +1 -0
- package/dist/types/useDictionaryDynamic.d.ts +15 -0
- package/dist/types/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/useTranslationsDictionary.d.ts +19 -0
- package/dist/types/useTranslationsDictionary.d.ts.map +1 -0
- package/dist/types/useTranslationsDictionaryDynamic.d.ts +12 -0
- package/dist/types/useTranslationsDictionaryDynamic.d.ts.map +1 -0
- package/package.json +142 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
4
|
+
|
|
5
|
+
//#region src/navigation/localizeHref.ts
|
|
6
|
+
/**
|
|
7
|
+
* Prefix a `next-intl` href with the given locale using Intlayer's
|
|
8
|
+
* `getLocalizedUrl`, preserving any query parameters.
|
|
9
|
+
*
|
|
10
|
+
* @param href - The target href (string or `{ pathname, query }`).
|
|
11
|
+
* @param locale - The locale to localize the href for.
|
|
12
|
+
* @returns The localized URL string.
|
|
13
|
+
*/
|
|
14
|
+
const localizeHref = (href, locale) => {
|
|
15
|
+
const localizedPathname = (0, _intlayer_core_localization.getLocalizedUrl)(typeof href === "string" ? href : href.pathname, locale);
|
|
16
|
+
if (typeof href === "string" || !href.query) return localizedPathname;
|
|
17
|
+
const searchParams = new URLSearchParams();
|
|
18
|
+
for (const [key, value] of Object.entries(href.query)) if (Array.isArray(value)) for (const entry of value) searchParams.append(key, String(entry));
|
|
19
|
+
else searchParams.append(key, String(value));
|
|
20
|
+
const queryString = searchParams.toString();
|
|
21
|
+
return queryString ? `${localizedPathname}?${queryString}` : localizedPathname;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.localizeHref = localizeHref;
|
|
26
|
+
//# sourceMappingURL=localizeHref.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localizeHref.cjs","names":[],"sources":["../../../src/navigation/localizeHref.ts"],"sourcesContent":["import { getLocalizedUrl } from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * A `next-intl` navigation href: either a pathname string or an object with a\n * `pathname` and optional `query`. The `pathnames` (typed routes) feature is\n * accepted for API compatibility but not interpolated.\n */\nexport type NextIntlHref =\n | string\n | {\n pathname: string;\n query?: Record<string, string | number | (string | number)[]>;\n params?: Record<string, string | number | (string | number)[]>;\n };\n\n/**\n * Prefix a `next-intl` href with the given locale using Intlayer's\n * `getLocalizedUrl`, preserving any query parameters.\n *\n * @param href - The target href (string or `{ pathname, query }`).\n * @param locale - The locale to localize the href for.\n * @returns The localized URL string.\n */\nexport const localizeHref = (href: NextIntlHref, locale: string): string => {\n const pathname = typeof href === 'string' ? href : href.pathname;\n const localizedPathname = getLocalizedUrl(pathname, locale as LocalesValues);\n\n if (typeof href === 'string' || !href.query) {\n return localizedPathname;\n }\n\n const searchParams = new URLSearchParams();\n for (const [key, value] of Object.entries(href.query)) {\n if (Array.isArray(value)) {\n for (const entry of value) {\n searchParams.append(key, String(entry));\n }\n } else {\n searchParams.append(key, String(value));\n }\n }\n\n const queryString = searchParams.toString();\n return queryString\n ? `${localizedPathname}?${queryString}`\n : localizedPathname;\n};\n"],"mappings":";;;;;;;;;;;;;AAwBA,MAAa,gBAAgB,MAAoB,WAA2B;CAE1E,MAAM,qEADW,OAAO,SAAS,WAAW,OAAO,KAAK,UACJ,OAAwB;AAE5E,KAAI,OAAO,SAAS,YAAY,CAAC,KAAK,MACpC,QAAO;CAGT,MAAM,eAAe,IAAI,iBAAiB;AAC1C,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,MAAM,CACnD,KAAI,MAAM,QAAQ,MAAM,CACtB,MAAK,MAAM,SAAS,MAClB,cAAa,OAAO,KAAK,OAAO,MAAM,CAAC;KAGzC,cAAa,OAAO,KAAK,OAAO,MAAM,CAAC;CAI3C,MAAM,cAAc,aAAa,UAAU;AAC3C,QAAO,cACH,GAAG,kBAAkB,GAAG,gBACxB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
|
|
3
|
+
//#region package.json
|
|
4
|
+
var require_package = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
5
|
+
module.exports = {
|
|
6
|
+
"name": "@intlayer/next-intl",
|
|
7
|
+
"version": "8.12.2",
|
|
8
|
+
"private": false,
|
|
9
|
+
"description": "next-intl API adapter for intlayer — useTranslations, useLocale, getTranslations, getLocale, NextIntlClientProvider backed by next-intlayer",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"intlayer",
|
|
12
|
+
"next-intl",
|
|
13
|
+
"next.js",
|
|
14
|
+
"react",
|
|
15
|
+
"i18n",
|
|
16
|
+
"adapter",
|
|
17
|
+
"compatibility"
|
|
18
|
+
],
|
|
19
|
+
"homepage": "https://intlayer.org",
|
|
20
|
+
"bugs": { "url": "https://github.com/aymericzip/intlayer/issues" },
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/aymericzip/intlayer.git"
|
|
24
|
+
},
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "Aymeric PINEAU",
|
|
28
|
+
"url": "https://github.com/aymericzip"
|
|
29
|
+
},
|
|
30
|
+
"contributors": [{
|
|
31
|
+
"name": "Aymeric Pineau",
|
|
32
|
+
"email": "ay.pineau@gmail.com",
|
|
33
|
+
"url": "https://github.com/aymericzip"
|
|
34
|
+
}],
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/types/index.d.ts",
|
|
39
|
+
"require": "./dist/cjs/index.cjs",
|
|
40
|
+
"import": "./dist/esm/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./server": {
|
|
43
|
+
"types": "./dist/types/server/index.d.ts",
|
|
44
|
+
"require": "./dist/cjs/server/index.cjs",
|
|
45
|
+
"import": "./dist/esm/server/index.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./routing": {
|
|
48
|
+
"types": "./dist/types/routing.d.ts",
|
|
49
|
+
"require": "./dist/cjs/routing.cjs",
|
|
50
|
+
"import": "./dist/esm/routing.mjs"
|
|
51
|
+
},
|
|
52
|
+
"./plugin": {
|
|
53
|
+
"types": "./dist/types/plugin/index.d.ts",
|
|
54
|
+
"require": "./dist/cjs/plugin/index.cjs",
|
|
55
|
+
"import": "./dist/esm/plugin/index.mjs"
|
|
56
|
+
},
|
|
57
|
+
"./package.json": "./package.json"
|
|
58
|
+
},
|
|
59
|
+
"main": "dist/cjs/index.cjs",
|
|
60
|
+
"module": "dist/esm/index.mjs",
|
|
61
|
+
"types": "dist/types/index.d.ts",
|
|
62
|
+
"typesVersions": { "*": {
|
|
63
|
+
"server": ["./dist/types/server/index.d.ts"],
|
|
64
|
+
"routing": ["./dist/types/routing.d.ts"],
|
|
65
|
+
"plugin": ["./dist/types/plugin/index.d.ts"]
|
|
66
|
+
} },
|
|
67
|
+
"files": ["./dist", "./package.json"],
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "bun --bun tsdown --config tsdown.config.ts",
|
|
70
|
+
"build:ci": "bun --bun tsdown --config tsdown.config.ts",
|
|
71
|
+
"clean": "bun --bun rimraf ./dist .turbo",
|
|
72
|
+
"dev": "bun --bun tsdown --config tsdown.config.ts --watch",
|
|
73
|
+
"format": "bun --bun biome format . --check",
|
|
74
|
+
"format:fix": "bun --bun biome format --write .",
|
|
75
|
+
"lint": "bun --bun biome lint .",
|
|
76
|
+
"lint:fix": "bun --bun biome lint --write .",
|
|
77
|
+
"prepublish": "cp -f ../../../README.md ./README.md",
|
|
78
|
+
"publish": "bun publish || true",
|
|
79
|
+
"publish:canary": "bun publish --access public --tag canary || true",
|
|
80
|
+
"publish:latest": "bun publish --access public --tag latest || true",
|
|
81
|
+
"test": "bun --bun vitest run",
|
|
82
|
+
"test:watch": "bun --bun vitest",
|
|
83
|
+
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"@intlayer/config": "workspace:*",
|
|
87
|
+
"@intlayer/core": "workspace:*",
|
|
88
|
+
"@intlayer/dictionaries-entry": "workspace:*",
|
|
89
|
+
"@intlayer/types": "workspace:*",
|
|
90
|
+
"next-intlayer": "workspace:*",
|
|
91
|
+
"react-intlayer": "workspace:*"
|
|
92
|
+
},
|
|
93
|
+
"devDependencies": {
|
|
94
|
+
"@types/node": "25.9.2",
|
|
95
|
+
"@types/react": "19.2.17",
|
|
96
|
+
"@utils/ts-config": "workspace:*",
|
|
97
|
+
"@utils/ts-config-types": "workspace:*",
|
|
98
|
+
"@utils/tsdown-config": "workspace:*",
|
|
99
|
+
"next-intl": "4.13.0",
|
|
100
|
+
"rimraf": "6.1.3",
|
|
101
|
+
"tsdown": "0.21.10",
|
|
102
|
+
"typescript": "6.0.3",
|
|
103
|
+
"vitest": "4.1.8"
|
|
104
|
+
},
|
|
105
|
+
"peerDependencies": {
|
|
106
|
+
"next": ">=14.0.0",
|
|
107
|
+
"next-intl": ">=3.0.0",
|
|
108
|
+
"react": ">=16.0.0",
|
|
109
|
+
"react-dom": ">=16.0.0"
|
|
110
|
+
},
|
|
111
|
+
"engines": { "node": ">=14.18" }
|
|
112
|
+
};
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
Object.defineProperty(exports, 'default', {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () {
|
|
119
|
+
return require_package();
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
//# sourceMappingURL=package.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.cjs","names":[],"sources":["../../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let next_intlayer_server = require("next-intlayer/server");
|
|
4
|
+
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
5
|
+
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
6
|
+
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
7
|
+
let node_module = require("node:module");
|
|
8
|
+
let node_path = require("node:path");
|
|
9
|
+
let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
|
|
10
|
+
let _intlayer_config_node = require("@intlayer/config/node");
|
|
11
|
+
|
|
12
|
+
//#region src/plugin/index.ts
|
|
13
|
+
/**
|
|
14
|
+
* `require` that works in both the CJS and ESM builds of this plugin.
|
|
15
|
+
* `import.meta.url` is rewritten to the module path in the CJS output by the
|
|
16
|
+
* bundler, so `createRequire` resolves correctly in either format.
|
|
17
|
+
*/
|
|
18
|
+
const compatRequire = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
19
|
+
/**
|
|
20
|
+
* Maps each original `next-intl` import specifier to the `@intlayer/next-intl`
|
|
21
|
+
* specifier that should serve it instead.
|
|
22
|
+
*/
|
|
23
|
+
const ALIAS_ENTRIES = [
|
|
24
|
+
{
|
|
25
|
+
request: "next-intl/server",
|
|
26
|
+
replacement: "@intlayer/next-intl/server"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
request: "next-intl/routing",
|
|
30
|
+
replacement: "@intlayer/next-intl/routing"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
request: "next-intl/navigation",
|
|
34
|
+
replacement: "@intlayer/next-intl/navigation"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
request: "next-intl/middleware",
|
|
38
|
+
replacement: "@intlayer/next-intl/middleware"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
request: "next-intl",
|
|
42
|
+
replacement: "@intlayer/next-intl"
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* Split a package specifier into its package name and export subpath.
|
|
47
|
+
*
|
|
48
|
+
* @param specifier - e.g. `@intlayer/next-intl/server` or `next-intl`.
|
|
49
|
+
* @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map
|
|
50
|
+
* key (`.` for the package root).
|
|
51
|
+
*/
|
|
52
|
+
const splitSpecifier = (specifier) => {
|
|
53
|
+
const segments = specifier.split("/");
|
|
54
|
+
const packageName = specifier.startsWith("@") ? segments.slice(0, 2).join("/") : segments[0] ?? specifier;
|
|
55
|
+
const subpath = specifier.slice(packageName?.length);
|
|
56
|
+
return {
|
|
57
|
+
packageName,
|
|
58
|
+
exportKey: subpath === "" ? "." : `.${subpath}`
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Resolve the absolute path of a package export, preferring the ESM (`import`)
|
|
63
|
+
* condition so Turbopack and modern bundlers load the `.mjs` build (which keeps
|
|
64
|
+
* the `"use client"` directives) rather than the CommonJS fallback.
|
|
65
|
+
*
|
|
66
|
+
* Both Turbopack and webpack ignore alias values that are bare package
|
|
67
|
+
* specifiers, so the aliases must point at real files.
|
|
68
|
+
*
|
|
69
|
+
* @param specifier - Package specifier, e.g. `@intlayer/next-intl/server`.
|
|
70
|
+
* @returns Absolute path to the resolved module file.
|
|
71
|
+
*/
|
|
72
|
+
const resolveEsmPath = (specifier) => {
|
|
73
|
+
const { packageName, exportKey } = splitSpecifier(specifier);
|
|
74
|
+
const packageJson = compatRequire(`${packageName}/package.json`);
|
|
75
|
+
const packageDir = (0, node_path.dirname)(compatRequire.resolve(`${packageName}/package.json`));
|
|
76
|
+
const exportEntry = packageJson.exports?.[exportKey];
|
|
77
|
+
const relativeFile = typeof exportEntry === "string" ? exportEntry : exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default;
|
|
78
|
+
if (!relativeFile) return compatRequire.resolve(specifier);
|
|
79
|
+
return (0, node_path.resolve)(packageDir, relativeFile);
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Format an absolute path as a project-root-relative specifier (prefixed with
|
|
83
|
+
* `./` and using forward slashes). Turbopack only honours `resolveAlias` values
|
|
84
|
+
* that are project-root-relative paths — bare specifiers are ignored and
|
|
85
|
+
* absolute paths are misread as root-relative. Mirrors `withIntlayer`'s
|
|
86
|
+
* Turbopack alias formatter.
|
|
87
|
+
*
|
|
88
|
+
* @param absolutePath - Absolute path to the target module file.
|
|
89
|
+
* @returns Relative specifier such as `./node_modules/@intlayer/next-intl/...`.
|
|
90
|
+
*/
|
|
91
|
+
const toTurbopackAlias = (absolutePath) => `./${(0, node_path.relative)(process.cwd(), absolutePath).split(node_path.sep).join("/")}`;
|
|
92
|
+
const NEXT_INTL_SWC_CALLERS = [{
|
|
93
|
+
callerName: "useTranslations",
|
|
94
|
+
importSources: ["next-intl", "@intlayer/next-intl"],
|
|
95
|
+
namespaceArgIndex: 0,
|
|
96
|
+
staticReplacement: "useDictionary",
|
|
97
|
+
dynamicReplacement: "useDictionaryDynamic"
|
|
98
|
+
}, {
|
|
99
|
+
callerName: "getTranslations",
|
|
100
|
+
importSources: ["next-intl/server", "@intlayer/next-intl/server"],
|
|
101
|
+
namespaceArgIndex: 0,
|
|
102
|
+
staticReplacement: "getDictionary",
|
|
103
|
+
dynamicReplacement: "getDictionaryDynamic"
|
|
104
|
+
}];
|
|
105
|
+
/**
|
|
106
|
+
* A Next.js plugin for next-intl compat that wraps next-intlayer's plugin
|
|
107
|
+
* and configures resolve aliases so `next-intl` imports are served by
|
|
108
|
+
* `@intlayer/next-intl`.
|
|
109
|
+
*/
|
|
110
|
+
const createNextIntlPlugin = (_i18nPath) => {
|
|
111
|
+
return async (nextConfig = {}) => {
|
|
112
|
+
const intlayerConfig = (0, _intlayer_config_node.getConfiguration)();
|
|
113
|
+
const appLogger = (0, _intlayer_config_logger.getAppLogger)(intlayerConfig);
|
|
114
|
+
(0, _intlayer_chokidar_utils.runOnce)((0, node_path.join)(intlayerConfig?.system?.baseDir ?? process.cwd(), ".intlayer", "cache", "intlayer-issues-invitation.lock"), () => {
|
|
115
|
+
appLogger([(0, _intlayer_config_logger.colorize)("Please report any issues you met on GitHub:", _intlayer_config_colors.GREY), (0, _intlayer_config_logger.colorize)("https://github.com/aymericzip/intlayer/issues", _intlayer_config_colors.GREY_LIGHT)]);
|
|
116
|
+
}, { cacheTimeoutMs: 1e3 * 60 * 60 });
|
|
117
|
+
const customWebpack = nextConfig.webpack;
|
|
118
|
+
const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({
|
|
119
|
+
request,
|
|
120
|
+
absolutePath: resolveEsmPath(replacement)
|
|
121
|
+
}));
|
|
122
|
+
const webpackAlias = Object.fromEntries(resolvedTargets.map(({ request, absolutePath }) => [request, absolutePath]));
|
|
123
|
+
const turboAlias = Object.fromEntries(resolvedTargets.map(({ request, absolutePath }) => [request, toTurbopackAlias(absolutePath)]));
|
|
124
|
+
const aliasConfig = { webpack: (config, options) => {
|
|
125
|
+
config.resolve.alias = {
|
|
126
|
+
...config.resolve.alias,
|
|
127
|
+
...webpackAlias
|
|
128
|
+
};
|
|
129
|
+
if (typeof customWebpack === "function") return customWebpack(config, options);
|
|
130
|
+
return config;
|
|
131
|
+
} };
|
|
132
|
+
const mergedConfig = {
|
|
133
|
+
...nextConfig,
|
|
134
|
+
...aliasConfig,
|
|
135
|
+
turbopack: {
|
|
136
|
+
...nextConfig.turbopack ?? {},
|
|
137
|
+
resolveAlias: {
|
|
138
|
+
...nextConfig.turbopack?.resolveAlias ?? {},
|
|
139
|
+
...turboAlias
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
let hasUserDefinedStorage = false;
|
|
144
|
+
try {
|
|
145
|
+
hasUserDefinedStorage = !!(intlayerConfig?.routing && "storage" in intlayerConfig.routing && intlayerConfig.routing.storage !== void 0);
|
|
146
|
+
} catch {}
|
|
147
|
+
return (0, next_intlayer_server.withIntlayer)(mergedConfig, hasUserDefinedStorage ? { swcExtraCallers: NEXT_INTL_SWC_CALLERS } : {
|
|
148
|
+
override: { routing: { storage: [{
|
|
149
|
+
type: "cookie",
|
|
150
|
+
name: "NEXT_LOCALE"
|
|
151
|
+
}, {
|
|
152
|
+
type: "header",
|
|
153
|
+
name: "x-intlayer-locale"
|
|
154
|
+
}] } },
|
|
155
|
+
swcExtraCallers: NEXT_INTL_SWC_CALLERS
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
exports.createNextIntlPlugin = createNextIntlPlugin;
|
|
162
|
+
exports.default = createNextIntlPlugin;
|
|
163
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["sep","ANSIColors"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original `next-intl` import specifier to the `@intlayer/next-intl`\n * specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-intl/server', replacement: '@intlayer/next-intl/server' },\n { request: 'next-intl/routing', replacement: '@intlayer/next-intl/routing' },\n {\n request: 'next-intl/navigation',\n replacement: '@intlayer/next-intl/navigation',\n },\n {\n request: 'next-intl/middleware',\n replacement: '@intlayer/next-intl/middleware',\n },\n { request: 'next-intl', replacement: '@intlayer/next-intl' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/next-intl/server` or `next-intl`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName?.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/next-intl/server`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/next-intl/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\nconst NEXT_INTL_SWC_CALLERS = [\n {\n callerName: 'useTranslations',\n importSources: ['next-intl', '@intlayer/next-intl'],\n namespaceArgIndex: 0,\n staticReplacement: 'useDictionary',\n dynamicReplacement: 'useDictionaryDynamic',\n },\n {\n callerName: 'getTranslations',\n importSources: ['next-intl/server', '@intlayer/next-intl/server'],\n namespaceArgIndex: 0,\n staticReplacement: 'getDictionary',\n dynamicReplacement: 'getDictionaryDynamic',\n },\n];\n\n/**\n * A Next.js plugin for next-intl compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-intl` imports are served by\n * `@intlayer/next-intl`.\n */\nexport const createNextIntlPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig?.system?.baseDir ?? process.cwd(),\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n // Only inject the NEXT_LOCALE cookie default when the user has not\n // configured their own routing.storage in intlayer.config.ts.\n // This lets users override via intlayer.config.ts while keeping\n // next-intl compatibility (NEXT_LOCALE) as the default.\n let hasUserDefinedStorage = false;\n try {\n hasUserDefinedStorage = !!(\n intlayerConfig?.routing &&\n 'storage' in intlayerConfig.routing &&\n intlayerConfig.routing.storage !== undefined\n );\n } catch {\n // If the config file cannot be read, fall back to the NEXT_LOCALE default.\n }\n\n const configOptions = hasUserDefinedStorage\n ? { swcExtraCallers: NEXT_INTL_SWC_CALLERS }\n : {\n override: {\n routing: {\n storage: [\n { type: 'cookie' as const, name: 'NEXT_LOCALE' },\n { type: 'header' as const, name: 'x-intlayer-locale' },\n ],\n },\n },\n swcExtraCallers: NEXT_INTL_SWC_CALLERS,\n };\n\n return withIntlayer(mergedConfig, configOptions);\n };\n};\n\nexport default createNextIntlPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;AAcA,MAAM,6FAA8C;;;;;AAMpD,MAAM,gBAA4D;CAChE;EAAE,SAAS;EAAoB,aAAa;EAA8B;CAC1E;EAAE,SAAS;EAAqB,aAAa;EAA+B;CAC5E;EACE,SAAS;EACT,aAAa;EACd;CACD;EACE,SAAS;EACT,aAAa;EACd;CACD;EAAE,SAAS;EAAa,aAAa;EAAuB;CAC7D;;;;;;;;AASD,MAAM,kBACJ,cAC+C;CAC/C,MAAM,WAAW,UAAU,MAAM,IAAI;CACrC,MAAM,cAAc,UAAU,WAAW,IAAI,GACzC,SAAS,MAAM,GAAG,EAAE,CAAC,KAAK,IAAI,GAC7B,SAAS,MAAM;CACpB,MAAM,UAAU,UAAU,MAAM,aAAa,OAAO;AACpD,QAAO;EAAE;EAAa,WAAW,YAAY,KAAK,MAAM,IAAI;EAAW;;;;;;;;;;;;;AAczE,MAAM,kBAAkB,cAA8B;CACpD,MAAM,EAAE,aAAa,cAAc,eAAe,UAAU;CAC5D,MAAM,cAAc,cAAc,GAAG,YAAY,eAAe;CAMhE,MAAM,oCACJ,cAAc,QAAQ,GAAG,YAAY,eAAe,CACrD;CAED,MAAM,cAAc,YAAY,UAAU;CAC1C,MAAM,eACJ,OAAO,gBAAgB,WACnB,cACC,aAAa,UAAU,aAAa,WAAW,aAAa;AAGnE,KAAI,CAAC,aAAc,QAAO,cAAc,QAAQ,UAAU;AAE1D,+BAAe,YAAY,aAAa;;;;;;;;;;;;AAa1C,MAAM,oBAAoB,iBACxB,6BAAc,QAAQ,KAAK,EAAE,aAAa,CAAC,MAAMA,cAAI,CAAC,KAAK,IAAI;AAEjE,MAAM,wBAAwB,CAC5B;CACE,YAAY;CACZ,eAAe,CAAC,aAAa,sBAAsB;CACnD,mBAAmB;CACnB,mBAAmB;CACnB,oBAAoB;CACrB,EACD;CACE,YAAY;CACZ,eAAe,CAAC,oBAAoB,6BAA6B;CACjE,mBAAmB;CACnB,mBAAmB;CACnB,oBAAoB;CACrB,CACF;;;;;;AAOD,MAAa,wBAAwB,cAAuB;AAC1D,QAAO,OAAO,aAAyB,EAAE,KAA0B;EACjE,MAAM,8DAAmC;EACzC,MAAM,sDAAyB,eAAe;AAE9C,4DAEI,gBAAgB,QAAQ,WAAW,QAAQ,KAAK,EAChD,aACA,SACA,kCACD,QACK;AACJ,aAAU,uCAEN,+CACAC,wBAAW,KACZ,wCAEC,iDACAA,wBAAW,WACZ,CACF,CAAC;KAEJ,EACE,gBAAgB,MAAO,KAAK,IAC7B,CACF;EAED,MAAM,gBAAgB,WAAW;EAEjC,MAAM,kBAAkB,cAAc,KAAK,EAAE,SAAS,mBAAmB;GACvE;GACA,cAAc,eAAe,YAAY;GAC1C,EAAE;EAGH,MAAM,eAAe,OAAO,YAC1B,gBAAgB,KAAK,EAAE,SAAS,mBAAmB,CACjD,SACA,aACD,CAAC,CACH;EAGD,MAAM,aAAa,OAAO,YACxB,gBAAgB,KAAK,EAAE,SAAS,mBAAmB,CACjD,SACA,iBAAiB,aAAa,CAC/B,CAAC,CACH;EAED,MAAM,cAAc,EAClB,UAAU,QAAa,YAAiB;AACtC,UAAO,QAAQ,QAAQ;IACrB,GAAG,OAAO,QAAQ;IAClB,GAAG;IACJ;AAED,OAAI,OAAO,kBAAkB,WAC3B,QAAO,cAAc,QAAQ,QAAQ;AAEvC,UAAO;KAEV;EAED,MAAM,eAA2B;GAC/B,GAAG;GACH,GAAG;GACH,WAAW;IACT,GAAI,WAAW,aAAa,EAAE;IAC9B,cAAc;KACZ,GAAI,WAAW,WAAW,gBAAgB,EAAE;KAC5C,GAAG;KACJ;IACF;GACF;EAMD,IAAI,wBAAwB;AAC5B,MAAI;AACF,2BAAwB,CAAC,EACvB,gBAAgB,WAChB,aAAa,eAAe,WAC5B,eAAe,QAAQ,YAAY;UAE/B;AAkBR,gDAAoB,cAdE,wBAClB,EAAE,iBAAiB,uBAAuB,GAC1C;GACE,UAAU,EACR,SAAS,EACP,SAAS,CACP;IAAE,MAAM;IAAmB,MAAM;IAAe,EAChD;IAAE,MAAM;IAAmB,MAAM;IAAqB,CACvD,EACF,EACF;GACD,iBAAiB;GAClB,CAE2C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
+
|
|
5
|
+
//#region src/routing.ts
|
|
6
|
+
/**
|
|
7
|
+
* Drop-in replacement for next-intl's `defineRouting()`.
|
|
8
|
+
*
|
|
9
|
+
* Merges the provided config with Intlayer's own routing / internationalization
|
|
10
|
+
* configuration so you don't have to repeat locale lists. All fields are
|
|
11
|
+
* optional — omitted values are read from the Intlayer config at runtime.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* export default defineRouting({
|
|
16
|
+
* locales: ['en', 'fr'],
|
|
17
|
+
* defaultLocale: 'en',
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const defineRouting = (config) => ({
|
|
22
|
+
locales: config?.locales ?? _intlayer_config_built.internationalization?.locales ?? [],
|
|
23
|
+
defaultLocale: config?.defaultLocale ?? _intlayer_config_built.internationalization?.defaultLocale,
|
|
24
|
+
localePrefix: config?.localePrefix ?? (_intlayer_config_built.routing?.prefixDefault ? "always" : "as-needed"),
|
|
25
|
+
...config
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.defineRouting = defineRouting;
|
|
30
|
+
//# sourceMappingURL=routing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.cjs","names":["internationalization","routing"],"sources":["../../src/routing.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport type Routing = {\n locales: LocalesValues[];\n defaultLocale: LocalesValues;\n localePrefix?: 'always' | 'as-needed' | 'never';\n pathnames?: Record<string, string | Record<string, string>>;\n};\n\n/**\n * Drop-in replacement for next-intl's `defineRouting()`.\n *\n * Merges the provided config with Intlayer's own routing / internationalization\n * configuration so you don't have to repeat locale lists. All fields are\n * optional — omitted values are read from the Intlayer config at runtime.\n *\n * @example\n * ```ts\n * export default defineRouting({\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * });\n * ```\n */\nexport const defineRouting: (config?: Partial<Routing>) => Routing = (\n config?: Partial<Routing>\n): Routing => ({\n locales:\n config?.locales ??\n ((internationalization?.locales ?? []) as LocalesValues[]),\n defaultLocale:\n config?.defaultLocale ??\n (internationalization?.defaultLocale as LocalesValues),\n localePrefix:\n config?.localePrefix ?? (routing?.prefixDefault ? 'always' : 'as-needed'),\n ...config,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,iBACX,YACa;CACb,SACE,QAAQ,WACNA,6CAAsB,WAAW,EAAE;CACvC,eACE,QAAQ,iBACPA,6CAAsB;CACzB,cACE,QAAQ,iBAAiBC,gCAAS,gBAAgB,WAAW;CAC/D,GAAG;CACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let next_intlayer_server = require("next-intlayer/server");
|
|
4
|
+
|
|
5
|
+
//#region src/server/getLocale.ts
|
|
6
|
+
/**
|
|
7
|
+
* Drop-in for next-intl's `getLocale()` server function.
|
|
8
|
+
*/
|
|
9
|
+
const getLocale = async () => await (0, next_intlayer_server.getLocale)();
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.getLocale = getLocale;
|
|
13
|
+
//# sourceMappingURL=getLocale.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLocale.cjs","names":[],"sources":["../../../src/server/getLocale.ts"],"sourcesContent":["import type { getLocale as _getLocale } from 'next-intl/server';\nimport { getLocale as getLocaleIntlayer } from 'next-intlayer/server';\n\n/**\n * Drop-in for next-intl's `getLocale()` server function.\n */\nexport const getLocale: typeof _getLocale = async (): Promise<string> =>\n (await getLocaleIntlayer()) as string;\n"],"mappings":";;;;;;;;AAMA,MAAa,YAA+B,YACzC,2CAAyB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
+
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
5
|
+
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
6
|
+
|
|
7
|
+
//#region src/server/getMessages.ts
|
|
8
|
+
/**
|
|
9
|
+
* Drop-in replacement for next-intl's `getMessages()` server function.
|
|
10
|
+
*
|
|
11
|
+
* Returns all compiled dictionary content for the current locale as a flat
|
|
12
|
+
* record keyed by dictionary name. Useful when you need to pass messages
|
|
13
|
+
* to a `NextIntlClientProvider`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const messages = await getMessages();
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @deprecated getMessages has no use case with intlayer.
|
|
21
|
+
* Messages are loaded automatically under the hood
|
|
22
|
+
*/
|
|
23
|
+
const getMessages = async () => {
|
|
24
|
+
if (process.env.NODE_ENV === "development") (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("getMessages", _intlayer_config_colors.CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
|
|
25
|
+
return {};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.getMessages = getMessages;
|
|
30
|
+
//# sourceMappingURL=getMessages.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMessages.cjs","names":["CYAN"],"sources":["../../../src/server/getMessages.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { getMessages as _getMessages } from 'next-intl/server';\n\n/**\n * Drop-in replacement for next-intl's `getMessages()` server function.\n *\n * Returns all compiled dictionary content for the current locale as a flat\n * record keyed by dictionary name. Useful when you need to pass messages\n * to a `NextIntlClientProvider`.\n *\n * @example\n * ```ts\n * const messages = await getMessages();\n * ```\n *\n * @deprecated getMessages has no use case with intlayer.\n * Messages are loaded automatically under the hood\n */\nexport const getMessages: typeof _getMessages = async () => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('getMessages', CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return {};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,cAAmC,YAAY;AAC1D,KAAI,QAAQ,IAAI,aAAa,cAE3B,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,eAAeA,6BAAK,CAAC,iHAClC;AAGH,QAAO,EAAE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_server_getLocale = require('./getLocale.cjs');
|
|
3
|
+
const require_createTranslator = require('../createTranslator.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/server/getTranslations.ts
|
|
6
|
+
/**
|
|
7
|
+
* Drop-in for next-intl's server `getTranslations()`.
|
|
8
|
+
*
|
|
9
|
+
* Messages support ICU MessageFormat syntax: simple arguments (`{name}`),
|
|
10
|
+
* plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted
|
|
11
|
+
* arguments (`{value, number}`). Rich text is available through `t.rich()`
|
|
12
|
+
* and `t.markup()`.
|
|
13
|
+
*
|
|
14
|
+
* Also accepts an options object `{ namespace, locale }` to match next-intl's
|
|
15
|
+
* full server API surface.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // Bare namespace — fully typed dot-paths
|
|
20
|
+
* const t = await getTranslations('about');
|
|
21
|
+
* return <h1>{t('counter.label')}</h1>;
|
|
22
|
+
*
|
|
23
|
+
* // ICU plural
|
|
24
|
+
* t('items', { count: 3 });
|
|
25
|
+
*
|
|
26
|
+
* // Options object with locale override
|
|
27
|
+
* const t = await getTranslations({ namespace: 'about', locale: 'fr' });
|
|
28
|
+
*
|
|
29
|
+
* // Rich text
|
|
30
|
+
* t.rich('terms', { link: (chunks) => <a href="/terms">{chunks}</a> });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
const getTranslations = (async (namespaceOrOptions) => {
|
|
34
|
+
let namespace;
|
|
35
|
+
let localeOverride;
|
|
36
|
+
if (typeof namespaceOrOptions === "object" && namespaceOrOptions !== null) {
|
|
37
|
+
namespace = namespaceOrOptions.namespace;
|
|
38
|
+
localeOverride = namespaceOrOptions.locale;
|
|
39
|
+
} else namespace = namespaceOrOptions;
|
|
40
|
+
return require_createTranslator.createTranslator(localeOverride ?? await require_server_getLocale.getLocale(), namespace);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
exports.getTranslations = getTranslations;
|
|
45
|
+
//# sourceMappingURL=getTranslations.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTranslations.cjs","names":["createTranslator","getLocale"],"sources":["../../../src/server/getTranslations.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { ReactNode } from 'react';\nimport {\n createTranslator,\n type MarkupChunkRenderer,\n type RichChunkRenderer,\n} from '../createTranslator';\nimport { getLocale } from './getLocale';\n\n/**\n * Options accepted by the options-object overload of {@link getTranslations}.\n */\ntype GetTranslationsOptions<N extends DictionaryKeys> = {\n /** The dictionary namespace to scope translations to. */\n namespace?: N;\n /** Override the locale instead of reading it from the current request. */\n locale?: LocalesValues;\n};\n\n/**\n * The translation function returned by {@link getTranslations}.\n *\n * Beyond the plain call signature, the function exposes:\n * - `has(key)` — returns `true` when the key exists in the namespace.\n * - `raw(key)` — returns the unprocessed message value.\n * - `rich(key, values)` — resolves `<tag>chunks</tag>` markup to React nodes.\n * - `markup(key, values)` — resolves `<tag>chunks</tag>` markup to a string.\n */\ntype TranslateFunction<N extends DictionaryKeys> = {\n /** Translate a key to a string, with optional ICU interpolation params. */\n <P extends ValidDotPathsFor<N>>(\n key: P,\n params?: Record<string, unknown>\n ): string;\n /** Returns `true` if the given key exists in the namespace. */\n has<P extends ValidDotPathsFor<N>>(key: P): boolean;\n /** Returns the raw unprocessed message for the given key. */\n raw<P extends ValidDotPathsFor<N>>(key: P): unknown;\n /** Resolves rich-text markup, mapping tags through React renderers. */\n rich<P extends ValidDotPathsFor<N>>(\n key: P,\n values?: Record<string, RichChunkRenderer | ReactNode>\n ): ReactNode;\n /** Resolves rich-text markup, mapping tags through string renderers. */\n markup<P extends ValidDotPathsFor<N>>(\n key: P,\n values?: Record<string, MarkupChunkRenderer | string | number>\n ): string;\n};\n\n/** Loosely-typed function returned for nested `'dict.scope'` namespaces. */\ntype LooseTranslateFunction = {\n (key: string, params?: Record<string, unknown>): string;\n has(key: string): boolean;\n raw(key: string): unknown;\n rich(\n key: string,\n values?: Record<string, RichChunkRenderer | ReactNode>\n ): ReactNode;\n markup(\n key: string,\n values?: Record<string, MarkupChunkRenderer | string | number>\n ): string;\n};\n\n/**\n * Overload set for {@link getTranslations}:\n *\n * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).\n * 2. An options object `{ namespace?, locale? }` → typed when namespace is\n * a known `DictionaryKeys` value.\n * 3. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative\n * `string` paths, matching next-intl's scoped-namespace behaviour.\n * 4. No namespace → root scope; the first segment of each key designates\n * the dictionary (`t('about.title')`).\n */\ntype GetTranslations = {\n <N extends DictionaryKeys>(namespace: N): Promise<TranslateFunction<N>>;\n <N extends DictionaryKeys>(\n options: GetTranslationsOptions<N>\n ): Promise<TranslateFunction<N>>;\n (namespace: `${string}.${string}`): Promise<LooseTranslateFunction>;\n (): Promise<LooseTranslateFunction>;\n};\n\n/**\n * Drop-in for next-intl's server `getTranslations()`.\n *\n * Messages support ICU MessageFormat syntax: simple arguments (`{name}`),\n * plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted\n * arguments (`{value, number}`). Rich text is available through `t.rich()`\n * and `t.markup()`.\n *\n * Also accepts an options object `{ namespace, locale }` to match next-intl's\n * full server API surface.\n *\n * @example\n * ```ts\n * // Bare namespace — fully typed dot-paths\n * const t = await getTranslations('about');\n * return <h1>{t('counter.label')}</h1>;\n *\n * // ICU plural\n * t('items', { count: 3 });\n *\n * // Options object with locale override\n * const t = await getTranslations({ namespace: 'about', locale: 'fr' });\n *\n * // Rich text\n * t.rich('terms', { link: (chunks) => <a href=\"/terms\">{chunks}</a> });\n * ```\n */\nexport const getTranslations: GetTranslations = (async (\n namespaceOrOptions?: string | GetTranslationsOptions<DictionaryKeys>\n) => {\n let namespace: string | undefined;\n let localeOverride: LocalesValues | undefined;\n\n if (typeof namespaceOrOptions === 'object' && namespaceOrOptions !== null) {\n namespace = namespaceOrOptions.namespace;\n localeOverride = namespaceOrOptions.locale;\n } else {\n namespace = namespaceOrOptions as string | undefined;\n }\n\n const locale = localeOverride ?? (await getLocale());\n\n return createTranslator(locale as LocalesValues, namespace);\n}) as GetTranslations;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,MAAa,mBAAoC,OAC/C,uBACG;CACH,IAAI;CACJ,IAAI;AAEJ,KAAI,OAAO,uBAAuB,YAAY,uBAAuB,MAAM;AACzE,cAAY,mBAAmB;AAC/B,mBAAiB,mBAAmB;OAEpC,aAAY;AAKd,QAAOA,0CAFQ,kBAAmB,MAAMC,oCAAW,EAEF,UAAU"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_createFormatter = require('../createFormatter.cjs');
|
|
3
|
+
const require_server_getLocale = require('./getLocale.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/server/helpers.ts
|
|
6
|
+
/**
|
|
7
|
+
* Drop-in for next-intl's server `getFormatter()`.
|
|
8
|
+
* Returns locale-aware formatters backed by the native `Intl.*` APIs.
|
|
9
|
+
*/
|
|
10
|
+
const getFormatter = (async (options) => {
|
|
11
|
+
return require_createFormatter.createFormatter(options?.locale ?? await require_server_getLocale.getLocale());
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Drop-in for next-intl's server `getNow()`.
|
|
15
|
+
* Returns the current `Date`.
|
|
16
|
+
*/
|
|
17
|
+
const getNow = (async () => /* @__PURE__ */ new Date());
|
|
18
|
+
/**
|
|
19
|
+
* Drop-in for next-intl's server `getTimeZone()`.
|
|
20
|
+
* Returns the system time zone resolved from `Intl.DateTimeFormat`.
|
|
21
|
+
*/
|
|
22
|
+
const getTimeZone = (async () => Intl.DateTimeFormat().resolvedOptions().timeZone);
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.getFormatter = getFormatter;
|
|
26
|
+
exports.getNow = getNow;
|
|
27
|
+
exports.getTimeZone = getTimeZone;
|
|
28
|
+
//# sourceMappingURL=helpers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.cjs","names":["createFormatter","getLocale"],"sources":["../../../src/server/helpers.ts"],"sourcesContent":["import type {\n getFormatter as _getFormatter,\n getNow as _getNow,\n getTimeZone as _getTimeZone,\n} from 'next-intl/server';\nimport { createFormatter } from '../createFormatter';\nimport { getLocale } from './getLocale';\n\n/**\n * Drop-in for next-intl's server `getFormatter()`.\n * Returns locale-aware formatters backed by the native `Intl.*` APIs.\n */\nexport const getFormatter: typeof _getFormatter = (async (options?: {\n locale?: string;\n}) => {\n const locale = options?.locale ?? (await getLocale());\n return createFormatter(locale as string);\n}) as typeof _getFormatter;\n\n/**\n * Drop-in for next-intl's server `getNow()`.\n * Returns the current `Date`.\n */\nexport const getNow: typeof _getNow = (async () =>\n new Date()) as typeof _getNow;\n\n/**\n * Drop-in for next-intl's server `getTimeZone()`.\n * Returns the system time zone resolved from `Intl.DateTimeFormat`.\n */\nexport const getTimeZone: typeof _getTimeZone = (async () =>\n Intl.DateTimeFormat().resolvedOptions().timeZone) as typeof _getTimeZone;\n"],"mappings":";;;;;;;;;AAYA,MAAa,gBAAsC,OAAO,YAEpD;AAEJ,QAAOA,wCADQ,SAAS,UAAW,MAAMC,oCAAW,CACZ;;;;;;AAO1C,MAAa,UAA0B,4BACrC,IAAI,MAAM;;;;;AAMZ,MAAa,eAAoC,YAC/C,KAAK,gBAAgB,CAAC,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_server_getLocale = require('./getLocale.cjs');
|
|
3
|
+
const require_getDictionary = require('../getDictionary.cjs');
|
|
4
|
+
const require_getDictionaryDynamic = require('../getDictionaryDynamic.cjs');
|
|
5
|
+
const require_server_helpers = require('./helpers.cjs');
|
|
6
|
+
const require_server_setLocale = require('./setLocale.cjs');
|
|
7
|
+
const require_server_getTranslations = require('./getTranslations.cjs');
|
|
8
|
+
const require_server_getMessages = require('./getMessages.cjs');
|
|
9
|
+
|
|
10
|
+
exports.getDictionary = require_getDictionary.getDictionary;
|
|
11
|
+
exports.getDictionaryDynamic = require_getDictionaryDynamic.getDictionaryDynamic;
|
|
12
|
+
exports.getFormatter = require_server_helpers.getFormatter;
|
|
13
|
+
exports.getLocale = require_server_getLocale.getLocale;
|
|
14
|
+
exports.getMessages = require_server_getMessages.getMessages;
|
|
15
|
+
exports.getNow = require_server_helpers.getNow;
|
|
16
|
+
exports.getTimeZone = require_server_helpers.getTimeZone;
|
|
17
|
+
exports.getTranslations = require_server_getTranslations.getTranslations;
|
|
18
|
+
exports.setLocale = require_server_setLocale.setLocale;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_core_utils = require("@intlayer/core/utils");
|
|
4
|
+
let next_headers_js = require("next/headers.js");
|
|
5
|
+
|
|
6
|
+
//#region src/server/setLocale.ts
|
|
7
|
+
/**
|
|
8
|
+
* Drop-in replacement for next-intl's `setLocale()` server action.
|
|
9
|
+
*
|
|
10
|
+
* Writes the locale to whichever cookie(s) the active `routing.storage`
|
|
11
|
+
* configuration specifies. When `createNextIntlPlugin` is used (the default),
|
|
12
|
+
* this is `NEXT_LOCALE`; when the user has configured a custom storage in
|
|
13
|
+
* `intlayer.config.ts`, that name is used instead.
|
|
14
|
+
*
|
|
15
|
+
* Must be called inside a Server Action.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* 'use server';
|
|
20
|
+
* await setLocale('fr');
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const setLocale = async (locale) => {
|
|
24
|
+
const cookieStore = await (0, next_headers_js.cookies)();
|
|
25
|
+
(0, _intlayer_core_utils.setLocaleInStorageServer)(locale, { setCookieStore: (name, value, attributes) => {
|
|
26
|
+
cookieStore.set(name, value, {
|
|
27
|
+
...attributes ?? {},
|
|
28
|
+
path: attributes?.path ?? "/",
|
|
29
|
+
sameSite: attributes?.sameSite ?? "lax",
|
|
30
|
+
httpOnly: attributes?.httpOnly ?? false,
|
|
31
|
+
secure: attributes?.secure ?? process.env.NODE_ENV === "production"
|
|
32
|
+
});
|
|
33
|
+
} });
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.setLocale = setLocale;
|
|
38
|
+
//# sourceMappingURL=setLocale.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setLocale.cjs","names":[],"sources":["../../../src/server/setLocale.ts"],"sourcesContent":["import { setLocaleInStorageServer } from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { cookies } from 'next/headers.js';\n\n/**\n * Drop-in replacement for next-intl's `setLocale()` server action.\n *\n * Writes the locale to whichever cookie(s) the active `routing.storage`\n * configuration specifies. When `createNextIntlPlugin` is used (the default),\n * this is `NEXT_LOCALE`; when the user has configured a custom storage in\n * `intlayer.config.ts`, that name is used instead.\n *\n * Must be called inside a Server Action.\n *\n * @example\n * ```ts\n * 'use server';\n * await setLocale('fr');\n * ```\n */\nexport const setLocale = async (locale: string): Promise<void> => {\n const cookieStore = await cookies();\n\n setLocaleInStorageServer(locale as LocalesValues, {\n setCookieStore: (name, value, attributes) => {\n cookieStore.set(name, value, {\n ...(attributes ?? {}),\n path: attributes?.path ?? '/',\n sameSite: (attributes?.sameSite as 'lax') ?? 'lax',\n httpOnly: attributes?.httpOnly ?? false,\n secure: attributes?.secure ?? process.env.NODE_ENV === 'production',\n });\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,YAAY,OAAO,WAAkC;CAChE,MAAM,cAAc,oCAAe;AAEnC,oDAAyB,QAAyB,EAChD,iBAAiB,MAAM,OAAO,eAAe;AAC3C,cAAY,IAAI,MAAM,OAAO;GAC3B,GAAI,cAAc,EAAE;GACpB,MAAM,YAAY,QAAQ;GAC1B,UAAW,YAAY,YAAsB;GAC7C,UAAU,YAAY,YAAY;GAClC,QAAQ,YAAY,UAAU,QAAQ,IAAI,aAAa;GACxD,CAAC;IAEL,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
let react_intlayer = require("react-intlayer");
|
|
6
|
+
|
|
7
|
+
//#region src/useDictionary.ts
|
|
8
|
+
const navigatePath = (objectValue, path) => {
|
|
9
|
+
if (!path) return objectValue;
|
|
10
|
+
const parts = path.split(".");
|
|
11
|
+
let current = objectValue;
|
|
12
|
+
for (const part of parts) {
|
|
13
|
+
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
14
|
+
current = current[part];
|
|
15
|
+
}
|
|
16
|
+
return current;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Dictionary-accepting variant of `useTranslations`.
|
|
20
|
+
*
|
|
21
|
+
* Used internally by the SWC optimization: instead of looking up the dictionary
|
|
22
|
+
* at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
|
|
23
|
+
* and passes it directly here. This enables tree-shaking of unused locale content.
|
|
24
|
+
*
|
|
25
|
+
* @example (generated by SWC, not written manually)
|
|
26
|
+
* import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
|
|
27
|
+
* const t = useDictionary(_abc);
|
|
28
|
+
*/
|
|
29
|
+
const useDictionary = (dictionary, namespacePrefix) => {
|
|
30
|
+
const content = (0, react_intlayer.useDictionary)(dictionary);
|
|
31
|
+
const resolveKey = (key) => namespacePrefix ? `${namespacePrefix}.${key}` : key;
|
|
32
|
+
return Object.assign((lookup, params) => {
|
|
33
|
+
const rawValue = navigatePath(content, resolveKey(String(lookup)));
|
|
34
|
+
const str = String(rawValue ?? resolveKey(String(lookup)));
|
|
35
|
+
if (!params) return str;
|
|
36
|
+
return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
37
|
+
}, {
|
|
38
|
+
has: (lookup) => navigatePath(content, resolveKey(String(lookup))) != null,
|
|
39
|
+
raw: (lookup) => navigatePath(content, resolveKey(String(lookup)))
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
exports.useDictionary = useDictionary;
|
|
45
|
+
//# sourceMappingURL=useDictionary.cjs.map
|