@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,59 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/createFormatter.ts
|
|
4
|
+
/** Time units orderable by their duration in seconds. */
|
|
5
|
+
const RELATIVE_TIME_UNITS = [
|
|
6
|
+
["year", 31536e3],
|
|
7
|
+
["month", 2628e3],
|
|
8
|
+
["week", 604800],
|
|
9
|
+
["day", 86400],
|
|
10
|
+
["hour", 3600],
|
|
11
|
+
["minute", 60],
|
|
12
|
+
["second", 1]
|
|
13
|
+
];
|
|
14
|
+
const toDate = (value) => value instanceof Date ? value : new Date(value);
|
|
15
|
+
/**
|
|
16
|
+
* Builds a next-intl compatible formatter backed by the native `Intl.*`
|
|
17
|
+
* APIs for the given locale.
|
|
18
|
+
*
|
|
19
|
+
* Shared by `useFormatter` (client) and `getFormatter` (server).
|
|
20
|
+
*/
|
|
21
|
+
const createFormatter = (locale) => ({
|
|
22
|
+
dateTime: (value, options) => new Intl.DateTimeFormat(locale, options).format(value),
|
|
23
|
+
number: (value, options) => new Intl.NumberFormat(locale, options).format(value),
|
|
24
|
+
/** Formats a date range with `Intl.DateTimeFormat#formatRange`. */
|
|
25
|
+
dateTimeRange: (start, end, options) => new Intl.DateTimeFormat(locale, options).formatRange(toDate(start), toDate(end)),
|
|
26
|
+
/**
|
|
27
|
+
* Formats a date relative to now (or a reference date), automatically
|
|
28
|
+
* selecting the largest fitting unit.
|
|
29
|
+
*/
|
|
30
|
+
relativeTime: (date, nowOrOptions) => {
|
|
31
|
+
const options = nowOrOptions instanceof Date || typeof nowOrOptions === "number" ? { now: nowOrOptions } : nowOrOptions ?? {};
|
|
32
|
+
const nowDate = options.now !== void 0 ? toDate(options.now) : /* @__PURE__ */ new Date();
|
|
33
|
+
const diffInSeconds = (toDate(date).getTime() - nowDate.getTime()) / 1e3;
|
|
34
|
+
let unit = options.unit;
|
|
35
|
+
if (!unit) {
|
|
36
|
+
const absoluteDiff = Math.abs(diffInSeconds);
|
|
37
|
+
unit = RELATIVE_TIME_UNITS.find(([, unitSeconds]) => absoluteDiff >= unitSeconds)?.[0] ?? "second";
|
|
38
|
+
}
|
|
39
|
+
const unitSeconds = RELATIVE_TIME_UNITS.find(([unitName]) => unitName === unit)?.[1] ?? 1;
|
|
40
|
+
return new Intl.RelativeTimeFormat(locale, {
|
|
41
|
+
numeric: "auto",
|
|
42
|
+
style: options.style
|
|
43
|
+
}).format(Math.round(diffInSeconds / unitSeconds), unit);
|
|
44
|
+
},
|
|
45
|
+
/** Formats a list with `Intl.ListFormat`. */
|
|
46
|
+
list: (value, options) => new Intl.ListFormat(locale, options).format(value),
|
|
47
|
+
displayName: (value, optionsOrFormat, extraOptions) => {
|
|
48
|
+
const resolvedOptions = typeof optionsOrFormat === "string" ? extraOptions : optionsOrFormat;
|
|
49
|
+
try {
|
|
50
|
+
return new Intl.DisplayNames([locale], resolvedOptions ?? { type: "language" }).of(value) ?? value;
|
|
51
|
+
} catch {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
exports.createFormatter = createFormatter;
|
|
59
|
+
//# sourceMappingURL=createFormatter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFormatter.cjs","names":[],"sources":["../../src/createFormatter.ts"],"sourcesContent":["import type { useFormatter as _useFormatter } from 'next-intl';\n\n/** The formatter object shape exposed by next-intl. */\nexport type Formatter = ReturnType<typeof _useFormatter>;\n\n/** Time units orderable by their duration in seconds. */\nconst RELATIVE_TIME_UNITS: [Intl.RelativeTimeFormatUnit, number][] = [\n ['year', 31536000],\n ['month', 2628000],\n ['week', 604800],\n ['day', 86400],\n ['hour', 3600],\n ['minute', 60],\n ['second', 1],\n];\n\nconst toDate = (value: Date | number | string): Date =>\n value instanceof Date ? value : new Date(value);\n\n/**\n * Builds a next-intl compatible formatter backed by the native `Intl.*`\n * APIs for the given locale.\n *\n * Shared by `useFormatter` (client) and `getFormatter` (server).\n */\nexport const createFormatter = (locale: string): Formatter =>\n ({\n dateTime: (value: Date | number, options?: Intl.DateTimeFormatOptions) =>\n new Intl.DateTimeFormat(locale, options).format(value),\n\n number: (value: number | bigint, options?: Intl.NumberFormatOptions) =>\n new Intl.NumberFormat(locale, options).format(value),\n\n /** Formats a date range with `Intl.DateTimeFormat#formatRange`. */\n dateTimeRange: (\n start: Date | number,\n end: Date | number,\n options?: Intl.DateTimeFormatOptions\n ) =>\n new Intl.DateTimeFormat(locale, options).formatRange(\n toDate(start),\n toDate(end)\n ),\n\n /**\n * Formats a date relative to now (or a reference date), automatically\n * selecting the largest fitting unit.\n */\n relativeTime: (\n date: Date | number | string,\n nowOrOptions?:\n | Date\n | number\n | {\n now?: Date | number;\n unit?: Intl.RelativeTimeFormatUnit;\n style?: Intl.RelativeTimeFormatStyle;\n numberingSystem?: string;\n }\n ) => {\n const options =\n nowOrOptions instanceof Date || typeof nowOrOptions === 'number'\n ? { now: nowOrOptions }\n : (nowOrOptions ?? {});\n\n const nowDate =\n options.now !== undefined ? toDate(options.now) : new Date();\n const diffInSeconds = (toDate(date).getTime() - nowDate.getTime()) / 1000;\n\n let unit = options.unit;\n if (!unit) {\n const absoluteDiff = Math.abs(diffInSeconds);\n unit =\n RELATIVE_TIME_UNITS.find(\n ([, unitSeconds]) => absoluteDiff >= unitSeconds\n )?.[0] ?? 'second';\n }\n\n const unitSeconds =\n RELATIVE_TIME_UNITS.find(([unitName]) => unitName === unit)?.[1] ?? 1;\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto',\n style: options.style,\n }).format(Math.round(diffInSeconds / unitSeconds), unit);\n },\n\n /** Formats a list with `Intl.ListFormat`. */\n list: (value: Iterable<string>, options?: Intl.ListFormatOptions): string =>\n new Intl.ListFormat(locale, options).format(value),\n\n displayName: (\n value: string,\n optionsOrFormat?: Intl.DisplayNamesOptions | string,\n extraOptions?: Intl.DisplayNamesOptions\n ): string => {\n const resolvedOptions =\n typeof optionsOrFormat === 'string' ? extraOptions : optionsOrFormat;\n try {\n return (\n new Intl.DisplayNames(\n [locale],\n resolvedOptions ?? { type: 'language' }\n ).of(value) ?? value\n );\n } catch {\n return value;\n }\n },\n }) as unknown as Formatter;\n"],"mappings":";;;;AAMA,MAAM,sBAA+D;CACnE,CAAC,QAAQ,QAAS;CAClB,CAAC,SAAS,OAAQ;CAClB,CAAC,QAAQ,OAAO;CAChB,CAAC,OAAO,MAAM;CACd,CAAC,QAAQ,KAAK;CACd,CAAC,UAAU,GAAG;CACd,CAAC,UAAU,EAAE;CACd;AAED,MAAM,UAAU,UACd,iBAAiB,OAAO,QAAQ,IAAI,KAAK,MAAM;;;;;;;AAQjD,MAAa,mBAAmB,YAC7B;CACC,WAAW,OAAsB,YAC/B,IAAI,KAAK,eAAe,QAAQ,QAAQ,CAAC,OAAO,MAAM;CAExD,SAAS,OAAwB,YAC/B,IAAI,KAAK,aAAa,QAAQ,QAAQ,CAAC,OAAO,MAAM;;CAGtD,gBACE,OACA,KACA,YAEA,IAAI,KAAK,eAAe,QAAQ,QAAQ,CAAC,YACvC,OAAO,MAAM,EACb,OAAO,IAAI,CACZ;;;;;CAMH,eACE,MACA,iBASG;EACH,MAAM,UACJ,wBAAwB,QAAQ,OAAO,iBAAiB,WACpD,EAAE,KAAK,cAAc,GACpB,gBAAgB,EAAE;EAEzB,MAAM,UACJ,QAAQ,QAAQ,SAAY,OAAO,QAAQ,IAAI,mBAAG,IAAI,MAAM;EAC9D,MAAM,iBAAiB,OAAO,KAAK,CAAC,SAAS,GAAG,QAAQ,SAAS,IAAI;EAErE,IAAI,OAAO,QAAQ;AACnB,MAAI,CAAC,MAAM;GACT,MAAM,eAAe,KAAK,IAAI,cAAc;AAC5C,UACE,oBAAoB,MACjB,GAAG,iBAAiB,gBAAgB,YACtC,GAAG,MAAM;;EAGd,MAAM,cACJ,oBAAoB,MAAM,CAAC,cAAc,aAAa,KAAK,GAAG,MAAM;AAEtE,SAAO,IAAI,KAAK,mBAAmB,QAAQ;GACzC,SAAS;GACT,OAAO,QAAQ;GAChB,CAAC,CAAC,OAAO,KAAK,MAAM,gBAAgB,YAAY,EAAE,KAAK;;;CAI1D,OAAO,OAAyB,YAC9B,IAAI,KAAK,WAAW,QAAQ,QAAQ,CAAC,OAAO,MAAM;CAEpD,cACE,OACA,iBACA,iBACW;EACX,MAAM,kBACJ,OAAO,oBAAoB,WAAW,eAAe;AACvD,MAAI;AACF,UACE,IAAI,KAAK,aACP,CAAC,OAAO,EACR,mBAAmB,EAAE,MAAM,YAAY,CACxC,CAAC,GAAG,MAAM,IAAI;UAEX;AACN,UAAO;;;CAGZ"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
4
|
+
let _intlayer_core_messageFormat = require("@intlayer/core/messageFormat");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
|
|
8
|
+
//#region src/createTranslator.tsx
|
|
9
|
+
const navigatePath = (objectValue, path) => {
|
|
10
|
+
if (!path) return objectValue;
|
|
11
|
+
const parts = path.split(".");
|
|
12
|
+
let current = objectValue;
|
|
13
|
+
for (const part of parts) {
|
|
14
|
+
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
15
|
+
current = current[part];
|
|
16
|
+
}
|
|
17
|
+
return current;
|
|
18
|
+
};
|
|
19
|
+
/** Splits rich values into scalar interpolation values and tag renderers. */
|
|
20
|
+
const splitRichValues = (values = {}) => {
|
|
21
|
+
const scalarValues = {};
|
|
22
|
+
const renderers = {};
|
|
23
|
+
for (const [valueKey, value] of Object.entries(values)) if (typeof value === "function") renderers[valueKey] = value;
|
|
24
|
+
else scalarValues[valueKey] = value;
|
|
25
|
+
return {
|
|
26
|
+
scalarValues,
|
|
27
|
+
renderers
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const renderRichTokens = (tokens, renderers) => tokens.map((token, tokenIndex) => {
|
|
31
|
+
if (typeof token === "string") return token;
|
|
32
|
+
const children = renderRichTokens(token.children, renderers);
|
|
33
|
+
const renderer = renderers[token.tag];
|
|
34
|
+
if (typeof renderer === "function") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: renderer(children) }, tokenIndex);
|
|
35
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children }, tokenIndex);
|
|
36
|
+
});
|
|
37
|
+
const renderMarkupTokens = (tokens, renderers) => tokens.map((token) => {
|
|
38
|
+
if (typeof token === "string") return token;
|
|
39
|
+
const children = renderMarkupTokens(token.children, renderers);
|
|
40
|
+
const renderer = renderers[token.tag];
|
|
41
|
+
if (typeof renderer === "function") return renderer(children);
|
|
42
|
+
return children;
|
|
43
|
+
}).join("");
|
|
44
|
+
/**
|
|
45
|
+
* The untyped runtime translator shared by `useTranslations` (client) and
|
|
46
|
+
* `getTranslations` (server).
|
|
47
|
+
*
|
|
48
|
+
* Behaviour matches next-intl:
|
|
49
|
+
* - namespace `'about'` → keys resolved inside the `about` dictionary
|
|
50
|
+
* - namespace `'about.counter'` → dictionary `about`, key prefix `counter`
|
|
51
|
+
* - no namespace → the first segment of each key is the dictionary key
|
|
52
|
+
* - messages support ICU syntax (plural, select, `#`, formatted arguments)
|
|
53
|
+
* - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided
|
|
54
|
+
* renderers; `t.raw` returns the raw value; `t.has` checks existence
|
|
55
|
+
*/
|
|
56
|
+
const createTranslator = (locale, namespace) => {
|
|
57
|
+
const [dictionaryKey, ...prefixSegments] = (namespace ?? "").split(".");
|
|
58
|
+
const keyPrefix = prefixSegments.join(".");
|
|
59
|
+
const lookup = (key) => {
|
|
60
|
+
let targetDictionaryKey = dictionaryKey;
|
|
61
|
+
let path = keyPrefix ? `${keyPrefix}.${key}` : key;
|
|
62
|
+
if (!targetDictionaryKey) {
|
|
63
|
+
const [firstSegment, ...restSegments] = key.split(".");
|
|
64
|
+
targetDictionaryKey = firstSegment;
|
|
65
|
+
path = restSegments.join(".");
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
return navigatePath((0, _intlayer_core_interpreter.getIntlayer)(targetDictionaryKey, locale), path);
|
|
69
|
+
} catch {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const resolveToString = (key, values = {}) => {
|
|
74
|
+
const rawValue = lookup(key);
|
|
75
|
+
if (rawValue === null || rawValue === void 0) return void 0;
|
|
76
|
+
return (0, _intlayer_core_messageFormat.resolveMessage)(rawValue, values, locale, "icu");
|
|
77
|
+
};
|
|
78
|
+
const missingKeyFallback = (key) => namespace ? `${namespace}.${key}` : key;
|
|
79
|
+
const translate = (key, values) => resolveToString(key, values) ?? missingKeyFallback(key);
|
|
80
|
+
return Object.assign(translate, {
|
|
81
|
+
/** Returns `true` if the given key exists in the namespace. */
|
|
82
|
+
has: (key) => lookup(key) !== void 0,
|
|
83
|
+
/** Returns the raw unprocessed content for the given key. */
|
|
84
|
+
raw: (key) => lookup(key),
|
|
85
|
+
/**
|
|
86
|
+
* Resolves a message containing `<tag>chunks</tag>` markup, mapping each
|
|
87
|
+
* tag through the matching renderer in `values`.
|
|
88
|
+
*/
|
|
89
|
+
rich: (key, values) => {
|
|
90
|
+
const { scalarValues, renderers } = splitRichValues(values);
|
|
91
|
+
const message = resolveToString(key, scalarValues);
|
|
92
|
+
if (message === void 0) return missingKeyFallback(key);
|
|
93
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: renderRichTokens((0, _intlayer_core_messageFormat.parseTaggedMessage)(message), renderers) });
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* Resolves a message containing `<tag>chunks</tag>` markup into a string,
|
|
97
|
+
* mapping each tag through the matching string renderer in `values`.
|
|
98
|
+
*/
|
|
99
|
+
markup: (key, values) => {
|
|
100
|
+
const { scalarValues, renderers } = splitRichValues(values);
|
|
101
|
+
const message = resolveToString(key, scalarValues);
|
|
102
|
+
if (message === void 0) return missingKeyFallback(key);
|
|
103
|
+
return renderMarkupTokens((0, _intlayer_core_messageFormat.parseTaggedMessage)(message), renderers);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
exports.createTranslator = createTranslator;
|
|
110
|
+
exports.navigatePath = navigatePath;
|
|
111
|
+
//# sourceMappingURL=createTranslator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTranslator.cjs","names":["Fragment"],"sources":["../../src/createTranslator.tsx"],"sourcesContent":["import { getIntlayer } from '@intlayer/core/interpreter';\nimport {\n type MessageValues,\n parseTaggedMessage,\n resolveMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { Fragment, type ReactNode } from 'react';\n\n/** Chunk renderer used by `t.rich()` — maps tag children to a React node. */\nexport type RichChunkRenderer = (chunks: ReactNode) => ReactNode;\n\n/** Chunk renderer used by `t.markup()` — maps tag children to a string. */\nexport type MarkupChunkRenderer = (chunks: string) => string;\n\nexport const navigatePath = (objectValue: unknown, path: string): unknown => {\n if (!path) return objectValue;\n const parts = path.split('.');\n let current: unknown = objectValue;\n for (const part of parts) {\n if (\n current === null ||\n current === undefined ||\n typeof current !== 'object'\n ) {\n return undefined;\n }\n current = (current as Record<string, unknown>)[part];\n }\n return current;\n};\n\n/** Splits rich values into scalar interpolation values and tag renderers. */\nconst splitRichValues = (\n values: Record<string, unknown> = {}\n): { scalarValues: MessageValues; renderers: Record<string, unknown> } => {\n const scalarValues: MessageValues = {};\n const renderers: Record<string, unknown> = {};\n\n for (const [valueKey, value] of Object.entries(values)) {\n if (typeof value === 'function') renderers[valueKey] = value;\n else scalarValues[valueKey] = value;\n }\n\n return { scalarValues, renderers };\n};\n\nconst renderRichTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): ReactNode[] =>\n tokens.map((token, tokenIndex) => {\n if (typeof token === 'string') return token;\n\n const children = renderRichTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n\n if (typeof renderer === 'function') {\n return (\n <Fragment key={tokenIndex}>\n {(renderer as RichChunkRenderer)(children)}\n </Fragment>\n );\n }\n\n // No renderer provided for the tag — render its children unwrapped\n return <Fragment key={tokenIndex}>{children}</Fragment>;\n });\n\nconst renderMarkupTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): string =>\n tokens\n .map((token) => {\n if (typeof token === 'string') return token;\n\n const children = renderMarkupTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n\n if (typeof renderer === 'function') {\n return (renderer as MarkupChunkRenderer)(children);\n }\n\n return children;\n })\n .join('');\n\n/**\n * The untyped runtime translator shared by `useTranslations` (client) and\n * `getTranslations` (server).\n *\n * Behaviour matches next-intl:\n * - namespace `'about'` → keys resolved inside the `about` dictionary\n * - namespace `'about.counter'` → dictionary `about`, key prefix `counter`\n * - no namespace → the first segment of each key is the dictionary key\n * - messages support ICU syntax (plural, select, `#`, formatted arguments)\n * - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided\n * renderers; `t.raw` returns the raw value; `t.has` checks existence\n */\nexport const createTranslator = (locale: LocalesValues, namespace?: string) => {\n const [dictionaryKey, ...prefixSegments] = (namespace ?? '').split('.');\n const keyPrefix = prefixSegments.join('.');\n\n const lookup = (key: string): unknown => {\n let targetDictionaryKey = dictionaryKey;\n let path = keyPrefix ? `${keyPrefix}.${key}` : key;\n\n if (!targetDictionaryKey) {\n // Root scope — the first key segment designates the dictionary\n const [firstSegment, ...restSegments] = key.split('.');\n targetDictionaryKey = firstSegment;\n path = restSegments.join('.');\n }\n\n try {\n const dictionary = getIntlayer(\n targetDictionaryKey as DictionaryKeys,\n locale\n );\n return navigatePath(dictionary, path);\n } catch {\n return undefined;\n }\n };\n\n const resolveToString = (\n key: string,\n values: MessageValues = {}\n ): string | undefined => {\n const rawValue = lookup(key);\n if (rawValue === null || rawValue === undefined) return undefined;\n return resolveMessage(rawValue, values, locale, 'icu');\n };\n\n const missingKeyFallback = (key: string): string =>\n namespace ? `${namespace}.${key}` : key;\n\n const translate = (key: string, values?: MessageValues): string =>\n resolveToString(key, values) ?? missingKeyFallback(key);\n\n return Object.assign(translate, {\n /** Returns `true` if the given key exists in the namespace. */\n has: (key: string): boolean => lookup(key) !== undefined,\n\n /** Returns the raw unprocessed content for the given key. */\n raw: (key: string): unknown => lookup(key),\n\n /**\n * Resolves a message containing `<tag>chunks</tag>` markup, mapping each\n * tag through the matching renderer in `values`.\n */\n rich: (key: string, values?: Record<string, unknown>): ReactNode => {\n const { scalarValues, renderers } = splitRichValues(values);\n const message = resolveToString(key, scalarValues);\n if (message === undefined) return missingKeyFallback(key);\n return <>{renderRichTokens(parseTaggedMessage(message), renderers)}</>;\n },\n\n /**\n * Resolves a message containing `<tag>chunks</tag>` markup into a string,\n * mapping each tag through the matching string renderer in `values`.\n */\n markup: (key: string, values?: Record<string, unknown>): string => {\n const { scalarValues, renderers } = splitRichValues(values);\n const message = resolveToString(key, scalarValues);\n if (message === undefined) return missingKeyFallback(key);\n return renderMarkupTokens(parseTaggedMessage(message), renderers);\n },\n });\n};\n\nexport type CompatTranslator = ReturnType<typeof createTranslator>;\n"],"mappings":";;;;;;;;AAmBA,MAAa,gBAAgB,aAAsB,SAA0B;AAC3E,KAAI,CAAC,KAAM,QAAO;CAClB,MAAM,QAAQ,KAAK,MAAM,IAAI;CAC7B,IAAI,UAAmB;AACvB,MAAK,MAAM,QAAQ,OAAO;AACxB,MACE,YAAY,QACZ,YAAY,UACZ,OAAO,YAAY,SAEnB;AAEF,YAAW,QAAoC;;AAEjD,QAAO;;;AAIT,MAAM,mBACJ,SAAkC,EAAE,KACoC;CACxE,MAAM,eAA8B,EAAE;CACtC,MAAM,YAAqC,EAAE;AAE7C,MAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,OAAO,CACpD,KAAI,OAAO,UAAU,WAAY,WAAU,YAAY;KAClD,cAAa,YAAY;AAGhC,QAAO;EAAE;EAAc;EAAW;;AAGpC,MAAM,oBACJ,QACA,cAEA,OAAO,KAAK,OAAO,eAAe;AAChC,KAAI,OAAO,UAAU,SAAU,QAAO;CAEtC,MAAM,WAAW,iBAAiB,MAAM,UAAU,UAAU;CAC5D,MAAM,WAAW,UAAU,MAAM;AAEjC,KAAI,OAAO,aAAa,WACtB,QACE,2CAACA,gBAAD,YACI,SAA+B,SAAS,EACjC,EAFI,WAEJ;AAKf,QAAO,2CAACA,gBAAD,EAA4B,UAAoB,EAAjC,WAAiC;EACvD;AAEJ,MAAM,sBACJ,QACA,cAEA,OACG,KAAK,UAAU;AACd,KAAI,OAAO,UAAU,SAAU,QAAO;CAEtC,MAAM,WAAW,mBAAmB,MAAM,UAAU,UAAU;CAC9D,MAAM,WAAW,UAAU,MAAM;AAEjC,KAAI,OAAO,aAAa,WACtB,QAAQ,SAAiC,SAAS;AAGpD,QAAO;EACP,CACD,KAAK,GAAG;;;;;;;;;;;;;AAcb,MAAa,oBAAoB,QAAuB,cAAuB;CAC7E,MAAM,CAAC,eAAe,GAAG,mBAAmB,aAAa,IAAI,MAAM,IAAI;CACvE,MAAM,YAAY,eAAe,KAAK,IAAI;CAE1C,MAAM,UAAU,QAAyB;EACvC,IAAI,sBAAsB;EAC1B,IAAI,OAAO,YAAY,GAAG,UAAU,GAAG,QAAQ;AAE/C,MAAI,CAAC,qBAAqB;GAExB,MAAM,CAAC,cAAc,GAAG,gBAAgB,IAAI,MAAM,IAAI;AACtD,yBAAsB;AACtB,UAAO,aAAa,KAAK,IAAI;;AAG/B,MAAI;AAKF,UAAO,yDAHL,qBACA,OAE4B,EAAE,KAAK;UAC/B;AACN;;;CAIJ,MAAM,mBACJ,KACA,SAAwB,EAAE,KACH;EACvB,MAAM,WAAW,OAAO,IAAI;AAC5B,MAAI,aAAa,QAAQ,aAAa,OAAW,QAAO;AACxD,0DAAsB,UAAU,QAAQ,QAAQ,MAAM;;CAGxD,MAAM,sBAAsB,QAC1B,YAAY,GAAG,UAAU,GAAG,QAAQ;CAEtC,MAAM,aAAa,KAAa,WAC9B,gBAAgB,KAAK,OAAO,IAAI,mBAAmB,IAAI;AAEzD,QAAO,OAAO,OAAO,WAAW;;EAE9B,MAAM,QAAyB,OAAO,IAAI,KAAK;;EAG/C,MAAM,QAAyB,OAAO,IAAI;;;;;EAM1C,OAAO,KAAa,WAAgD;GAClE,MAAM,EAAE,cAAc,cAAc,gBAAgB,OAAO;GAC3D,MAAM,UAAU,gBAAgB,KAAK,aAAa;AAClD,OAAI,YAAY,OAAW,QAAO,mBAAmB,IAAI;AACzD,UAAO,mFAAG,sEAAoC,QAAQ,EAAE,UAAU,EAAI;;;;;;EAOxE,SAAS,KAAa,WAA6C;GACjE,MAAM,EAAE,cAAc,cAAc,gBAAgB,OAAO;GAC3D,MAAM,UAAU,gBAAgB,KAAK,aAAa;AAClD,OAAI,YAAY,OAAW,QAAO,mBAAmB,IAAI;AACzD,UAAO,wEAAsC,QAAQ,EAAE,UAAU;;EAEpE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_server_getLocale = require('./server/getLocale.cjs');
|
|
4
|
+
let next_intlayer = require("next-intlayer");
|
|
5
|
+
|
|
6
|
+
//#region src/getDictionary.ts
|
|
7
|
+
const navigatePath = (objectValue, path) => {
|
|
8
|
+
if (!path) return objectValue;
|
|
9
|
+
const parts = path.split(".");
|
|
10
|
+
let current = objectValue;
|
|
11
|
+
for (const part of parts) {
|
|
12
|
+
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
13
|
+
current = current[part];
|
|
14
|
+
}
|
|
15
|
+
return current;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Dictionary-accepting variant of `getTranslations`.
|
|
19
|
+
*
|
|
20
|
+
* Used internally by the SWC optimization: instead of looking up the dictionary
|
|
21
|
+
* at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
|
|
22
|
+
* and passes it directly here. This enables tree-shaking of unused locale content.
|
|
23
|
+
*
|
|
24
|
+
* Runs on the server, where next-intl apps do not mount an `IntlayerServerProvider`.
|
|
25
|
+
* The request locale therefore cannot be read from a server context and is resolved
|
|
26
|
+
* asynchronously from the cookie/header via `getLocale()`. `getTranslations` is always
|
|
27
|
+
* awaited, so an async resolver is a drop-in replacement.
|
|
28
|
+
*/
|
|
29
|
+
const getDictionary = async (dictionary, namespacePrefix) => {
|
|
30
|
+
const content = (0, next_intlayer.getDictionary)(dictionary, await require_server_getLocale.getLocale());
|
|
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.getDictionary = getDictionary;
|
|
45
|
+
//# sourceMappingURL=getDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDictionary.cjs","names":["getLocale"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getDictionary as getDictionaryBase } from 'next-intlayer';\nimport { getLocale } from './server/getLocale';\n\nconst navigatePath = (objectValue: unknown, path: string): unknown => {\n if (!path) return objectValue;\n const parts = path.split('.');\n let current: unknown = objectValue;\n for (const part of parts) {\n if (\n current === null ||\n current === undefined ||\n typeof current !== 'object'\n ) {\n return undefined;\n }\n current = (current as Record<string, unknown>)[part];\n }\n return current;\n};\n\n/**\n * Dictionary-accepting variant of `getTranslations`.\n *\n * Used internally by the SWC optimization: instead of looking up the dictionary\n * at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time\n * and passes it directly here. This enables tree-shaking of unused locale content.\n *\n * Runs on the server, where next-intl apps do not mount an `IntlayerServerProvider`.\n * The request locale therefore cannot be read from a server context and is resolved\n * asynchronously from the cookie/header via `getLocale()`. `getTranslations` is always\n * awaited, so an async resolver is a drop-in replacement.\n */\nexport const getDictionary = async <T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n) => {\n const locale = (await getLocale()) as LocalesValues;\n const content = getDictionaryBase(dictionary, locale);\n\n const resolveKey = (key: string): string =>\n namespacePrefix ? `${namespacePrefix}.${key}` : key;\n\n return Object.assign(\n <P extends ValidDotPathsFor<any>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const str = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{${k}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<any>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<any>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;;;;AAMA,MAAM,gBAAgB,aAAsB,SAA0B;AACpE,KAAI,CAAC,KAAM,QAAO;CAClB,MAAM,QAAQ,KAAK,MAAM,IAAI;CAC7B,IAAI,UAAmB;AACvB,MAAK,MAAM,QAAQ,OAAO;AACxB,MACE,YAAY,QACZ,YAAY,UACZ,OAAO,YAAY,SAEnB;AAEF,YAAW,QAAoC;;AAEjD,QAAO;;;;;;;;;;;;;;AAeT,MAAa,gBAAgB,OAC3B,YACA,oBACG;CAEH,MAAM,2CAA4B,YAAY,MADxBA,oCAAW,CACoB;CAErD,MAAM,cAAc,QAClB,kBAAkB,GAAG,gBAAgB,GAAG,QAAQ;AAElD,QAAO,OAAO,QAEV,QACA,WACW;EACX,MAAM,WAAW,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EAClE,MAAM,MAAM,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC1D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,MACnC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,IAAI,EAAE,GAC/C;IAEH;EACE,MAAuC,WACrC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAAuC,WACrC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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/getDictionaryDynamic.ts
|
|
6
|
+
const navigatePath = (objectValue, path) => {
|
|
7
|
+
if (!path) return objectValue;
|
|
8
|
+
const parts = path.split(".");
|
|
9
|
+
let current = objectValue;
|
|
10
|
+
for (const part of parts) {
|
|
11
|
+
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
12
|
+
current = current[part];
|
|
13
|
+
}
|
|
14
|
+
return current;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Dynamic dictionary-accepting variant of `getTranslations`.
|
|
18
|
+
*/
|
|
19
|
+
const getDictionaryDynamic = async (dictionaryPromise, key, namespacePrefix) => {
|
|
20
|
+
const content = await (0, next_intlayer_server.useDictionaryDynamic)(dictionaryPromise, key);
|
|
21
|
+
const resolveKey = (lookupKey) => namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;
|
|
22
|
+
return Object.assign((lookup, params) => {
|
|
23
|
+
const rawValue = navigatePath(content, resolveKey(String(lookup)));
|
|
24
|
+
const str = String(rawValue ?? resolveKey(String(lookup)));
|
|
25
|
+
if (!params) return str;
|
|
26
|
+
return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
27
|
+
}, {
|
|
28
|
+
has: (lookup) => navigatePath(content, resolveKey(String(lookup))) != null,
|
|
29
|
+
raw: (lookup) => navigatePath(content, resolveKey(String(lookup)))
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.getDictionaryDynamic = getDictionaryDynamic;
|
|
35
|
+
//# sourceMappingURL=getDictionaryDynamic.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDictionaryDynamic.cjs","names":[],"sources":["../../src/getDictionaryDynamic.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useDictionaryDynamic as getDictionaryDynamicBase } from 'next-intlayer/server';\n\nconst navigatePath = (objectValue: unknown, path: string): unknown => {\n if (!path) return objectValue;\n const parts = path.split('.');\n let current: unknown = objectValue;\n for (const part of parts) {\n if (\n current === null ||\n current === undefined ||\n typeof current !== 'object'\n ) {\n return undefined;\n }\n current = (current as Record<string, unknown>)[part];\n }\n return current;\n};\n\n/**\n * Dynamic dictionary-accepting variant of `getTranslations`.\n */\nexport const getDictionaryDynamic = async <\n const T extends Dictionary,\n const K extends string,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix?: string\n) => {\n const content = await getDictionaryDynamicBase<T, any>(\n dictionaryPromise,\n key as any\n );\n\n const resolveKey = (lookupKey: string): string =>\n namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;\n\n return Object.assign(\n <P extends ValidDotPathsFor<any>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const str = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{${k}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<any>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<any>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;;;AAKA,MAAM,gBAAgB,aAAsB,SAA0B;AACpE,KAAI,CAAC,KAAM,QAAO;CAClB,MAAM,QAAQ,KAAK,MAAM,IAAI;CAC7B,IAAI,UAAmB;AACvB,MAAK,MAAM,QAAQ,OAAO;AACxB,MACE,YAAY,QACZ,YAAY,UACZ,OAAO,YAAY,SAEnB;AAEF,YAAW,QAAoC;;AAEjD,QAAO;;;;;AAMT,MAAa,uBAAuB,OAIlC,mBACA,KACA,oBACG;CACH,MAAM,UAAU,qDACd,mBACA,IACD;CAED,MAAM,cAAc,cAClB,kBAAkB,GAAG,gBAAgB,GAAG,cAAc;AAExD,QAAO,OAAO,QAEV,QACA,WACW;EACX,MAAM,WAAW,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EAClE,MAAM,MAAM,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC1D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,MACnC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,IAAI,EAAE,GAC/C;IAEH;EACE,MAAuC,WACrC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAAuC,WACrC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
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/getTranslationsDictionary.ts
|
|
6
|
+
/**
|
|
7
|
+
* Dictionary-accepting variant of `getTranslations`.
|
|
8
|
+
*
|
|
9
|
+
* Used internally by the SWC optimization: instead of looking up the dictionary
|
|
10
|
+
* at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
|
|
11
|
+
* and passes it directly here. This enables tree-shaking of unused locale content.
|
|
12
|
+
*/
|
|
13
|
+
const getTranslationsDictionary = async (dictionary, namespacePrefix) => {
|
|
14
|
+
const content = (0, next_intlayer_server.getDictionary)(dictionary);
|
|
15
|
+
return (lookup, params) => {
|
|
16
|
+
const lookupKey = namespacePrefix ? `${namespacePrefix}.${String(lookup)}` : String(lookup);
|
|
17
|
+
const parts = lookupKey.split(".");
|
|
18
|
+
let current = content;
|
|
19
|
+
for (const part of parts) {
|
|
20
|
+
if (current == null) break;
|
|
21
|
+
current = current[part];
|
|
22
|
+
}
|
|
23
|
+
const str = String(current ?? lookupKey);
|
|
24
|
+
if (!params) return str;
|
|
25
|
+
return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.getTranslationsDictionary = getTranslationsDictionary;
|
|
31
|
+
//# sourceMappingURL=getTranslationsDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTranslationsDictionary.cjs","names":[],"sources":["../../src/getTranslationsDictionary.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getDictionary } from 'next-intlayer/server';\n\n/**\n * Dictionary-accepting variant of `getTranslations`.\n *\n * Used internally by the SWC optimization: instead of looking up the dictionary\n * at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time\n * and passes it directly here. This enables tree-shaking of unused locale content.\n */\nexport const getTranslationsDictionary = async <T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n) => {\n const content = getDictionary(dictionary);\n\n return <P extends ValidDotPathsFor<any>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const lookupKey = namespacePrefix\n ? `${namespacePrefix}.${String(lookup)}`\n : String(lookup);\n const parts = lookupKey.split('.');\n let current: any = content;\n for (const part of parts) {\n if (current == null) break;\n current = current[part];\n }\n const str = String(current ?? lookupKey);\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{${k}}`\n );\n };\n};\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,4BAA4B,OACvC,YACA,oBACG;CACH,MAAM,kDAAwB,WAAW;AAEzC,SACE,QACA,WACW;EACX,MAAM,YAAY,kBACd,GAAG,gBAAgB,GAAG,OAAO,OAAO,KACpC,OAAO,OAAO;EAClB,MAAM,QAAQ,UAAU,MAAM,IAAI;EAClC,IAAI,UAAe;AACnB,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,WAAW,KAAM;AACrB,aAAU,QAAQ;;EAEpB,MAAM,MAAM,OAAO,WAAW,UAAU;AACxC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,MACnC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,IAAI,EAAE,GAC/C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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/getTranslationsDictionaryDynamic.ts
|
|
6
|
+
/**
|
|
7
|
+
* Dynamic dictionary-accepting variant of `getTranslations`.
|
|
8
|
+
*/
|
|
9
|
+
const getTranslationsDictionaryDynamic = async (dictionaryPromise, key, namespacePrefix) => {
|
|
10
|
+
const content = await (0, next_intlayer_server.getDictionaryDynamic)(dictionaryPromise, key);
|
|
11
|
+
return (lookup, params) => {
|
|
12
|
+
const lookupKey = namespacePrefix ? `${namespacePrefix}.${String(lookup)}` : String(lookup);
|
|
13
|
+
const parts = lookupKey.split(".");
|
|
14
|
+
let current = content;
|
|
15
|
+
for (const part of parts) {
|
|
16
|
+
if (current == null) break;
|
|
17
|
+
current = current[part];
|
|
18
|
+
}
|
|
19
|
+
const str = String(current ?? lookupKey);
|
|
20
|
+
if (!params) return str;
|
|
21
|
+
return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.getTranslationsDictionaryDynamic = getTranslationsDictionaryDynamic;
|
|
27
|
+
//# sourceMappingURL=getTranslationsDictionaryDynamic.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTranslationsDictionaryDynamic.cjs","names":[],"sources":["../../src/getTranslationsDictionaryDynamic.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { getDictionaryDynamic } from 'next-intlayer/server';\n\n/**\n * Dynamic dictionary-accepting variant of `getTranslations`.\n */\nexport const getTranslationsDictionaryDynamic = async <\n const T extends Dictionary,\n const K extends string,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix?: string\n) => {\n const content = await getDictionaryDynamic<T, any>(\n dictionaryPromise,\n key as any\n );\n\n return <P extends ValidDotPathsFor<any>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const lookupKey = namespacePrefix\n ? `${namespacePrefix}.${String(lookup)}`\n : String(lookup);\n const parts = lookupKey.split('.');\n let current: any = content;\n for (const part of parts) {\n if (current == null) break;\n current = current[part];\n }\n const str = String(current ?? lookupKey);\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{${k}}`\n );\n };\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,mCAAmC,OAI9C,mBACA,KACA,oBACG;CACH,MAAM,UAAU,qDACd,mBACA,IACD;AAED,SACE,QACA,WACW;EACX,MAAM,YAAY,kBACd,GAAG,gBAAgB,GAAG,OAAO,OAAO,KACpC,OAAO,OAAO;EAClB,MAAM,QAAQ,UAAU,MAAM,IAAI;EAClC,IAAI,UAAe;AACnB,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,WAAW,KAAM;AACrB,aAAU,QAAQ;;EAEpB,MAAM,MAAM,OAAO,WAAW,UAAU;AACxC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,MACnC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,IAAI,EAAE,GAC/C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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/hasLocale.ts
|
|
6
|
+
/**
|
|
7
|
+
* Drop-in for next-intl's `hasLocale`.
|
|
8
|
+
*
|
|
9
|
+
* Checks that a locale candidate is part of the given locales list (or, when
|
|
10
|
+
* the list is read from routing, the locales configured in intlayer).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { routing } from '@/i18n/routing';
|
|
15
|
+
*
|
|
16
|
+
* if (hasLocale(routing.locales, requested)) { … }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
const hasLocale = ((locales, candidate) => {
|
|
20
|
+
return (locales ?? _intlayer_config_built.internationalization?.locales?.map(String) ?? []).includes(candidate);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.hasLocale = hasLocale;
|
|
25
|
+
//# sourceMappingURL=hasLocale.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasLocale.cjs","names":["internationalization"],"sources":["../../src/hasLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { hasLocale as _hasLocale } from 'next-intl';\n\n/**\n * Drop-in for next-intl's `hasLocale`.\n *\n * Checks that a locale candidate is part of the given locales list (or, when\n * the list is read from routing, the locales configured in intlayer).\n *\n * @example\n * ```ts\n * import { routing } from '@/i18n/routing';\n *\n * if (hasLocale(routing.locales, requested)) { … }\n * ```\n */\nexport const hasLocale: typeof _hasLocale = ((\n locales: readonly string[],\n candidate: string | undefined | null\n): boolean => {\n const availableLocales =\n locales ?? internationalization?.locales?.map(String) ?? [];\n return availableLocales.includes(candidate as string);\n}) as typeof _hasLocale;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,MAAa,cACX,SACA,cACY;AAGZ,SADE,WAAWA,6CAAsB,SAAS,IAAI,OAAO,IAAI,EAAE,EACrC,SAAS,UAAoB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_routing = require('./routing.cjs');
|
|
3
|
+
const require_hasLocale = require('./hasLocale.cjs');
|
|
4
|
+
const require_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
|
|
5
|
+
const require_useDictionary = require('./useDictionary.cjs');
|
|
6
|
+
const require_client_helpers = require('./client/helpers.cjs');
|
|
7
|
+
const require_client_NextIntlClientProvider = require('./client/NextIntlClientProvider.cjs');
|
|
8
|
+
const require_client_useLocale = require('./client/useLocale.cjs');
|
|
9
|
+
const require_client_useTranslations = require('./client/useTranslations.cjs');
|
|
10
|
+
|
|
11
|
+
exports.IntlProvider = require_client_helpers.IntlProvider;
|
|
12
|
+
exports.NextIntlClientProvider = require_client_NextIntlClientProvider.NextIntlClientProvider;
|
|
13
|
+
exports.defineRouting = require_routing.defineRouting;
|
|
14
|
+
exports.hasLocale = require_hasLocale.hasLocale;
|
|
15
|
+
exports.useDictionary = require_useDictionary.useDictionary;
|
|
16
|
+
exports.useDictionaryDynamic = require_useDictionaryDynamic.useDictionaryDynamic;
|
|
17
|
+
exports.useExtracted = require_client_helpers.useExtracted;
|
|
18
|
+
exports.useFormatter = require_client_helpers.useFormatter;
|
|
19
|
+
exports.useLocale = require_client_useLocale.useLocale;
|
|
20
|
+
exports.useMessages = require_client_helpers.useMessages;
|
|
21
|
+
exports.useNow = require_client_helpers.useNow;
|
|
22
|
+
exports.useTimeZone = require_client_helpers.useTimeZone;
|
|
23
|
+
exports.useTranslations = require_client_useTranslations.useTranslations;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let next_intlayer_middleware = require("next-intlayer/middleware");
|
|
4
|
+
|
|
5
|
+
//#region src/middleware.ts
|
|
6
|
+
/**
|
|
7
|
+
* Drop-in replacement for next-intl's `createMiddleware`.
|
|
8
|
+
*
|
|
9
|
+
* Returns Intlayer's proxy/middleware, which handles locale detection and
|
|
10
|
+
* routing from the Intlayer configuration. The `routing` argument is accepted
|
|
11
|
+
* for API compatibility but ignored — locales come from `intlayer.config`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // proxy.ts (or middleware.ts on Next <= 15)
|
|
16
|
+
* import createMiddleware from 'next-intl/middleware';
|
|
17
|
+
* export default createMiddleware(routing);
|
|
18
|
+
* export const config = { matcher: ['/((?!api|_next|.*\\..*).*)'] };
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const createMiddleware = (_routing) => (request, event) => {
|
|
22
|
+
const response = (0, next_intlayer_middleware.intlayerMiddleware)(request, event);
|
|
23
|
+
if (response) {
|
|
24
|
+
const resolvedLocale = response.headers.get("x-intlayer-locale");
|
|
25
|
+
if (resolvedLocale) response.cookies.set("NEXT_LOCALE", resolvedLocale, {
|
|
26
|
+
path: "/",
|
|
27
|
+
sameSite: "lax",
|
|
28
|
+
maxAge: 3600 * 24 * 365
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return response;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.createMiddleware = createMiddleware;
|
|
36
|
+
exports.default = createMiddleware;
|
|
37
|
+
//# sourceMappingURL=middleware.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.cjs","names":[],"sources":["../../src/middleware.ts"],"sourcesContent":["import type { NextFetchEvent, NextRequest } from 'next/server';\nimport type _createMiddleware from 'next-intl/middleware';\nimport { intlayerMiddleware } from 'next-intlayer/middleware';\n\n/**\n * Drop-in replacement for next-intl's `createMiddleware`.\n *\n * Returns Intlayer's proxy/middleware, which handles locale detection and\n * routing from the Intlayer configuration. The `routing` argument is accepted\n * for API compatibility but ignored — locales come from `intlayer.config`.\n *\n * @example\n * ```ts\n * // proxy.ts (or middleware.ts on Next <= 15)\n * import createMiddleware from 'next-intl/middleware';\n * export default createMiddleware(routing);\n * export const config = { matcher: ['/((?!api|_next|.*\\\\..*).*)'] };\n * ```\n */\nexport const createMiddleware: typeof _createMiddleware =\n (_routing?: unknown) => (request: NextRequest, event?: NextFetchEvent) => {\n const response = intlayerMiddleware(request, event);\n\n if (response) {\n // Intlayer middleware writes the resolved locale to the x-intlayer-locale header\n // We read it and explicitly set the NEXT_LOCALE cookie to maintain compatibility with next-intl\n const resolvedLocale = response.headers.get('x-intlayer-locale');\n if (resolvedLocale) {\n response.cookies.set('NEXT_LOCALE', resolvedLocale, {\n path: '/',\n sameSite: 'lax',\n maxAge: 60 * 60 * 24 * 365,\n });\n }\n }\n\n return response;\n };\n\nexport default createMiddleware;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,oBACV,cAAwB,SAAsB,UAA2B;CACxE,MAAM,4DAA8B,SAAS,MAAM;AAEnD,KAAI,UAAU;EAGZ,MAAM,iBAAiB,SAAS,QAAQ,IAAI,oBAAoB;AAChE,MAAI,eACF,UAAS,QAAQ,IAAI,eAAe,gBAAgB;GAClD,MAAM;GACN,UAAU;GACV,QAAQ,OAAU,KAAK;GACxB,CAAC;;AAIN,QAAO"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
const require_navigation_localizeHref = require('./localizeHref.cjs');
|
|
6
|
+
let next_intlayer = require("next-intlayer");
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
let next_link = require("next/link");
|
|
10
|
+
next_link = require_runtime.__toESM(next_link);
|
|
11
|
+
|
|
12
|
+
//#region src/navigation/Link.tsx
|
|
13
|
+
/**
|
|
14
|
+
* Drop-in for the `Link` returned by next-intl's `createNavigation`. Prefixes
|
|
15
|
+
* `href` with the active locale (or the `locale` prop) before delegating to
|
|
16
|
+
* `next/link`.
|
|
17
|
+
*/
|
|
18
|
+
const Link = (0, react.forwardRef)(({ href, locale, ...rest }, ref) => {
|
|
19
|
+
const { locale: currentLocale } = (0, next_intlayer.useLocale)();
|
|
20
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(next_link.default, {
|
|
21
|
+
ref,
|
|
22
|
+
href: require_navigation_localizeHref.localizeHref(href, locale ?? currentLocale),
|
|
23
|
+
...rest
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
Link.displayName = "Link";
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.Link = Link;
|
|
30
|
+
//# sourceMappingURL=Link.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Link.cjs","names":["NextLink","localizeHref"],"sources":["../../../src/navigation/Link.tsx"],"sourcesContent":["'use client';\n\nimport NextLink from 'next/link';\nimport { useLocale } from 'next-intlayer';\nimport { type ComponentPropsWithoutRef, forwardRef, type Ref } from 'react';\nimport { localizeHref, type NextIntlHref } from './localizeHref';\n\n/**\n * Props for the compat `Link`: identical to `next/link` except `href` accepts a\n * `next-intl` href and an optional `locale` overrides the current one.\n */\nexport type LinkProps = Omit<\n ComponentPropsWithoutRef<typeof NextLink>,\n 'href' | 'locale'\n> & {\n href: NextIntlHref;\n locale?: string;\n};\n\n/**\n * Drop-in for the `Link` returned by next-intl's `createNavigation`. Prefixes\n * `href` with the active locale (or the `locale` prop) before delegating to\n * `next/link`.\n */\nexport const Link = forwardRef(\n ({ href, locale, ...rest }: LinkProps, ref: Ref<HTMLAnchorElement>) => {\n const { locale: currentLocale } = useLocale();\n const targetLocale = locale ?? (currentLocale as string);\n\n return (\n <NextLink ref={ref} href={localizeHref(href, targetLocale)} {...rest} />\n );\n }\n);\n\nLink.displayName = 'Link';\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,MAAa,8BACV,EAAE,MAAM,QAAQ,GAAG,QAAmB,QAAgC;CACrE,MAAM,EAAE,QAAQ,gDAA6B;AAG7C,QACE,2CAACA,mBAAD;EAAe;EAAK,MAAMC,6CAAa,MAHpB,UAAW,cAG4B;EAAE,GAAI;EAAQ;EAG7E;AAED,KAAK,cAAc"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_navigation_localizeHref = require('./localizeHref.cjs');
|
|
4
|
+
const require_navigation_Link = require('./Link.cjs');
|
|
5
|
+
const require_navigation_hooks = require('./hooks.cjs');
|
|
6
|
+
let next_navigation = require("next/navigation");
|
|
7
|
+
|
|
8
|
+
//#region src/navigation/createNavigation.ts
|
|
9
|
+
/**
|
|
10
|
+
* Drop-in replacement for next-intl's `createNavigation`.
|
|
11
|
+
*
|
|
12
|
+
* Returns locale-aware navigation APIs (`Link`, `usePathname`, `useRouter`,
|
|
13
|
+
* `getPathname`, `redirect`, `permanentRedirect`) backed by Intlayer's routing
|
|
14
|
+
* configuration. The `routing` argument is accepted for API compatibility;
|
|
15
|
+
* locales come from the Intlayer configuration.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* export const { Link, redirect, usePathname, useRouter, getPathname } =
|
|
20
|
+
* createNavigation();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const createNavigation = (_routing) => {
|
|
24
|
+
const getPathname = ({ href, locale }) => require_navigation_localizeHref.localizeHref(href, locale);
|
|
25
|
+
const redirect = ({ href, locale }, type) => (0, next_navigation.redirect)(require_navigation_localizeHref.localizeHref(href, locale), type);
|
|
26
|
+
const permanentRedirect = ({ href, locale }, type) => (0, next_navigation.permanentRedirect)(require_navigation_localizeHref.localizeHref(href, locale), type);
|
|
27
|
+
return {
|
|
28
|
+
Link: require_navigation_Link.Link,
|
|
29
|
+
usePathname: require_navigation_hooks.usePathname,
|
|
30
|
+
useRouter: require_navigation_hooks.useRouter,
|
|
31
|
+
getPathname,
|
|
32
|
+
redirect,
|
|
33
|
+
permanentRedirect
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.createNavigation = createNavigation;
|
|
39
|
+
exports.default = createNavigation;
|
|
40
|
+
//# sourceMappingURL=createNavigation.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createNavigation.cjs","names":["localizeHref","Link"],"sources":["../../../src/navigation/createNavigation.ts"],"sourcesContent":["import {\n permanentRedirect as nextPermanentRedirect,\n redirect as nextRedirect,\n} from 'next/navigation';\nimport type { createNavigation as _createNavigation } from 'next-intl/navigation';\nimport { usePathname, useRouter } from './hooks';\nimport { Link } from './Link';\nimport { localizeHref, type NextIntlHref } from './localizeHref';\n\n/** Arguments shared by `getPathname`, `redirect` and `permanentRedirect`. */\ntype LocalizedHrefArgs = { href: NextIntlHref; locale: string };\n\n/** The optional `RedirectType` accepted by `next/navigation`'s redirect APIs. */\ntype RedirectTypeArg = Parameters<typeof nextRedirect>[1];\n\n/**\n * Drop-in replacement for next-intl's `createNavigation`.\n *\n * Returns locale-aware navigation APIs (`Link`, `usePathname`, `useRouter`,\n * `getPathname`, `redirect`, `permanentRedirect`) backed by Intlayer's routing\n * configuration. The `routing` argument is accepted for API compatibility;\n * locales come from the Intlayer configuration.\n *\n * @example\n * ```ts\n * export const { Link, redirect, usePathname, useRouter, getPathname } =\n * createNavigation();\n * ```\n */\nexport const createNavigation: typeof _createNavigation = (\n _routing?: unknown\n) => {\n const getPathname = ({ href, locale }: LocalizedHrefArgs): string =>\n localizeHref(href, locale);\n\n const redirect = (\n { href, locale }: LocalizedHrefArgs,\n type?: RedirectTypeArg\n ) => nextRedirect(localizeHref(href, locale), type);\n\n const permanentRedirect = (\n { href, locale }: LocalizedHrefArgs,\n type?: RedirectTypeArg\n ) => nextPermanentRedirect(localizeHref(href, locale), type);\n\n return {\n Link: Link as ReturnType<typeof _createNavigation>['Link'],\n usePathname,\n useRouter,\n getPathname,\n redirect,\n permanentRedirect,\n } as ReturnType<typeof _createNavigation>;\n};\n\nexport default createNavigation;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,oBACX,aACG;CACH,MAAM,eAAe,EAAE,MAAM,aAC3BA,6CAAa,MAAM,OAAO;CAE5B,MAAM,YACJ,EAAE,MAAM,UACR,uCACgBA,6CAAa,MAAM,OAAO,EAAE,KAAK;CAEnD,MAAM,qBACJ,EAAE,MAAM,UACR,gDACyBA,6CAAa,MAAM,OAAO,EAAE,KAAK;AAE5D,QAAO;EACL,MAAMC;EACN;EACA;EACA;EACA;EACA;EACD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
const require_navigation_localizeHref = require('./localizeHref.cjs');
|
|
6
|
+
let next_intlayer = require("next-intlayer");
|
|
7
|
+
let next_navigation = require("next/navigation");
|
|
8
|
+
|
|
9
|
+
//#region src/navigation/hooks.ts
|
|
10
|
+
/**
|
|
11
|
+
* Drop-in for the `usePathname` returned by next-intl's `createNavigation`.
|
|
12
|
+
* Returns the current pathname with the locale prefix stripped.
|
|
13
|
+
*/
|
|
14
|
+
const usePathname = () => {
|
|
15
|
+
const pathname = (0, next_navigation.usePathname)();
|
|
16
|
+
const { locale } = (0, next_intlayer.useLocale)();
|
|
17
|
+
const prefix = `/${locale}`;
|
|
18
|
+
if (pathname === prefix) return "/";
|
|
19
|
+
if (pathname.startsWith(`${prefix}/`)) return pathname.slice(prefix.length);
|
|
20
|
+
return pathname;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Drop-in for the `useRouter` returned by next-intl's `createNavigation`.
|
|
24
|
+
* Wraps the Next.js router so `push`/`replace`/`prefetch` localize their href
|
|
25
|
+
* (honouring an optional `locale` option) before navigating.
|
|
26
|
+
*/
|
|
27
|
+
const useRouter = () => {
|
|
28
|
+
const router = (0, next_navigation.useRouter)();
|
|
29
|
+
const { locale: currentLocale } = (0, next_intlayer.useLocale)();
|
|
30
|
+
const localize = (href, locale) => require_navigation_localizeHref.localizeHref(href, locale ?? currentLocale);
|
|
31
|
+
return {
|
|
32
|
+
...router,
|
|
33
|
+
push: (href, options) => router.push(localize(href, options?.locale), options),
|
|
34
|
+
replace: (href, options) => router.replace(localize(href, options?.locale), options),
|
|
35
|
+
prefetch: (href, options) => router.prefetch(localize(href, options?.locale))
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.usePathname = usePathname;
|
|
41
|
+
exports.useRouter = useRouter;
|
|
42
|
+
//# sourceMappingURL=hooks.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.cjs","names":["localizeHref"],"sources":["../../../src/navigation/hooks.ts"],"sourcesContent":["'use client';\n\nimport {\n usePathname as useNextPathname,\n useRouter as useNextRouter,\n} from 'next/navigation';\nimport { useLocale } from 'next-intlayer';\nimport { localizeHref, type NextIntlHref } from './localizeHref';\n\n/**\n * Options accepted by the locale-aware router methods: the standard Next.js\n * navigate options plus an optional target `locale`.\n */\ntype NavigateOptions = { locale?: string } & Record<string, unknown>;\n\n/**\n * Drop-in for the `usePathname` returned by next-intl's `createNavigation`.\n * Returns the current pathname with the locale prefix stripped.\n */\nexport const usePathname = (): string => {\n const pathname = useNextPathname();\n const { locale } = useLocale();\n const prefix = `/${locale}`;\n\n if (pathname === prefix) return '/';\n if (pathname.startsWith(`${prefix}/`)) return pathname.slice(prefix.length);\n return pathname;\n};\n\n/**\n * Drop-in for the `useRouter` returned by next-intl's `createNavigation`.\n * Wraps the Next.js router so `push`/`replace`/`prefetch` localize their href\n * (honouring an optional `locale` option) before navigating.\n */\nexport const useRouter = () => {\n const router = useNextRouter();\n const { locale: currentLocale } = useLocale();\n\n const localize = (href: NextIntlHref, locale?: string): string =>\n localizeHref(href, locale ?? (currentLocale as string));\n\n return {\n ...router,\n push: (href: NextIntlHref, options?: NavigateOptions) =>\n router.push(\n localize(href, options?.locale),\n options as Parameters<typeof router.push>[1]\n ),\n replace: (href: NextIntlHref, options?: NavigateOptions) =>\n router.replace(\n localize(href, options?.locale),\n options as Parameters<typeof router.replace>[1]\n ),\n prefetch: (href: NextIntlHref, options?: NavigateOptions) =>\n router.prefetch(localize(href, options?.locale)),\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAmBA,MAAa,oBAA4B;CACvC,MAAM,6CAA4B;CAClC,MAAM,EAAE,yCAAsB;CAC9B,MAAM,SAAS,IAAI;AAEnB,KAAI,aAAa,OAAQ,QAAO;AAChC,KAAI,SAAS,WAAW,GAAG,OAAO,GAAG,CAAE,QAAO,SAAS,MAAM,OAAO,OAAO;AAC3E,QAAO;;;;;;;AAQT,MAAa,kBAAkB;CAC7B,MAAM,yCAAwB;CAC9B,MAAM,EAAE,QAAQ,gDAA6B;CAE7C,MAAM,YAAY,MAAoB,WACpCA,6CAAa,MAAM,UAAW,cAAyB;AAEzD,QAAO;EACL,GAAG;EACH,OAAO,MAAoB,YACzB,OAAO,KACL,SAAS,MAAM,SAAS,OAAO,EAC/B,QACD;EACH,UAAU,MAAoB,YAC5B,OAAO,QACL,SAAS,MAAM,SAAS,OAAO,EAC/B,QACD;EACH,WAAW,MAAoB,YAC7B,OAAO,SAAS,SAAS,MAAM,SAAS,OAAO,CAAC;EACnD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_navigation_Link = require('./Link.cjs');
|
|
3
|
+
const require_navigation_hooks = require('./hooks.cjs');
|
|
4
|
+
const require_navigation_createNavigation = require('./createNavigation.cjs');
|
|
5
|
+
|
|
6
|
+
exports.Link = require_navigation_Link.Link;
|
|
7
|
+
exports.createNavigation = require_navigation_createNavigation.createNavigation;
|
|
8
|
+
exports.default = require_navigation_createNavigation.createNavigation;
|
|
9
|
+
exports.usePathname = require_navigation_hooks.usePathname;
|
|
10
|
+
exports.useRouter = require_navigation_hooks.useRouter;
|