@intlayer/next-intl 9.0.0-canary.2 → 9.0.0-canary.4
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/dist/cjs/client/NextIntlClientProvider.cjs +7 -3
- package/dist/cjs/client/NextIntlClientProvider.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +56 -13
- package/dist/cjs/index.cjs +92 -15
- package/dist/cjs/server/getLocale.cjs +15 -1
- package/dist/cjs/server/getLocale.cjs.map +1 -1
- package/dist/cjs/server/getRequestConfig.cjs +28 -0
- package/dist/cjs/server/getRequestConfig.cjs.map +1 -0
- package/dist/cjs/server/getTranslations.cjs +9 -4
- package/dist/cjs/server/getTranslations.cjs.map +1 -1
- package/dist/cjs/server/helpers.cjs +5 -3
- package/dist/cjs/server/helpers.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +5 -1
- package/dist/cjs/server/requestLocaleCache.cjs +36 -0
- package/dist/cjs/server/requestLocaleCache.cjs.map +1 -0
- package/dist/cjs/server/setRequestLocale.cjs +33 -0
- package/dist/cjs/server/setRequestLocale.cjs.map +1 -0
- package/dist/esm/client/NextIntlClientProvider.mjs +9 -4
- package/dist/esm/client/NextIntlClientProvider.mjs.map +1 -1
- package/dist/esm/client/index.mjs +1 -4
- package/dist/esm/index.mjs +3 -6
- package/dist/esm/server/getLocale.mjs +15 -1
- package/dist/esm/server/getLocale.mjs.map +1 -1
- package/dist/esm/server/getRequestConfig.mjs +25 -0
- package/dist/esm/server/getRequestConfig.mjs.map +1 -0
- package/dist/esm/server/getTranslations.mjs +8 -4
- package/dist/esm/server/getTranslations.mjs.map +1 -1
- package/dist/esm/server/helpers.mjs +4 -3
- package/dist/esm/server/helpers.mjs.map +1 -1
- package/dist/esm/server/index.mjs +3 -1
- package/dist/esm/server/requestLocaleCache.mjs +33 -0
- package/dist/esm/server/requestLocaleCache.mjs.map +1 -0
- package/dist/esm/server/setRequestLocale.mjs +32 -0
- package/dist/esm/server/setRequestLocale.mjs.map +1 -0
- package/dist/types/client/NextIntlClientProvider.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -4
- package/dist/types/index.d.ts +3 -6
- package/dist/types/server/getLocale.d.ts +9 -0
- package/dist/types/server/getLocale.d.ts.map +1 -1
- package/dist/types/server/getRequestConfig.d.ts +19 -0
- package/dist/types/server/getRequestConfig.d.ts.map +1 -0
- package/dist/types/server/getTranslations.d.ts +7 -29
- package/dist/types/server/getTranslations.d.ts.map +1 -1
- package/dist/types/server/helpers.d.ts +2 -1
- package/dist/types/server/helpers.d.ts.map +1 -1
- package/dist/types/server/index.d.ts +3 -1
- package/dist/types/server/requestLocaleCache.d.ts +17 -0
- package/dist/types/server/requestLocaleCache.d.ts.map +1 -0
- package/dist/types/server/setRequestLocale.d.ts +29 -0
- package/dist/types/server/setRequestLocale.d.ts.map +1 -0
- package/package.json +11 -16
- package/dist/cjs/client/helpers.cjs +0 -66
- package/dist/cjs/client/helpers.cjs.map +0 -1
- package/dist/cjs/client/useTranslations.cjs +0 -39
- package/dist/cjs/client/useTranslations.cjs.map +0 -1
- package/dist/cjs/createFormatter.cjs +0 -59
- package/dist/cjs/createFormatter.cjs.map +0 -1
- package/dist/cjs/createTranslator.cjs +0 -111
- package/dist/cjs/createTranslator.cjs.map +0 -1
- package/dist/cjs/getTranslationsDictionary.cjs +0 -31
- package/dist/cjs/getTranslationsDictionary.cjs.map +0 -1
- package/dist/cjs/getTranslationsDictionaryDynamic.cjs +0 -27
- package/dist/cjs/getTranslationsDictionaryDynamic.cjs.map +0 -1
- package/dist/cjs/hasLocale.cjs +0 -25
- package/dist/cjs/hasLocale.cjs.map +0 -1
- package/dist/cjs/package.cjs +0 -122
- package/dist/cjs/package.cjs.map +0 -1
- package/dist/cjs/useDictionary.cjs +0 -45
- package/dist/cjs/useDictionary.cjs.map +0 -1
- package/dist/cjs/useDictionaryDynamic.cjs +0 -37
- package/dist/cjs/useDictionaryDynamic.cjs.map +0 -1
- package/dist/cjs/useTranslationsDictionary.cjs +0 -37
- package/dist/cjs/useTranslationsDictionary.cjs.map +0 -1
- package/dist/cjs/useTranslationsDictionaryDynamic.cjs +0 -29
- package/dist/cjs/useTranslationsDictionaryDynamic.cjs.map +0 -1
- package/dist/esm/_virtual/_rolldown/runtime.mjs +0 -8
- package/dist/esm/client/helpers.mjs +0 -59
- package/dist/esm/client/helpers.mjs.map +0 -1
- package/dist/esm/client/useTranslations.mjs +0 -37
- package/dist/esm/client/useTranslations.mjs.map +0 -1
- package/dist/esm/createFormatter.mjs +0 -57
- package/dist/esm/createFormatter.mjs.map +0 -1
- package/dist/esm/createTranslator.mjs +0 -108
- package/dist/esm/createTranslator.mjs.map +0 -1
- package/dist/esm/getTranslationsDictionary.mjs +0 -29
- package/dist/esm/getTranslationsDictionary.mjs.map +0 -1
- package/dist/esm/getTranslationsDictionaryDynamic.mjs +0 -25
- package/dist/esm/getTranslationsDictionaryDynamic.mjs.map +0 -1
- package/dist/esm/hasLocale.mjs +0 -23
- package/dist/esm/hasLocale.mjs.map +0 -1
- package/dist/esm/package.mjs +0 -119
- package/dist/esm/package.mjs.map +0 -1
- package/dist/esm/useDictionary.mjs +0 -43
- package/dist/esm/useDictionary.mjs.map +0 -1
- package/dist/esm/useDictionaryDynamic.mjs +0 -35
- package/dist/esm/useDictionaryDynamic.mjs.map +0 -1
- package/dist/esm/useTranslationsDictionary.mjs +0 -35
- package/dist/esm/useTranslationsDictionary.mjs.map +0 -1
- package/dist/esm/useTranslationsDictionaryDynamic.mjs +0 -27
- package/dist/esm/useTranslationsDictionaryDynamic.mjs.map +0 -1
- package/dist/types/client/helpers.d.ts +0 -45
- package/dist/types/client/helpers.d.ts.map +0 -1
- package/dist/types/client/useTranslations.d.ts +0 -74
- package/dist/types/client/useTranslations.d.ts.map +0 -1
- package/dist/types/createFormatter.d.ts +0 -15
- package/dist/types/createFormatter.d.ts.map +0 -1
- package/dist/types/createTranslator.d.ts +0 -40
- package/dist/types/createTranslator.d.ts.map +0 -1
- package/dist/types/getTranslationsDictionary.d.ts +0 -15
- package/dist/types/getTranslationsDictionary.d.ts.map +0 -1
- package/dist/types/getTranslationsDictionaryDynamic.d.ts +0 -12
- package/dist/types/getTranslationsDictionaryDynamic.d.ts.map +0 -1
- package/dist/types/hasLocale.d.ts +0 -20
- package/dist/types/hasLocale.d.ts.map +0 -1
- package/dist/types/useDictionary.d.ts +0 -22
- package/dist/types/useDictionary.d.ts.map +0 -1
- package/dist/types/useDictionaryDynamic.d.ts +0 -15
- package/dist/types/useDictionaryDynamic.d.ts.map +0 -1
- package/dist/types/useTranslationsDictionary.d.ts +0 -19
- package/dist/types/useTranslationsDictionary.d.ts.map +0 -1
- package/dist/types/useTranslationsDictionaryDynamic.d.ts +0 -12
- package/dist/types/useTranslationsDictionaryDynamic.d.ts.map +0 -1
|
@@ -1,29 +0,0 @@
|
|
|
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/useTranslationsDictionaryDynamic.ts
|
|
8
|
-
/**
|
|
9
|
-
* Dynamic dictionary-accepting variant of `useTranslations`.
|
|
10
|
-
*/
|
|
11
|
-
const useTranslationsDictionaryDynamic = (dictionaryPromise, key, namespacePrefix) => {
|
|
12
|
-
const content = (0, react_intlayer.useDictionaryDynamic)(dictionaryPromise, key);
|
|
13
|
-
return (lookup, params) => {
|
|
14
|
-
const lookupKey = namespacePrefix ? `${namespacePrefix}.${String(lookup)}` : String(lookup);
|
|
15
|
-
const parts = lookupKey.split(".");
|
|
16
|
-
let current = content;
|
|
17
|
-
for (const part of parts) {
|
|
18
|
-
if (current == null) break;
|
|
19
|
-
current = current[part];
|
|
20
|
-
}
|
|
21
|
-
const str = String(current ?? lookupKey);
|
|
22
|
-
if (!params) return str;
|
|
23
|
-
return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
exports.useTranslationsDictionaryDynamic = useTranslationsDictionaryDynamic;
|
|
29
|
-
//# sourceMappingURL=useTranslationsDictionaryDynamic.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslationsDictionaryDynamic.cjs","names":[],"sources":["../../src/useTranslationsDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useDictionaryDynamic } from 'react-intlayer';\n\n/**\n * Dynamic dictionary-accepting variant of `useTranslations`.\n */\nexport const useTranslationsDictionaryDynamic = <\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 = useDictionaryDynamic<T, any>(dictionaryPromise, key as any);\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":";;;;;;;;;;AAUA,MAAa,oCAIX,mBACA,KACA,oBACG;CACH,MAAM,mDAAuC,mBAAmB,IAAW;AAE3E,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"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
3
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
4
|
-
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
//#endregion
|
|
8
|
-
export { __require };
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { createFormatter } from "../createFormatter.mjs";
|
|
4
|
-
import { log } from "@intlayer/config/built";
|
|
5
|
-
import { useLocale } from "next-intlayer";
|
|
6
|
-
import { Fragment, jsx } from "react/jsx-runtime";
|
|
7
|
-
import { CYAN } from "@intlayer/config/colors";
|
|
8
|
-
import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
9
|
-
|
|
10
|
-
//#region src/client/helpers.tsx
|
|
11
|
-
/**
|
|
12
|
-
* Drop-in for next-intl's `useNow`.
|
|
13
|
-
* Returns the current `Date`. The `updateInterval` option is ignored.
|
|
14
|
-
*/
|
|
15
|
-
const useNow = () => /* @__PURE__ */ new Date();
|
|
16
|
-
/**
|
|
17
|
-
* Drop-in for next-intl's `useTimeZone`.
|
|
18
|
-
* Returns the system time zone resolved from `Intl.DateTimeFormat`.
|
|
19
|
-
*/
|
|
20
|
-
const useTimeZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
21
|
-
/**
|
|
22
|
-
* Drop-in for next-intl's `useMessages`.
|
|
23
|
-
*
|
|
24
|
-
* @deprecated useMessages has no use case with intlayer.
|
|
25
|
-
* Messages are loaded automatically under the hood.
|
|
26
|
-
* @returns An empty object.
|
|
27
|
-
*/
|
|
28
|
-
const useMessages = () => {
|
|
29
|
-
getAppLogger({ log })(`${colorize("useMessages", CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
|
|
30
|
-
return {};
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Drop-in for next-intl's `useFormatter`.
|
|
34
|
-
* Returns locale-aware formatters backed by the native `Intl.*` APIs:
|
|
35
|
-
* `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and
|
|
36
|
-
* `displayName`.
|
|
37
|
-
*/
|
|
38
|
-
const useFormatter = () => {
|
|
39
|
-
const { locale } = useLocale();
|
|
40
|
-
return createFormatter(locale ?? "en");
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Drop-in for next-intl's `IntlProvider`.
|
|
44
|
-
* Renders children as-is — Intlayer provides its own context via
|
|
45
|
-
* `IntlayerClientProvider`.
|
|
46
|
-
*
|
|
47
|
-
* @deprecated IntlProvider has no use case with intlayer.
|
|
48
|
-
* Use `IntlayerClientProvider` or `NextIntlClientProvider` instead.
|
|
49
|
-
*/
|
|
50
|
-
const IntlProvider = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
|
|
51
|
-
/**
|
|
52
|
-
* @internal Not part of the public next-intl API surface; provided for
|
|
53
|
-
* internal compatibility shims only.
|
|
54
|
-
*/
|
|
55
|
-
const useExtracted = (..._args) => ({});
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
export { IntlProvider, useExtracted, useFormatter, useMessages, useNow, useTimeZone };
|
|
59
|
-
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../src/client/helpers.tsx"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type {\n IntlProvider as _IntlProvider,\n useFormatter as _useFormatter,\n useMessages as _useMessages,\n useNow as _useNow,\n useTimeZone as _useTimeZone,\n} from 'next-intl';\nimport { useLocale } from 'next-intlayer';\nimport type * as React from 'react';\nimport { createFormatter } from '../createFormatter';\n\n/**\n * Drop-in for next-intl's `useNow`.\n * Returns the current `Date`. The `updateInterval` option is ignored.\n */\nexport const useNow: typeof _useNow = () => new Date();\n\n/**\n * Drop-in for next-intl's `useTimeZone`.\n * Returns the system time zone resolved from `Intl.DateTimeFormat`.\n */\nexport const useTimeZone: typeof _useTimeZone = () =>\n Intl.DateTimeFormat().resolvedOptions().timeZone;\n\n/**\n * Drop-in for next-intl's `useMessages`.\n *\n * @deprecated useMessages has no use case with intlayer.\n * Messages are loaded automatically under the hood.\n * @returns An empty object.\n */\nexport const useMessages: typeof _useMessages = () => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('useMessages', CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return {} as ReturnType<typeof _useMessages>;\n};\n\n/**\n * Drop-in for next-intl's `useFormatter`.\n * Returns locale-aware formatters backed by the native `Intl.*` APIs:\n * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and\n * `displayName`.\n */\nexport const useFormatter: typeof _useFormatter = () => {\n const { locale } = useLocale();\n return createFormatter((locale as string) ?? 'en');\n};\n\ninterface ProviderProps {\n children?: React.ReactNode;\n [key: string]: unknown;\n}\n\n/**\n * Drop-in for next-intl's `IntlProvider`.\n * Renders children as-is — Intlayer provides its own context via\n * `IntlayerClientProvider`.\n *\n * @deprecated IntlProvider has no use case with intlayer.\n * Use `IntlayerClientProvider` or `NextIntlClientProvider` instead.\n */\nexport const IntlProvider: typeof _IntlProvider = ({\n children,\n}: ProviderProps) => <>{children}</>;\n\n/**\n * @internal Not part of the public next-intl API surface; provided for\n * internal compatibility shims only.\n */\nexport const useExtracted = (..._args: unknown[]) => ({});\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAa,+BAA+B,IAAI,MAAM;;;;;AAMtD,MAAa,oBACX,KAAK,gBAAgB,CAAC,iBAAiB,CAAC;;;;;;;;AAS1C,MAAa,oBAAyC;AAGlD,CADkB,aAAa,EAAE,KAAK,CAC7B,CACP,GAAG,SAAS,eAAe,KAAK,CAAC,iHAClC;AAGH,QAAO,EAAE;;;;;;;;AASX,MAAa,qBAA2C;CACtD,MAAM,EAAE,WAAW,WAAW;AAC9B,QAAO,gBAAiB,UAAqB,KAAK;;;;;;;;;;AAgBpD,MAAa,gBAAsC,EACjD,eACmB,gCAAG,UAAY;;;;;AAMpC,MAAa,gBAAgB,GAAG,WAAsB,EAAE"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { createTranslator } from "../createTranslator.mjs";
|
|
4
|
-
import { IntlayerClientContext } from "next-intlayer";
|
|
5
|
-
import { useContext, useMemo } from "react";
|
|
6
|
-
|
|
7
|
-
//#region src/client/useTranslations.ts
|
|
8
|
-
/**
|
|
9
|
-
* Drop-in for next-intl's `useTranslations`.
|
|
10
|
-
*
|
|
11
|
-
* Messages support ICU MessageFormat syntax: simple arguments (`{name}`),
|
|
12
|
-
* plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted
|
|
13
|
-
* arguments (`{value, number}`). Rich text is available through `t.rich()`
|
|
14
|
-
* and `t.markup()`.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* const t = useTranslations('about');
|
|
19
|
-
* t('counter.label'); // ✓ typed
|
|
20
|
-
* t('items', { count: 3 }); // ICU plural
|
|
21
|
-
*
|
|
22
|
-
* // Scoped to a nested object (next-intl idiom)
|
|
23
|
-
* const t = useTranslations('about.counter');
|
|
24
|
-
* t('label'); // resolves about → counter.label
|
|
25
|
-
*
|
|
26
|
-
* // Rich text
|
|
27
|
-
* t.rich('terms', { link: (chunks) => <a href="/terms">{chunks}</a> });
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
const useTranslations = ((namespace) => {
|
|
31
|
-
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
32
|
-
return useMemo(() => createTranslator(currentLocale, namespace), [currentLocale, namespace]);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
export { useTranslations };
|
|
37
|
-
//# sourceMappingURL=useTranslations.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslations.mjs","names":[],"sources":["../../../src/client/useTranslations.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerClientContext } from 'next-intlayer';\nimport { type ReactNode, useContext, useMemo } from 'react';\nimport {\n createTranslator,\n type MarkupChunkRenderer,\n type RichChunkRenderer,\n} from '../createTranslator';\n\n/**\n * The translation function returned by {@link useTranslations}.\n *\n * When the namespace is a bare dictionary key, `key` is validated against the\n * dictionary's dot-paths. When the namespace is a nested scope\n * (`'about.counter'`), `key` is a relative `string` path.\n *\n * Beyond the call signature, the function exposes:\n * - `has(key)` — returns `true` when the key exists in the namespace.\n * - `raw(key)` — returns the unprocessed content 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 content 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 useTranslations}:\n *\n * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).\n * 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative\n * `string` paths, matching next-intl's scoped-namespace behaviour.\n * 3. No namespace → root scope; the first segment of each key designates\n * the dictionary (`t('about.title')`).\n */\ntype UseTranslations = {\n <N extends DictionaryKeys>(namespace: N): TranslateFunction<N>;\n (namespace: `${string}.${string}`): LooseTranslateFunction;\n (): LooseTranslateFunction;\n};\n\n/**\n * Drop-in for next-intl's `useTranslations`.\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 * @example\n * ```tsx\n * const t = useTranslations('about');\n * t('counter.label'); // ✓ typed\n * t('items', { count: 3 }); // ICU plural\n *\n * // Scoped to a nested object (next-intl idiom)\n * const t = useTranslations('about.counter');\n * t('label'); // resolves about → counter.label\n *\n * // Rich text\n * t.rich('terms', { link: (chunks) => <a href=\"/terms\">{chunks}</a> });\n * ```\n */\nexport const useTranslations = ((namespace?: string) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n return useMemo(\n () => createTranslator(currentLocale as LocalesValues, namespace),\n [currentLocale, namespace]\n );\n}) as UseTranslations;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,MAAa,oBAAoB,cAAuB;CACtD,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB,IAAI,EAAE;AAEzE,QAAO,cACC,iBAAiB,eAAgC,UAAU,EACjE,CAAC,eAAe,UAAU,CAC3B"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
//#region src/createFormatter.ts
|
|
2
|
-
/** Time units orderable by their duration in seconds. */
|
|
3
|
-
const RELATIVE_TIME_UNITS = [
|
|
4
|
-
["year", 31536e3],
|
|
5
|
-
["month", 2628e3],
|
|
6
|
-
["week", 604800],
|
|
7
|
-
["day", 86400],
|
|
8
|
-
["hour", 3600],
|
|
9
|
-
["minute", 60],
|
|
10
|
-
["second", 1]
|
|
11
|
-
];
|
|
12
|
-
const toDate = (value) => value instanceof Date ? value : new Date(value);
|
|
13
|
-
/**
|
|
14
|
-
* Builds a next-intl compatible formatter backed by the native `Intl.*`
|
|
15
|
-
* APIs for the given locale.
|
|
16
|
-
*
|
|
17
|
-
* Shared by `useFormatter` (client) and `getFormatter` (server).
|
|
18
|
-
*/
|
|
19
|
-
const createFormatter = (locale) => ({
|
|
20
|
-
dateTime: (value, options) => new Intl.DateTimeFormat(locale, options).format(value),
|
|
21
|
-
number: (value, options) => new Intl.NumberFormat(locale, options).format(value),
|
|
22
|
-
/** Formats a date range with `Intl.DateTimeFormat#formatRange`. */
|
|
23
|
-
dateTimeRange: (start, end, options) => new Intl.DateTimeFormat(locale, options).formatRange(toDate(start), toDate(end)),
|
|
24
|
-
/**
|
|
25
|
-
* Formats a date relative to now (or a reference date), automatically
|
|
26
|
-
* selecting the largest fitting unit.
|
|
27
|
-
*/
|
|
28
|
-
relativeTime: (date, nowOrOptions) => {
|
|
29
|
-
const options = nowOrOptions instanceof Date || typeof nowOrOptions === "number" ? { now: nowOrOptions } : nowOrOptions ?? {};
|
|
30
|
-
const nowDate = options.now !== void 0 ? toDate(options.now) : /* @__PURE__ */ new Date();
|
|
31
|
-
const diffInSeconds = (toDate(date).getTime() - nowDate.getTime()) / 1e3;
|
|
32
|
-
let unit = options.unit;
|
|
33
|
-
if (!unit) {
|
|
34
|
-
const absoluteDiff = Math.abs(diffInSeconds);
|
|
35
|
-
unit = RELATIVE_TIME_UNITS.find(([, unitSeconds]) => absoluteDiff >= unitSeconds)?.[0] ?? "second";
|
|
36
|
-
}
|
|
37
|
-
const unitSeconds = RELATIVE_TIME_UNITS.find(([unitName]) => unitName === unit)?.[1] ?? 1;
|
|
38
|
-
return new Intl.RelativeTimeFormat(locale, {
|
|
39
|
-
numeric: "auto",
|
|
40
|
-
style: options.style
|
|
41
|
-
}).format(Math.round(diffInSeconds / unitSeconds), unit);
|
|
42
|
-
},
|
|
43
|
-
/** Formats a list with `Intl.ListFormat`. */
|
|
44
|
-
list: (value, options) => new Intl.ListFormat(locale, options).format(value),
|
|
45
|
-
displayName: (value, optionsOrFormat, extraOptions) => {
|
|
46
|
-
const resolvedOptions = typeof optionsOrFormat === "string" ? extraOptions : optionsOrFormat;
|
|
47
|
-
try {
|
|
48
|
-
return new Intl.DisplayNames([locale], resolvedOptions ?? { type: "language" }).of(value) ?? value;
|
|
49
|
-
} catch {
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
//#endregion
|
|
56
|
-
export { createFormatter };
|
|
57
|
-
//# sourceMappingURL=createFormatter.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFormatter.mjs","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"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { getIntlayer } from "@intlayer/core/interpreter";
|
|
2
|
-
import { parseTaggedMessage, resolveMessage } from "@intlayer/core/messageFormat";
|
|
3
|
-
import { Fragment } from "react";
|
|
4
|
-
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
5
|
-
|
|
6
|
-
//#region src/createTranslator.tsx
|
|
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
|
-
/** Splits rich values into scalar interpolation values and tag renderers. */
|
|
18
|
-
const splitRichValues = (values = {}) => {
|
|
19
|
-
const scalarValues = {};
|
|
20
|
-
const renderers = {};
|
|
21
|
-
for (const [valueKey, value] of Object.entries(values)) if (typeof value === "function") renderers[valueKey] = value;
|
|
22
|
-
else scalarValues[valueKey] = value;
|
|
23
|
-
return {
|
|
24
|
-
scalarValues,
|
|
25
|
-
renderers
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
const renderRichTokens = (tokens, renderers) => tokens.map((token, tokenIndex) => {
|
|
29
|
-
if (typeof token === "string") return token;
|
|
30
|
-
const children = renderRichTokens(token.children, renderers);
|
|
31
|
-
const renderer = renderers[token.tag];
|
|
32
|
-
if (typeof renderer === "function") return /* @__PURE__ */ jsx(Fragment, { children: renderer(children) }, tokenIndex);
|
|
33
|
-
return /* @__PURE__ */ jsx(Fragment, { children }, tokenIndex);
|
|
34
|
-
});
|
|
35
|
-
const renderMarkupTokens = (tokens, renderers) => tokens.map((token) => {
|
|
36
|
-
if (typeof token === "string") return token;
|
|
37
|
-
const children = renderMarkupTokens(token.children, renderers);
|
|
38
|
-
const renderer = renderers[token.tag];
|
|
39
|
-
if (typeof renderer === "function") return renderer(children);
|
|
40
|
-
return children;
|
|
41
|
-
}).join("");
|
|
42
|
-
/**
|
|
43
|
-
* The untyped runtime translator shared by `useTranslations` (client) and
|
|
44
|
-
* `getTranslations` (server).
|
|
45
|
-
*
|
|
46
|
-
* Behaviour matches next-intl:
|
|
47
|
-
* - namespace `'about'` → keys resolved inside the `about` dictionary
|
|
48
|
-
* - namespace `'about.counter'` → dictionary `about`, key prefix `counter`
|
|
49
|
-
* - no namespace → the first segment of each key is the dictionary key
|
|
50
|
-
* - messages support ICU syntax (plural, select, `#`, formatted arguments)
|
|
51
|
-
* - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided
|
|
52
|
-
* renderers; `t.raw` returns the raw value; `t.has` checks existence
|
|
53
|
-
*/
|
|
54
|
-
const createTranslator = (locale, namespace) => {
|
|
55
|
-
const [dictionaryKey, ...prefixSegments] = (namespace ?? "").split(".");
|
|
56
|
-
const keyPrefix = prefixSegments.join(".");
|
|
57
|
-
const lookup = (key) => {
|
|
58
|
-
let targetDictionaryKey = dictionaryKey;
|
|
59
|
-
let path = keyPrefix ? `${keyPrefix}.${key}` : key;
|
|
60
|
-
if (!targetDictionaryKey) {
|
|
61
|
-
const [firstSegment, ...restSegments] = key.split(".");
|
|
62
|
-
targetDictionaryKey = firstSegment;
|
|
63
|
-
path = restSegments.join(".");
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
return navigatePath(getIntlayer(targetDictionaryKey, locale), path);
|
|
67
|
-
} catch {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const resolveToString = (key, values = {}) => {
|
|
72
|
-
const rawValue = lookup(key);
|
|
73
|
-
if (rawValue === null || rawValue === void 0) return void 0;
|
|
74
|
-
return resolveMessage(rawValue, values, locale, "icu");
|
|
75
|
-
};
|
|
76
|
-
const missingKeyFallback = (key) => namespace ? `${namespace}.${key}` : key;
|
|
77
|
-
const translate = (key, values) => resolveToString(key, values) ?? missingKeyFallback(key);
|
|
78
|
-
return Object.assign(translate, {
|
|
79
|
-
/** Returns `true` if the given key exists in the namespace. */
|
|
80
|
-
has: (key) => lookup(key) !== void 0,
|
|
81
|
-
/** Returns the raw unprocessed content for the given key. */
|
|
82
|
-
raw: (key) => lookup(key),
|
|
83
|
-
/**
|
|
84
|
-
* Resolves a message containing `<tag>chunks</tag>` markup, mapping each
|
|
85
|
-
* tag through the matching renderer in `values`.
|
|
86
|
-
*/
|
|
87
|
-
rich: (key, values) => {
|
|
88
|
-
const { scalarValues, renderers } = splitRichValues(values);
|
|
89
|
-
const message = resolveToString(key, scalarValues);
|
|
90
|
-
if (message === void 0) return missingKeyFallback(key);
|
|
91
|
-
return /* @__PURE__ */ jsx(Fragment$1, { children: renderRichTokens(parseTaggedMessage(message), renderers) });
|
|
92
|
-
},
|
|
93
|
-
/**
|
|
94
|
-
* Resolves a message containing `<tag>chunks</tag>` markup into a string,
|
|
95
|
-
* mapping each tag through the matching string renderer in `values`.
|
|
96
|
-
*/
|
|
97
|
-
markup: (key, values) => {
|
|
98
|
-
const { scalarValues, renderers } = splitRichValues(values);
|
|
99
|
-
const message = resolveToString(key, scalarValues);
|
|
100
|
-
if (message === void 0) return missingKeyFallback(key);
|
|
101
|
-
return renderMarkupTokens(parseTaggedMessage(message), renderers);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
//#endregion
|
|
107
|
-
export { createTranslator, navigatePath };
|
|
108
|
-
//# sourceMappingURL=createTranslator.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createTranslator.mjs","names":[],"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,oBAAC,UAAD,YACI,SAA+B,SAAS,EACjC,EAFI,WAEJ;AAKf,QAAO,oBAAC,UAAD,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,aAJY,YACjB,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,SAAO,eAAe,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,4CAAG,iBAAiB,mBAAmB,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,mBAAmB,mBAAmB,QAAQ,EAAE,UAAU;;EAEpE,CAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { getDictionary } from "next-intlayer/server";
|
|
2
|
-
|
|
3
|
-
//#region src/getTranslationsDictionary.ts
|
|
4
|
-
/**
|
|
5
|
-
* Dictionary-accepting variant of `getTranslations`.
|
|
6
|
-
*
|
|
7
|
-
* Used internally by the SWC optimization: instead of looking up the dictionary
|
|
8
|
-
* at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
|
|
9
|
-
* and passes it directly here. This enables tree-shaking of unused locale content.
|
|
10
|
-
*/
|
|
11
|
-
const getTranslationsDictionary = async (dictionary, namespacePrefix) => {
|
|
12
|
-
const content = getDictionary(dictionary);
|
|
13
|
-
return (lookup, params) => {
|
|
14
|
-
const lookupKey = namespacePrefix ? `${namespacePrefix}.${String(lookup)}` : String(lookup);
|
|
15
|
-
const parts = lookupKey.split(".");
|
|
16
|
-
let current = content;
|
|
17
|
-
for (const part of parts) {
|
|
18
|
-
if (current == null) break;
|
|
19
|
-
current = current[part];
|
|
20
|
-
}
|
|
21
|
-
const str = String(current ?? lookupKey);
|
|
22
|
-
if (!params) return str;
|
|
23
|
-
return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
export { getTranslationsDictionary };
|
|
29
|
-
//# sourceMappingURL=getTranslationsDictionary.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslationsDictionary.mjs","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,UAAU,cAAc,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"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { getDictionaryDynamic } from "next-intlayer/server";
|
|
2
|
-
|
|
3
|
-
//#region src/getTranslationsDictionaryDynamic.ts
|
|
4
|
-
/**
|
|
5
|
-
* Dynamic dictionary-accepting variant of `getTranslations`.
|
|
6
|
-
*/
|
|
7
|
-
const getTranslationsDictionaryDynamic = async (dictionaryPromise, key, namespacePrefix) => {
|
|
8
|
-
const content = await getDictionaryDynamic(dictionaryPromise, key);
|
|
9
|
-
return (lookup, params) => {
|
|
10
|
-
const lookupKey = namespacePrefix ? `${namespacePrefix}.${String(lookup)}` : String(lookup);
|
|
11
|
-
const parts = lookupKey.split(".");
|
|
12
|
-
let current = content;
|
|
13
|
-
for (const part of parts) {
|
|
14
|
-
if (current == null) break;
|
|
15
|
-
current = current[part];
|
|
16
|
-
}
|
|
17
|
-
const str = String(current ?? lookupKey);
|
|
18
|
-
if (!params) return str;
|
|
19
|
-
return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
export { getTranslationsDictionaryDynamic };
|
|
25
|
-
//# sourceMappingURL=getTranslationsDictionaryDynamic.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslationsDictionaryDynamic.mjs","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,MAAM,qBACpB,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"}
|
package/dist/esm/hasLocale.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { internationalization } from "@intlayer/config/built";
|
|
2
|
-
|
|
3
|
-
//#region src/hasLocale.ts
|
|
4
|
-
/**
|
|
5
|
-
* Drop-in for next-intl's `hasLocale`.
|
|
6
|
-
*
|
|
7
|
-
* Checks that a locale candidate is part of the given locales list (or, when
|
|
8
|
-
* the list is read from routing, the locales configured in intlayer).
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* import { routing } from '@/i18n/routing';
|
|
13
|
-
*
|
|
14
|
-
* if (hasLocale(routing.locales, requested)) { … }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
const hasLocale = ((locales, candidate) => {
|
|
18
|
-
return (locales ?? internationalization?.locales?.map(String) ?? []).includes(candidate);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
export { hasLocale };
|
|
23
|
-
//# sourceMappingURL=hasLocale.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hasLocale.mjs","names":[],"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,WAAW,sBAAsB,SAAS,IAAI,OAAO,IAAI,EAAE,EACrC,SAAS,UAAoB"}
|
package/dist/esm/package.mjs
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { __commonJSMin } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
|
-
|
|
3
|
-
//#region package.json
|
|
4
|
-
var require_package = /* @__PURE__ */ __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
|
-
export default require_package();
|
|
117
|
-
|
|
118
|
-
export { require_package };
|
|
119
|
-
//# sourceMappingURL=package.mjs.map
|
package/dist/esm/package.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package.mjs","names":[],"sources":["../../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useDictionary as useDictionary$1 } from "react-intlayer";
|
|
4
|
-
|
|
5
|
-
//#region src/useDictionary.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
|
-
* Dictionary-accepting variant of `useTranslations`.
|
|
18
|
-
*
|
|
19
|
-
* Used internally by the SWC optimization: instead of looking up the dictionary
|
|
20
|
-
* at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
|
|
21
|
-
* and passes it directly here. This enables tree-shaking of unused locale content.
|
|
22
|
-
*
|
|
23
|
-
* @example (generated by SWC, not written manually)
|
|
24
|
-
* import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
|
|
25
|
-
* const t = useDictionary(_abc);
|
|
26
|
-
*/
|
|
27
|
-
const useDictionary = (dictionary, namespacePrefix) => {
|
|
28
|
-
const content = useDictionary$1(dictionary);
|
|
29
|
-
const resolveKey = (key) => namespacePrefix ? `${namespacePrefix}.${key}` : key;
|
|
30
|
-
return Object.assign((lookup, params) => {
|
|
31
|
-
const rawValue = navigatePath(content, resolveKey(String(lookup)));
|
|
32
|
-
const str = String(rawValue ?? resolveKey(String(lookup)));
|
|
33
|
-
if (!params) return str;
|
|
34
|
-
return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
35
|
-
}, {
|
|
36
|
-
has: (lookup) => navigatePath(content, resolveKey(String(lookup))) != null,
|
|
37
|
-
raw: (lookup) => navigatePath(content, resolveKey(String(lookup)))
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
|
-
export { useDictionary };
|
|
43
|
-
//# sourceMappingURL=useDictionary.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":["useDictionaryBase"],"sources":["../../src/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { useDictionary as useDictionaryBase } from 'react-intlayer';\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 `useTranslations`.\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 * @example (generated by SWC, not written manually)\n * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };\n * const t = useDictionary(_abc);\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n) => {\n const content = useDictionaryBase(dictionary);\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;;;;;;;;;;;;;AAcT,MAAa,iBACX,YACA,oBACG;CACH,MAAM,UAAUA,gBAAkB,WAAW;CAE7C,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"}
|