@intlayer/use-intl 9.0.0-canary.10 → 9.0.0-canary.12
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/esm/client/useTranslations.mjs +1 -1
- package/dist/esm/client/useTranslations.mjs.map +1 -1
- package/dist/esm/core/createTranslator.mjs.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/plugin/index.mjs +3 -36
- package/dist/esm/plugin/index.mjs.map +1 -1
- package/dist/esm/shared/namespaceTranslator.mjs +55 -44
- package/dist/esm/shared/namespaceTranslator.mjs.map +1 -1
- package/dist/esm/useDictionary.mjs +10 -15
- package/dist/esm/useDictionary.mjs.map +1 -1
- package/dist/esm/useDictionaryDynamic.mjs +7 -15
- package/dist/esm/useDictionaryDynamic.mjs.map +1 -1
- package/dist/types/client/useTranslations.d.ts +4 -3
- package/dist/types/client/useTranslations.d.ts.map +1 -1
- package/dist/types/core/createTranslator.d.ts +6 -5
- package/dist/types/core/createTranslator.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/shared/namespaceTranslator.d.ts +28 -10
- package/dist/types/shared/namespaceTranslator.d.ts.map +1 -1
- package/dist/types/shared/translateFunctionTypes.d.ts +40 -4
- package/dist/types/shared/translateFunctionTypes.d.ts.map +1 -1
- package/dist/types/useDictionary.d.ts +15 -5
- package/dist/types/useDictionary.d.ts.map +1 -1
- package/dist/types/useDictionaryDynamic.d.ts +12 -6
- package/dist/types/useDictionaryDynamic.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { createNamespaceTranslator } from "../shared/namespaceTranslator.mjs";
|
|
4
|
-
import { IntlayerClientContext } from "react-intlayer";
|
|
5
4
|
import { useContext, useMemo } from "react";
|
|
5
|
+
import { IntlayerClientContext } from "react-intlayer";
|
|
6
6
|
|
|
7
7
|
//#region src/client/useTranslations.ts
|
|
8
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslations.mjs","names":[],"sources":["../../../src/client/useTranslations.ts"],"sourcesContent":["'use client';\n\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from 'react-intlayer';\nimport { createNamespaceTranslator } from '../shared/namespaceTranslator';\nimport type {\n LooseTranslateFunction,\n TranslateFunction,\n} from '../shared/translateFunctionTypes';\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 *
|
|
1
|
+
{"version":3,"file":"useTranslations.mjs","names":[],"sources":["../../../src/client/useTranslations.ts"],"sourcesContent":["'use client';\n\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from 'react-intlayer';\nimport { createNamespaceTranslator } from '../shared/namespaceTranslator';\nimport type {\n LooseTranslateFunction,\n TranslateFunction,\n TranslateFunctionForNamespace,\n} from '../shared/translateFunctionTypes';\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 * dot-paths under the scope, typed against the dictionary, matching\n * use-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 <N extends `${string}.${string}`>(\n namespace: N\n ): TranslateFunctionForNamespace<N>;\n (): LooseTranslateFunction;\n};\n\n/**\n * Drop-in for use-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 (use-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 () => createNamespaceTranslator(currentLocale as LocalesValues, namespace),\n [currentLocale, namespace]\n );\n}) as UseTranslations;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAa,oBAAoB,cAAuB;CACtD,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB,IAAI,EAAE;AAEzE,QAAO,cACC,0BAA0B,eAAgC,UAAU,EAC1E,CAAC,eAAe,UAAU,CAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTranslator.mjs","names":[],"sources":["../../../src/core/createTranslator.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { createNamespaceTranslator } from '../shared/namespaceTranslator';\nimport type {\n LooseTranslateFunction,\n TranslateFunction,\n} from '../shared/translateFunctionTypes';\n\n/**\n * Configuration accepted by {@link createTranslator}.\n *\n * Mirrors use-intl's `IntlConfig`, but `messages`, `formats`, `now`,\n * `timeZone`, `onError`, and `getMessageFallback` have no effect — Intlayer\n * resolves content from its own compiled dictionaries.\n */\nexport type CreateTranslatorConfig<N extends DictionaryKeys> = {\n /** The locale dictionaries are resolved for. */\n locale: LocalesValues;\n /** A bare dictionary key, or a nested `'dictionary.scope'` namespace. */\n namespace?: N | (string & {});\n /**\n * @deprecated has no use case with intlayer. Messages are loaded\n * automatically under the hood for bundle optimization reason.\n */\n messages?: never;\n} & Record<string, unknown>;\n\n/**\n * Overload set for {@link createTranslator}:\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 *
|
|
1
|
+
{"version":3,"file":"createTranslator.mjs","names":[],"sources":["../../../src/core/createTranslator.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { createNamespaceTranslator } from '../shared/namespaceTranslator';\nimport type {\n LooseTranslateFunction,\n TranslateFunction,\n TranslateFunctionForNamespace,\n} from '../shared/translateFunctionTypes';\n\n/**\n * Configuration accepted by {@link createTranslator}.\n *\n * Mirrors use-intl's `IntlConfig`, but `messages`, `formats`, `now`,\n * `timeZone`, `onError`, and `getMessageFallback` have no effect — Intlayer\n * resolves content from its own compiled dictionaries.\n */\nexport type CreateTranslatorConfig<N extends DictionaryKeys> = {\n /** The locale dictionaries are resolved for. */\n locale: LocalesValues;\n /** A bare dictionary key, or a nested `'dictionary.scope'` namespace. */\n namespace?: N | (string & {});\n /**\n * @deprecated has no use case with intlayer. Messages are loaded\n * automatically under the hood for bundle optimization reason.\n */\n messages?: never;\n} & Record<string, unknown>;\n\n/**\n * Overload set for {@link createTranslator}:\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 * dot-paths under the scope, typed against the dictionary, matching\n * use-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 CreateTranslator = {\n <N extends DictionaryKeys>(\n config: CreateTranslatorConfig<N> & { namespace: N }\n ): TranslateFunction<N>;\n <N extends `${string}.${string}`>(\n config: CreateTranslatorConfig<DictionaryKeys> & { namespace: N }\n ): TranslateFunctionForNamespace<N>;\n (config: CreateTranslatorConfig<DictionaryKeys>): LooseTranslateFunction;\n};\n\n/**\n * Drop-in for use-intl's `createTranslator`.\n *\n * Returns a translate function (with `rich`, `markup`, `raw`, `has`) that\n * resolves messages from Intlayer's compiled dictionaries for the given\n * `locale`. Messages support ICU MessageFormat syntax.\n *\n * @example\n * ```ts\n * const t = createTranslator({ locale: 'en', namespace: 'about' });\n * t('counter.label'); // ✓ typed\n * t('items', { count: 3 }); // ICU plural\n * ```\n */\nexport const createTranslator = (({\n locale,\n namespace,\n messages: _messages,\n}: CreateTranslatorConfig<DictionaryKeys>) => {\n if (process.env.NODE_ENV === 'development' && _messages !== undefined) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('createTranslator', CYAN)} do not pass the messages option with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return createNamespaceTranslator(locale, namespace);\n}) as CreateTranslator;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,qBAAqB,EAChC,QACA,WACA,UAAU,gBACkC;AAC5C,KAA8C,cAAc,OAE1D,CADkB,aAAa,EAAE,KAAK,CAC7B,CACP,GAAG,SAAS,oBAAoB,KAAK,CAAC,iIACvC;AAGH,QAAO,0BAA0B,QAAQ,UAAU"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createDictionaryTranslator } from "./shared/namespaceTranslator.mjs";
|
|
1
2
|
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
2
3
|
import { useDictionary } from "./useDictionary.mjs";
|
|
3
4
|
import { useFormatter, useMessages, useNow, useTimeZone } from "./client/helpers.mjs";
|
|
@@ -11,4 +12,4 @@ import { IntlError, IntlErrorCode } from "./core/errors.mjs";
|
|
|
11
12
|
import { hasLocale } from "./core/hasLocale.mjs";
|
|
12
13
|
import { initializeConfig } from "./core/initializeConfig.mjs";
|
|
13
14
|
|
|
14
|
-
export { IntlError, IntlErrorCode, IntlProvider, _useExtracted, createFormatter, createTranslator, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
15
|
+
export { IntlError, IntlErrorCode, IntlProvider, _useExtracted, createDictionaryTranslator, createFormatter, createTranslator, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
@@ -1,46 +1,13 @@
|
|
|
1
1
|
import * as ANSIColors from "@intlayer/config/colors";
|
|
2
2
|
import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { USE_INTL_CALLERS } from "@intlayer/config/callers";
|
|
5
5
|
import { getConfiguration } from "@intlayer/config/node";
|
|
6
|
+
import { runOnce } from "@intlayer/engine/utils";
|
|
6
7
|
import { intlayer } from "vite-intlayer";
|
|
7
8
|
|
|
8
9
|
//#region src/plugin/index.ts
|
|
9
10
|
/**
|
|
10
|
-
* Caller configurations for use-intl's translation entry points.
|
|
11
|
-
*
|
|
12
|
-
* Tells the intlayer field-usage analyser how to extract the dictionary key
|
|
13
|
-
* (namespace) and consumed fields from `useTranslations` / `createTranslator`
|
|
14
|
-
* call sites, enabling accurate dictionary pruning for projects using
|
|
15
|
-
* `@intlayer/use-intl`.
|
|
16
|
-
*/
|
|
17
|
-
const USE_INTL_COMPAT_CALLERS = [{
|
|
18
|
-
callerName: "useTranslations",
|
|
19
|
-
importSources: [
|
|
20
|
-
"use-intl",
|
|
21
|
-
"use-intl/react",
|
|
22
|
-
"@intlayer/use-intl"
|
|
23
|
-
],
|
|
24
|
-
namespace: {
|
|
25
|
-
from: "argument",
|
|
26
|
-
index: 0
|
|
27
|
-
},
|
|
28
|
-
translationFunction: "return-value"
|
|
29
|
-
}, {
|
|
30
|
-
callerName: "createTranslator",
|
|
31
|
-
importSources: [
|
|
32
|
-
"use-intl",
|
|
33
|
-
"use-intl/core",
|
|
34
|
-
"@intlayer/use-intl"
|
|
35
|
-
],
|
|
36
|
-
namespace: {
|
|
37
|
-
from: "option",
|
|
38
|
-
argumentIndex: 0,
|
|
39
|
-
property: "namespace"
|
|
40
|
-
},
|
|
41
|
-
translationFunction: "return-value"
|
|
42
|
-
}];
|
|
43
|
-
/**
|
|
44
11
|
* A Vite plugin for use-intl compat that wraps vite-intlayer and configures
|
|
45
12
|
* resolve aliases so `use-intl` imports are served by `@intlayer/use-intl`.
|
|
46
13
|
*
|
|
@@ -62,7 +29,7 @@ const useIntlVitePlugin = (options) => {
|
|
|
62
29
|
}, { cacheTimeoutMs: 1e3 * 60 * 60 });
|
|
63
30
|
const basePlugins = intlayer({
|
|
64
31
|
...options,
|
|
65
|
-
compatCallers: [...options?.compatCallers ?? [], ...
|
|
32
|
+
compatCallers: [...options?.compatCallers ?? [], ...USE_INTL_CALLERS]
|
|
66
33
|
});
|
|
67
34
|
const compatPlugin = {
|
|
68
35
|
name: "vite-use-intl-compat-plugin",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { USE_INTL_CALLERS } from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { runOnce } from '@intlayer/engine/utils';\nimport type { PluginOption } from 'vite';\nimport { intlayer } from 'vite-intlayer';\n\n/**\n * A Vite plugin for use-intl compat that wraps vite-intlayer and configures\n * resolve aliases so `use-intl` imports are served by `@intlayer/use-intl`.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import useIntlVitePlugin from '@intlayer/use-intl/plugin';\n *\n * export default defineConfig({\n * plugins: [useIntlVitePlugin()],\n * });\n * ```\n */\nexport const useIntlVitePlugin = (\n options?: Parameters<typeof intlayer>[0]\n): PluginOption[] => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const basePlugins = intlayer({\n ...options,\n compatCallers: [...(options?.compatCallers ?? []), ...USE_INTL_CALLERS],\n });\n\n const compatPlugin: PluginOption = {\n name: 'vite-use-intl-compat-plugin',\n config: () => ({\n resolve: {\n alias: {\n 'use-intl': '@intlayer/use-intl',\n },\n },\n }),\n };\n\n return [\n ...(Array.isArray(basePlugins) ? basePlugins : [basePlugins]),\n compatPlugin,\n ];\n};\n\nexport default useIntlVitePlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,qBACX,YACmB;CACnB,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,YAAY,aAAa,eAAe;AAE9C,SACE,KACE,eAAe,OAAO,SACtB,aACA,SACA,kCACD,QACK;AACJ,YAAU,CACR,SACE,+CACA,WAAW,KACZ,EACD,SACE,iDACA,WAAW,WACZ,CACF,CAAC;IAEJ,EACE,gBAAgB,MAAO,KAAK,IAC7B,CACF;CAED,MAAM,cAAc,SAAS;EAC3B,GAAG;EACH,eAAe,CAAC,GAAI,SAAS,iBAAiB,EAAE,EAAG,GAAG,iBAAiB;EACxE,CAAC;CAEF,MAAM,eAA6B;EACjC,MAAM;EACN,eAAe,EACb,SAAS,EACP,OAAO,EACL,YAAY,sBACb,EACF,EACF;EACF;AAED,QAAO,CACL,GAAI,MAAM,QAAQ,YAAY,GAAG,cAAc,CAAC,YAAY,EAC5D,aACD"}
|
|
@@ -1,31 +1,10 @@
|
|
|
1
|
+
import { Fragment } from "react";
|
|
1
2
|
import { getIntlayer } from "@intlayer/core/interpreter";
|
|
2
|
-
import { parseTaggedMessage, resolveMessage } from "@intlayer/core/messageFormat";
|
|
3
|
+
import { navigatePath, navigatePath as navigatePath$1, parseTaggedMessage, resolveMessage } from "@intlayer/core/messageFormat";
|
|
3
4
|
import { getDictionaries } from "@intlayer/dictionaries-entry";
|
|
4
|
-
import { Fragment } from "react";
|
|
5
5
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
6
6
|
|
|
7
7
|
//#region src/shared/namespaceTranslator.tsx
|
|
8
|
-
/**
|
|
9
|
-
* Reads a dotted `path` (e.g. `counter.label`) out of a nested object value.
|
|
10
|
-
*
|
|
11
|
-
* @param objectValue - The object to read from.
|
|
12
|
-
* @param path - Dot-separated path. An empty path returns `objectValue`.
|
|
13
|
-
* @returns The value found at `path`, or `undefined` when any segment is absent.
|
|
14
|
-
*/
|
|
15
|
-
const navigatePath = (objectValue, path) => {
|
|
16
|
-
if (!path) return objectValue;
|
|
17
|
-
if (path.includes(".") && objectValue !== null && objectValue !== void 0 && typeof objectValue === "object") {
|
|
18
|
-
const flatValue = objectValue[path];
|
|
19
|
-
if (flatValue !== void 0) return flatValue;
|
|
20
|
-
}
|
|
21
|
-
const parts = path.split(".");
|
|
22
|
-
let current = objectValue;
|
|
23
|
-
for (const part of parts) {
|
|
24
|
-
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
25
|
-
current = current[part];
|
|
26
|
-
}
|
|
27
|
-
return current;
|
|
28
|
-
};
|
|
29
8
|
/** Splits rich values into scalar interpolation values and tag renderers. */
|
|
30
9
|
const splitRichValues = (values = {}) => {
|
|
31
10
|
const scalarValues = {};
|
|
@@ -70,31 +49,63 @@ const renderMarkupTokens = (tokens, renderers) => tokens.map((token) => {
|
|
|
70
49
|
const createNamespaceTranslator = (locale, namespace) => {
|
|
71
50
|
const [dictionaryKey, ...prefixSegments] = (namespace ?? "").split(".");
|
|
72
51
|
const keyPrefix = prefixSegments.join(".");
|
|
73
|
-
const lookup = (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
52
|
+
const lookup = (lookupKey) => lookupNamespaceKey(locale, dictionaryKey ?? "", keyPrefix, lookupKey);
|
|
53
|
+
return createLookupTranslator(locale, lookup, (key) => namespace ? `${namespace}.${key}` : key);
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Key-based lookup used by {@link createNamespaceTranslator}: resolves the
|
|
57
|
+
* dictionary through the runtime registry (`getIntlayer`).
|
|
58
|
+
*/
|
|
59
|
+
const lookupNamespaceKey = (locale, dictionaryKey, keyPrefix, key) => {
|
|
60
|
+
let targetDictionaryKey = dictionaryKey;
|
|
61
|
+
let path = keyPrefix ? `${keyPrefix}.${key}` : key;
|
|
62
|
+
const dictionaries = getDictionaries();
|
|
63
|
+
if (!targetDictionaryKey) {
|
|
64
|
+
const [firstSegment, ...restSegments] = key.split(".");
|
|
65
|
+
targetDictionaryKey = firstSegment ?? key;
|
|
66
|
+
path = restSegments.join(".");
|
|
67
|
+
if (!dictionaries[targetDictionaryKey]) for (const dictKey of Object.keys(dictionaries)) try {
|
|
68
|
+
const result = navigatePath$1(getIntlayer(dictKey, locale), key);
|
|
69
|
+
if (result !== void 0) return result;
|
|
70
|
+
} catch {}
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return navigatePath$1(getIntlayer(targetDictionaryKey, locale), path);
|
|
74
|
+
} catch {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Dictionary-bound translator used by the build-optimized `useDictionary` /
|
|
80
|
+
* `getDictionary` variants: instead of resolving the dictionary by key at
|
|
81
|
+
* runtime, the pre-resolved content is supplied directly (the babel/swc
|
|
82
|
+
* optimize pass imports the dictionary JSON at build time).
|
|
83
|
+
*
|
|
84
|
+
* @param locale - The locale messages are resolved for.
|
|
85
|
+
* @param content - The dictionary content, already resolved for `locale`.
|
|
86
|
+
* @param namespacePrefix - Optional key prefix for nested namespaces
|
|
87
|
+
* (`useTranslations('about.counter')` → content of `about`, prefix `counter`).
|
|
88
|
+
* @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.
|
|
89
|
+
*/
|
|
90
|
+
const createDictionaryTranslator = (locale, content, namespacePrefix) => {
|
|
91
|
+
const resolveKey = (key) => namespacePrefix ? `${namespacePrefix}.${key}` : key;
|
|
92
|
+
return createLookupTranslator(locale, (key) => navigatePath$1(content, resolveKey(key)), resolveKey);
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The untyped runtime translator core shared by every factory above:
|
|
96
|
+
* ICU message resolution plus the `has` / `raw` / `rich` / `markup` helpers.
|
|
97
|
+
*
|
|
98
|
+
* @param locale - The locale messages are resolved for.
|
|
99
|
+
* @param lookup - Reads the raw content value for a message key.
|
|
100
|
+
* @param missingKeyFallback - Builds the echoed key on lookup miss
|
|
101
|
+
* (use-intl convention: `namespace.key`).
|
|
102
|
+
*/
|
|
103
|
+
const createLookupTranslator = (locale, lookup, missingKeyFallback) => {
|
|
92
104
|
const resolveToString = (key, values = {}) => {
|
|
93
105
|
const rawValue = lookup(key);
|
|
94
106
|
if (rawValue === null || rawValue === void 0) return void 0;
|
|
95
107
|
return resolveMessage(rawValue, values, locale, "icu");
|
|
96
108
|
};
|
|
97
|
-
const missingKeyFallback = (key) => namespace ? `${namespace}.${key}` : key;
|
|
98
109
|
const translate = (key, values) => resolveToString(key, values) ?? missingKeyFallback(key);
|
|
99
110
|
return Object.assign(translate, {
|
|
100
111
|
/** Returns `true` if the given key exists in the namespace. */
|
|
@@ -125,5 +136,5 @@ const createNamespaceTranslator = (locale, namespace) => {
|
|
|
125
136
|
};
|
|
126
137
|
|
|
127
138
|
//#endregion
|
|
128
|
-
export { createNamespaceTranslator, navigatePath };
|
|
139
|
+
export { createDictionaryTranslator, createNamespaceTranslator, navigatePath };
|
|
129
140
|
//# sourceMappingURL=namespaceTranslator.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"namespaceTranslator.mjs","names":[],"sources":["../../../src/shared/namespaceTranslator.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 { getDictionaries } from '@intlayer/dictionaries-entry';\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\n/**\n * Reads a dotted `path` (e.g. `counter.label`) out of a nested object value.\n *\n * @param objectValue - The object to read from.\n * @param path - Dot-separated path. An empty path returns `objectValue`.\n * @returns The value found at `path`, or `undefined` when any segment is absent.\n */\nexport const navigatePath = (objectValue: unknown, path: string): unknown => {\n if (!path) return objectValue;\n\n // Try the full key as a flat property first (supports flat JSON files\n // that use dotted keys like \"section.title\": \"value\").\n if (\n path.includes('.') &&\n objectValue !== null &&\n objectValue !== undefined &&\n typeof objectValue === 'object'\n ) {\n const flatValue = (objectValue as Record<string, unknown>)[path];\n if (flatValue !== undefined) {\n return flatValue;\n }\n }\n\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` (React hook) and\n * `createTranslator` (non-React core).\n *\n * Behaviour matches use-intl / 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 *\n * @param locale - The locale dictionaries are resolved for.\n * @param namespace - Optional dictionary key, optionally with a nested scope.\n * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.\n */\nexport const createNamespaceTranslator = (\n locale: LocalesValues,\n namespace?: string\n) => {\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 const dictionaries = getDictionaries();\n\n if (!targetDictionaryKey) {\n // Root scope — the first key segment usually designates the dictionary\n const [firstSegment, ...restSegments] = key.split('.');\n targetDictionaryKey = firstSegment;\n path = restSegments.join('.');\n\n // If the assumed dictionary doesn't exist, we must fall back to searching all dictionaries.\n // This supports apps migrating from standard next-intl where all messages were grouped together.\n if (!dictionaries[targetDictionaryKey as DictionaryKeys]) {\n for (const dictKey of Object.keys(dictionaries)) {\n try {\n const dictionary = getIntlayer(dictKey as DictionaryKeys, locale);\n const result = navigatePath(dictionary, key);\n if (result !== undefined) {\n return result;\n }\n } catch {\n // Ignore if getIntlayer throws\n }\n }\n }\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 createNamespaceTranslator>;\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"namespaceTranslator.mjs","names":["navigatePath"],"sources":["../../../src/shared/namespaceTranslator.tsx"],"sourcesContent":["import { getIntlayer } from '@intlayer/core/interpreter';\nimport {\n type MessageValues,\n navigatePath,\n parseTaggedMessage,\n resolveMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { Fragment, type ReactNode } from 'react';\n\nexport { navigatePath } from '@intlayer/core/messageFormat';\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\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` (React hook) and\n * `createTranslator` (non-React core).\n *\n * Behaviour matches use-intl / 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 *\n * @param locale - The locale dictionaries are resolved for.\n * @param namespace - Optional dictionary key, optionally with a nested scope.\n * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.\n */\nexport const createNamespaceTranslator = (\n locale: LocalesValues,\n namespace?: string\n) => {\n const [dictionaryKey, ...prefixSegments] = (namespace ?? '').split('.');\n const keyPrefix = prefixSegments.join('.');\n\n const lookup = (lookupKey: string): unknown =>\n lookupNamespaceKey(locale, dictionaryKey ?? '', keyPrefix, lookupKey);\n\n return createLookupTranslator(locale, lookup, (key) =>\n namespace ? `${namespace}.${key}` : key\n );\n};\n\n/**\n * Key-based lookup used by {@link createNamespaceTranslator}: resolves the\n * dictionary through the runtime registry (`getIntlayer`).\n */\nconst lookupNamespaceKey = (\n locale: LocalesValues,\n dictionaryKey: string,\n keyPrefix: string,\n key: string\n): unknown => {\n let targetDictionaryKey = dictionaryKey;\n let path = keyPrefix ? `${keyPrefix}.${key}` : key;\n\n const dictionaries = getDictionaries();\n\n if (!targetDictionaryKey) {\n // Root scope — the first key segment usually designates the dictionary\n const [firstSegment, ...restSegments] = key.split('.');\n targetDictionaryKey = firstSegment ?? key;\n path = restSegments.join('.');\n\n // If the assumed dictionary doesn't exist, we must fall back to searching all dictionaries.\n // This supports apps migrating from standard next-intl where all messages were grouped together.\n if (!dictionaries[targetDictionaryKey as DictionaryKeys]) {\n for (const dictKey of Object.keys(dictionaries)) {\n try {\n const dictionary = getIntlayer(dictKey as DictionaryKeys, locale);\n const result = navigatePath(dictionary, key);\n if (result !== undefined) {\n return result;\n }\n } catch {\n // Ignore if getIntlayer throws\n }\n }\n }\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/**\n * Dictionary-bound translator used by the build-optimized `useDictionary` /\n * `getDictionary` variants: instead of resolving the dictionary by key at\n * runtime, the pre-resolved content is supplied directly (the babel/swc\n * optimize pass imports the dictionary JSON at build time).\n *\n * @param locale - The locale messages are resolved for.\n * @param content - The dictionary content, already resolved for `locale`.\n * @param namespacePrefix - Optional key prefix for nested namespaces\n * (`useTranslations('about.counter')` → content of `about`, prefix `counter`).\n * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.\n */\nexport const createDictionaryTranslator = (\n locale: LocalesValues,\n content: unknown,\n namespacePrefix?: string\n) => {\n const resolveKey = (key: string): string =>\n namespacePrefix ? `${namespacePrefix}.${key}` : key;\n\n return createLookupTranslator(\n locale,\n (key) => navigatePath(content, resolveKey(key)),\n resolveKey\n );\n};\n\n/**\n * The untyped runtime translator core shared by every factory above:\n * ICU message resolution plus the `has` / `raw` / `rich` / `markup` helpers.\n *\n * @param locale - The locale messages are resolved for.\n * @param lookup - Reads the raw content value for a message key.\n * @param missingKeyFallback - Builds the echoed key on lookup miss\n * (use-intl convention: `namespace.key`).\n */\nconst createLookupTranslator = (\n locale: LocalesValues,\n lookup: (key: string) => unknown,\n missingKeyFallback: (key: string) => string\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 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 createNamespaceTranslator>;\n"],"mappings":"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"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { createDictionaryTranslator } from "./shared/namespaceTranslator.mjs";
|
|
4
|
+
import { useContext } from "react";
|
|
5
|
+
import { IntlayerClientContext, useDictionary as useDictionary$1 } from "react-intlayer";
|
|
5
6
|
|
|
6
7
|
//#region src/useDictionary.ts
|
|
7
8
|
/**
|
|
@@ -12,23 +13,17 @@ import { useDictionary as useDictionary$1 } from "react-intlayer";
|
|
|
12
13
|
* JSON at build time and passes it directly here. This enables tree-shaking of
|
|
13
14
|
* unused locale content.
|
|
14
15
|
*
|
|
16
|
+
* The returned translator matches `useTranslations` exactly (ICU messages,
|
|
17
|
+
* `has`, `raw`, `rich`, `markup`).
|
|
18
|
+
*
|
|
15
19
|
* @example (generated by the plugin, not written manually)
|
|
16
20
|
* import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
|
|
17
21
|
* const t = useDictionary(_abc);
|
|
18
22
|
*/
|
|
19
|
-
const useDictionary = (dictionary, namespacePrefix) => {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const rawValue = navigatePath(content, resolveKey(String(lookup)));
|
|
24
|
-
const text = String(rawValue ?? resolveKey(String(lookup)));
|
|
25
|
-
if (!params) return text;
|
|
26
|
-
return text.replace(/\{(\w+)\}/g, (_match, key) => params[key] != null ? String(params[key]) : `{${key}}`);
|
|
27
|
-
}, {
|
|
28
|
-
has: (lookup) => navigatePath(content, resolveKey(String(lookup))) != null,
|
|
29
|
-
raw: (lookup) => navigatePath(content, resolveKey(String(lookup)))
|
|
30
|
-
});
|
|
31
|
-
};
|
|
23
|
+
const useDictionary = ((dictionary, namespacePrefix) => {
|
|
24
|
+
const { locale } = useContext(IntlayerClientContext) ?? {};
|
|
25
|
+
return createDictionaryTranslator(locale, useDictionary$1(dictionary), namespacePrefix);
|
|
26
|
+
});
|
|
32
27
|
|
|
33
28
|
//#endregion
|
|
34
29
|
export { useDictionary };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":["useDictionaryBase"],"sources":["../../src/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":["useDictionaryBase"],"sources":["../../src/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'react';\nimport {\n IntlayerClientContext,\n useDictionary as useDictionaryBase,\n} from 'react-intlayer';\nimport { createDictionaryTranslator } from './shared/namespaceTranslator';\nimport type {\n ScopedTranslateFunction,\n TranslateFunction,\n} from './shared/translateFunctionTypes';\n\n/**\n * Overload set for {@link useDictionary}: without a prefix the translator is\n * typed against the dictionary's dot-paths; with a prefix the keys are\n * relative dot-paths under that scope.\n */\ntype UseDictionary = {\n <T extends Dictionary>(\n dictionary: T\n ): TranslateFunction<T['key'] & DictionaryKeys>;\n <T extends Dictionary, Prefix extends string>(\n dictionary: T,\n namespacePrefix: Prefix\n ): ScopedTranslateFunction<T['key'] & DictionaryKeys, Prefix>;\n};\n\n/**\n * Dictionary-accepting variant of `useTranslations`.\n *\n * Used internally by the build-time optimization: instead of looking up the\n * dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary\n * JSON at build time and passes it directly here. This enables tree-shaking of\n * unused locale content.\n *\n * The returned translator matches `useTranslations` exactly (ICU messages,\n * `has`, `raw`, `rich`, `markup`).\n *\n * @example (generated by the plugin, 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 { locale } = useContext(IntlayerClientContext) ?? {};\n const content = useDictionaryBase(dictionary);\n\n return createDictionaryTranslator(\n locale as LocalesValues,\n content,\n namespacePrefix\n );\n}) as UseDictionary;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,kBACX,YACA,oBACG;CACH,MAAM,EAAE,WAAW,WAAW,sBAAsB,IAAI,EAAE;AAG1D,QAAO,2BACL,QAHcA,gBAAkB,WAIzB,EACP,gBACD"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { createDictionaryTranslator } from "./shared/namespaceTranslator.mjs";
|
|
4
|
+
import { useContext } from "react";
|
|
5
|
+
import { IntlayerClientContext, useDictionaryDynamic as useDictionaryDynamic$1 } from "react-intlayer";
|
|
5
6
|
|
|
6
7
|
//#region src/useDictionaryDynamic.ts
|
|
7
8
|
/**
|
|
@@ -10,19 +11,10 @@ import { useDictionaryDynamic as useDictionaryDynamic$1 } from "react-intlayer";
|
|
|
10
11
|
* Counterpart to {@link useDictionary} for dictionaries imported lazily per
|
|
11
12
|
* locale. Used internally by the build-time optimization.
|
|
12
13
|
*/
|
|
13
|
-
const useDictionaryDynamic = (dictionaryPromise, key, namespacePrefix) => {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const rawValue = navigatePath(content, resolveKey(String(lookup)));
|
|
18
|
-
const text = String(rawValue ?? resolveKey(String(lookup)));
|
|
19
|
-
if (!params) return text;
|
|
20
|
-
return text.replace(/\{(\w+)\}/g, (_match, key) => params[key] != null ? String(params[key]) : `{${key}}`);
|
|
21
|
-
}, {
|
|
22
|
-
has: (lookup) => navigatePath(content, resolveKey(String(lookup))) != null,
|
|
23
|
-
raw: (lookup) => navigatePath(content, resolveKey(String(lookup)))
|
|
24
|
-
});
|
|
25
|
-
};
|
|
14
|
+
const useDictionaryDynamic = ((dictionaryPromise, key, namespacePrefix) => {
|
|
15
|
+
const { locale } = useContext(IntlayerClientContext) ?? {};
|
|
16
|
+
return createDictionaryTranslator(locale, useDictionaryDynamic$1(dictionaryPromise, key), namespacePrefix);
|
|
17
|
+
});
|
|
26
18
|
|
|
27
19
|
//#endregion
|
|
28
20
|
export { useDictionaryDynamic };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":["useDictionaryDynamicBase"],"sources":["../../src/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":["useDictionaryDynamicBase"],"sources":["../../src/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'react';\nimport {\n IntlayerClientContext,\n useDictionaryDynamic as useDictionaryDynamicBase,\n} from 'react-intlayer';\nimport { createDictionaryTranslator } from './shared/namespaceTranslator';\nimport type {\n ScopedTranslateFunction,\n TranslateFunction,\n} from './shared/translateFunctionTypes';\n\n/**\n * Overload set for {@link useDictionaryDynamic}: without a prefix the\n * translator is typed against the dictionary's dot-paths; with a prefix the\n * keys are relative dot-paths under that scope.\n */\ntype UseDictionaryDynamic = {\n <T extends Dictionary, K extends DictionaryKeys>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K\n ): TranslateFunction<K>;\n <T extends Dictionary, K extends DictionaryKeys, Prefix extends string>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix: Prefix\n ): ScopedTranslateFunction<K, Prefix>;\n};\n\n/**\n * Dynamic dictionary-accepting variant of `useTranslations`.\n *\n * Counterpart to {@link useDictionary} for dictionaries imported lazily per\n * locale. Used internally by the build-time optimization.\n */\nexport const useDictionaryDynamic = (<\n const T extends Dictionary,\n const K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix?: string\n) => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n const content = useDictionaryDynamicBase<T, K>(dictionaryPromise, key);\n\n return createDictionaryTranslator(\n locale as LocalesValues,\n content,\n namespacePrefix\n );\n}) as UseDictionaryDynamic;\n"],"mappings":";;;;;;;;;;;;;AA0CA,MAAa,yBAIX,mBACA,KACA,oBACG;CACH,MAAM,EAAE,WAAW,WAAW,sBAAsB,IAAI,EAAE;AAG1D,QAAO,2BACL,QAHcA,uBAA+B,mBAAmB,IAIzD,EACP,gBACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LooseTranslateFunction, TranslateFunction } from "../shared/translateFunctionTypes.js";
|
|
1
|
+
import { LooseTranslateFunction, TranslateFunction, TranslateFunctionForNamespace } from "../shared/translateFunctionTypes.js";
|
|
2
2
|
import { DictionaryKeys } from "@intlayer/types/module_augmentation";
|
|
3
3
|
|
|
4
4
|
//#region src/client/useTranslations.d.ts
|
|
@@ -7,13 +7,14 @@ import { DictionaryKeys } from "@intlayer/types/module_augmentation";
|
|
|
7
7
|
*
|
|
8
8
|
* 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).
|
|
9
9
|
* 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative
|
|
10
|
-
*
|
|
10
|
+
* dot-paths under the scope, typed against the dictionary, matching
|
|
11
|
+
* use-intl's scoped-namespace behaviour.
|
|
11
12
|
* 3. No namespace → root scope; the first segment of each key designates
|
|
12
13
|
* the dictionary (`t('about.title')`).
|
|
13
14
|
*/
|
|
14
15
|
type UseTranslations = {
|
|
15
16
|
<N extends DictionaryKeys>(namespace: N): TranslateFunction<N>;
|
|
16
|
-
|
|
17
|
+
<N extends `${string}.${string}`>(namespace: N): TranslateFunctionForNamespace<N>;
|
|
17
18
|
(): LooseTranslateFunction;
|
|
18
19
|
};
|
|
19
20
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslations.d.ts","names":[],"sources":["../../../src/client/useTranslations.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"useTranslations.d.ts","names":[],"sources":["../../../src/client/useTranslations.ts"],"mappings":";;;;;;AAa0C;;;;;;;;KAYrC,eAAA;EAAA,WACQ,cAAA,EAAgB,SAAA,EAAW,CAAA,GAAI,iBAAA,CAAkB,CAAA;EAAA,kCAE1D,SAAA,EAAW,CAAA,GACV,6BAAA,CAA8B,CAAA;EAAA,IAC7B,sBAAA;AAAA;;;;;;;;;;;;;;;AAyBN;;;;;;;;cAAa,eAAA,EAOP,eAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LooseTranslateFunction, TranslateFunction } from "../shared/translateFunctionTypes.js";
|
|
1
|
+
import { LooseTranslateFunction, TranslateFunction, TranslateFunctionForNamespace } from "../shared/translateFunctionTypes.js";
|
|
2
2
|
import { DictionaryKeys, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
3
|
|
|
4
4
|
//#region src/core/createTranslator.d.ts
|
|
@@ -23,7 +23,8 @@ type CreateTranslatorConfig<N extends DictionaryKeys> = {
|
|
|
23
23
|
*
|
|
24
24
|
* 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).
|
|
25
25
|
* 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative
|
|
26
|
-
*
|
|
26
|
+
* dot-paths under the scope, typed against the dictionary, matching
|
|
27
|
+
* use-intl's scoped-namespace behaviour.
|
|
27
28
|
* 3. No namespace → root scope; the first segment of each key designates
|
|
28
29
|
* the dictionary (`t('about.title')`).
|
|
29
30
|
*/
|
|
@@ -31,9 +32,9 @@ type CreateTranslator = {
|
|
|
31
32
|
<N extends DictionaryKeys>(config: CreateTranslatorConfig<N> & {
|
|
32
33
|
namespace: N;
|
|
33
34
|
}): TranslateFunction<N>;
|
|
34
|
-
(config: CreateTranslatorConfig<DictionaryKeys> & {
|
|
35
|
-
namespace:
|
|
36
|
-
}):
|
|
35
|
+
<N extends `${string}.${string}`>(config: CreateTranslatorConfig<DictionaryKeys> & {
|
|
36
|
+
namespace: N;
|
|
37
|
+
}): TranslateFunctionForNamespace<N>;
|
|
37
38
|
(config: CreateTranslatorConfig<DictionaryKeys>): LooseTranslateFunction;
|
|
38
39
|
};
|
|
39
40
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTranslator.d.ts","names":[],"sources":["../../../src/core/createTranslator.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"createTranslator.d.ts","names":[],"sources":["../../../src/core/createTranslator.ts"],"mappings":";;;;;;AAqBA;;;;;KAAY,sBAAA,WAAiC,cAAA;EAUzC,gDARF,MAAA,EAAQ,aAAA,EAQA;EANR,SAAA,GAAY,CAAA;EAJ+B;;;;EAS3C,QAAA;AAAA,IACE,MAAA;;;;AAAwB;;;;;;;KAYvB,gBAAA;EAAA,WACQ,cAAA,EACT,MAAA,EAAQ,sBAAA,CAAuB,CAAA;IAAO,SAAA,EAAW,CAAA;EAAA,IAChD,iBAAA,CAAkB,CAAA;EAAA,kCAEnB,MAAA,EAAQ,sBAAA,CAAuB,cAAA;IAAoB,SAAA,EAAW,CAAA;EAAA,IAC7D,6BAAA,CAA8B,CAAA;EAAA,CAChC,MAAA,EAAQ,sBAAA,CAAuB,cAAA,IAAkB,sBAAA;AAAA;;;;;;;;;;;;;;;cAiBvC,gBAAA,EAaP,gBAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IntlProvider, IntlProviderProps } from "./client/IntlProvider.js";
|
|
2
2
|
import { useFormatter, useMessages, useNow, useTimeZone } from "./client/helpers.js";
|
|
3
|
+
import { MarkupChunkRenderer, RichChunkRenderer, createDictionaryTranslator } from "./shared/namespaceTranslator.js";
|
|
4
|
+
import { ContentAtPath, LooseTranslateFunction, ScopedDotPaths, ScopedTranslateFunction, TranslateFunction, TranslateFunctionForNamespace, TranslatedValue } from "./shared/translateFunctionTypes.js";
|
|
3
5
|
import { useDictionary } from "./useDictionary.js";
|
|
4
6
|
import { useDictionaryDynamic } from "./useDictionaryDynamic.js";
|
|
5
7
|
import { useLocale } from "./client/useLocale.js";
|
|
6
|
-
import { MarkupChunkRenderer, RichChunkRenderer } from "./shared/namespaceTranslator.js";
|
|
7
|
-
import { LooseTranslateFunction, TranslateFunction } from "./shared/translateFunctionTypes.js";
|
|
8
8
|
import { useTranslations } from "./client/useTranslations.js";
|
|
9
9
|
import { _useExtracted } from "./client/index.js";
|
|
10
10
|
import { createFormatter } from "./core/createFormatter.js";
|
|
@@ -13,4 +13,4 @@ import { IntlError, IntlErrorCode } from "./core/errors.js";
|
|
|
13
13
|
import { hasLocale } from "./core/hasLocale.js";
|
|
14
14
|
import { initializeConfig } from "./core/initializeConfig.js";
|
|
15
15
|
import { AbstractIntlMessages, AppConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, Locale, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, RichTagsFunction, RichTranslationValues, Timezone, TranslationValues } from "./core/types.js";
|
|
16
|
-
export { AbstractIntlMessages, AppConfig, CreateTranslatorConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, IntlError, IntlErrorCode, IntlProvider, IntlProviderProps, Locale, type LooseTranslateFunction, type MarkupChunkRenderer, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, type RichChunkRenderer, RichTagsFunction, RichTranslationValues, Timezone, type TranslateFunction, TranslationValues, _useExtracted, createFormatter, createTranslator, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
16
|
+
export { AbstractIntlMessages, AppConfig, type ContentAtPath, CreateTranslatorConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, IntlError, IntlErrorCode, IntlProvider, IntlProviderProps, Locale, type LooseTranslateFunction, type MarkupChunkRenderer, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, type RichChunkRenderer, RichTagsFunction, RichTranslationValues, type ScopedDotPaths, type ScopedTranslateFunction, Timezone, type TranslateFunction, type TranslateFunctionForNamespace, type TranslatedValue, TranslationValues, _useExtracted, createDictionaryTranslator, createFormatter, createTranslator, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":";;;;;;AAuBA;;;;;;;;;;;;cAAa,iBAAA,GACX,OAAA,GAAU,UAAA,QAAkB,QAAA,SAC3B,YAAA"}
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
|
-
import { MessageValues } from "@intlayer/core/messageFormat";
|
|
3
|
+
import { MessageValues, navigatePath } from "@intlayer/core/messageFormat";
|
|
4
4
|
|
|
5
5
|
//#region src/shared/namespaceTranslator.d.ts
|
|
6
6
|
/** Chunk renderer used by `t.rich()` — maps tag children to a React node. */
|
|
7
7
|
type RichChunkRenderer = (chunks: ReactNode) => ReactNode;
|
|
8
8
|
/** Chunk renderer used by `t.markup()` — maps tag children to a string. */
|
|
9
9
|
type MarkupChunkRenderer = (chunks: string) => string;
|
|
10
|
-
/**
|
|
11
|
-
* Reads a dotted `path` (e.g. `counter.label`) out of a nested object value.
|
|
12
|
-
*
|
|
13
|
-
* @param objectValue - The object to read from.
|
|
14
|
-
* @param path - Dot-separated path. An empty path returns `objectValue`.
|
|
15
|
-
* @returns The value found at `path`, or `undefined` when any segment is absent.
|
|
16
|
-
*/
|
|
17
|
-
declare const navigatePath: (objectValue: unknown, path: string) => unknown;
|
|
18
10
|
/**
|
|
19
11
|
* The untyped runtime translator shared by `useTranslations` (React hook) and
|
|
20
12
|
* `createTranslator` (non-React core).
|
|
@@ -45,7 +37,33 @@ declare const createNamespaceTranslator: (locale: LocalesValues, namespace?: str
|
|
|
45
37
|
*/
|
|
46
38
|
markup: (key: string, values?: Record<string, unknown>) => string;
|
|
47
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Dictionary-bound translator used by the build-optimized `useDictionary` /
|
|
42
|
+
* `getDictionary` variants: instead of resolving the dictionary by key at
|
|
43
|
+
* runtime, the pre-resolved content is supplied directly (the babel/swc
|
|
44
|
+
* optimize pass imports the dictionary JSON at build time).
|
|
45
|
+
*
|
|
46
|
+
* @param locale - The locale messages are resolved for.
|
|
47
|
+
* @param content - The dictionary content, already resolved for `locale`.
|
|
48
|
+
* @param namespacePrefix - Optional key prefix for nested namespaces
|
|
49
|
+
* (`useTranslations('about.counter')` → content of `about`, prefix `counter`).
|
|
50
|
+
* @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.
|
|
51
|
+
*/
|
|
52
|
+
declare const createDictionaryTranslator: (locale: LocalesValues, content: unknown, namespacePrefix?: string) => ((key: string, values?: MessageValues) => string) & {
|
|
53
|
+
/** Returns `true` if the given key exists in the namespace. */has: (key: string) => boolean; /** Returns the raw unprocessed content for the given key. */
|
|
54
|
+
raw: (key: string) => unknown;
|
|
55
|
+
/**
|
|
56
|
+
* Resolves a message containing `<tag>chunks</tag>` markup, mapping each
|
|
57
|
+
* tag through the matching renderer in `values`.
|
|
58
|
+
*/
|
|
59
|
+
rich: (key: string, values?: Record<string, unknown>) => ReactNode;
|
|
60
|
+
/**
|
|
61
|
+
* Resolves a message containing `<tag>chunks</tag>` markup into a string,
|
|
62
|
+
* mapping each tag through the matching string renderer in `values`.
|
|
63
|
+
*/
|
|
64
|
+
markup: (key: string, values?: Record<string, unknown>) => string;
|
|
65
|
+
};
|
|
48
66
|
type CompatTranslator = ReturnType<typeof createNamespaceTranslator>;
|
|
49
67
|
//#endregion
|
|
50
|
-
export { CompatTranslator, MarkupChunkRenderer, RichChunkRenderer, createNamespaceTranslator, navigatePath };
|
|
68
|
+
export { CompatTranslator, MarkupChunkRenderer, RichChunkRenderer, createDictionaryTranslator, createNamespaceTranslator, navigatePath };
|
|
51
69
|
//# sourceMappingURL=namespaceTranslator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"namespaceTranslator.d.ts","names":[],"sources":["../../../src/shared/namespaceTranslator.tsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"namespaceTranslator.d.ts","names":[],"sources":["../../../src/shared/namespaceTranslator.tsx"],"mappings":";;;;;;KAkBY,iBAAA,IAAqB,MAAA,EAAQ,SAAA,KAAc,SAAA;;KAG3C,mBAAA,IAAuB,MAAA;;;;;;;AAAnC;;;;;AA0EA;;;;;cAAa,yBAAA,GACX,MAAA,EAAQ,aAAA,EACR,SAAA,gBAAkB,GAAA,UAgHY,MAAA,GAAW,aAAA;EAcgB,8FAWlB;;EA1I/B;;;;sBA+HY,MAAA,GAAW,MAAA,sBAA0B,SAAA;EAd3B;;;;wBAyBR,MAAA,GAAW,MAAA;AAAA;;;;;;;;;;;AA/DnC;;cAAa,0BAAA,GACX,MAAA,EAAQ,aAAA,EACR,OAAA,WACA,eAAA,gBAAwB,GAAA,UAmCM,MAAA,GAAW,aAAA;EArCjC,8FAmDuB;;EAWE;;;;sBAXb,MAAA,GAAW,MAAA,sBAA0B,SAAA;EAlDzD;;;;wBA6DsB,MAAA,GAAW,MAAA;AAAA;AAAA,KASvB,gBAAA,GAAmB,UAAA,QAAkB,yBAAA"}
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
import { MarkupChunkRenderer, RichChunkRenderer } from "./namespaceTranslator.js";
|
|
2
2
|
import { DictionaryKeys } from "@intlayer/types/module_augmentation";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
|
+
import { GetNestingResult } from "@intlayer/core/interpreter";
|
|
4
5
|
import { ValidDotPathsFor } from "@intlayer/core/transpiler";
|
|
5
6
|
|
|
6
7
|
//#region src/shared/translateFunctionTypes.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* The interpreter-resolved content type at dot-path `P` of dictionary `N` —
|
|
10
|
+
* the same type strength as the base `useIntlayer` hook.
|
|
11
|
+
*/
|
|
12
|
+
type ContentAtPath<N extends DictionaryKeys, P> = GetNestingResult<N, P>;
|
|
13
|
+
/**
|
|
14
|
+
* The value returned by `t()` for key `P` of dictionary `N`: string literals
|
|
15
|
+
* declared in the dictionary keep their literal type (matching the strength of
|
|
16
|
+
* `useIntlayer`), every other node resolves to `string` at runtime.
|
|
17
|
+
*/
|
|
18
|
+
type TranslatedValue<N extends DictionaryKeys, P> = ContentAtPath<N, P> extends string ? ContentAtPath<N, P> : string;
|
|
19
|
+
/**
|
|
20
|
+
* The dot-paths of dictionary `D` relative to the nested namespace scope
|
|
21
|
+
* `Prefix` (`useTranslations('about.counter')` → paths under `about.counter`).
|
|
22
|
+
*/
|
|
23
|
+
type ScopedDotPaths<D extends DictionaryKeys, Prefix extends string> = ValidDotPathsFor<D> extends infer AllPaths ? AllPaths extends `${Prefix}.${infer RelativePath}` ? RelativePath : never : never;
|
|
7
24
|
/**
|
|
8
25
|
* The translation function returned for a bare dictionary key namespace.
|
|
9
26
|
*
|
|
@@ -15,13 +32,32 @@ import { ValidDotPathsFor } from "@intlayer/core/transpiler";
|
|
|
15
32
|
* - `markup(key, values)` — resolves `<tag>chunks</tag>` markup to a string.
|
|
16
33
|
*/
|
|
17
34
|
type TranslateFunction<N extends DictionaryKeys> = {
|
|
18
|
-
/** Translate a key to a string, with optional ICU interpolation params. */<P extends ValidDotPathsFor<N>>(key: P, params?: Record<string, unknown>):
|
|
35
|
+
/** Translate a key to a string, with optional ICU interpolation params. */<P extends ValidDotPathsFor<N>>(key: P, params?: Record<string, unknown>): TranslatedValue<N, P>; /** Returns `true` if the given key exists in the namespace. */
|
|
19
36
|
has<P extends ValidDotPathsFor<N>>(key: P): boolean; /** Returns the raw unprocessed content for the given key. */
|
|
20
|
-
raw<P extends ValidDotPathsFor<N>>(key: P):
|
|
37
|
+
raw<P extends ValidDotPathsFor<N>>(key: P): ContentAtPath<N, P>; /** Resolves rich-text markup, mapping tags through React renderers. */
|
|
21
38
|
rich<P extends ValidDotPathsFor<N>>(key: P, values?: Record<string, RichChunkRenderer | ReactNode>): ReactNode; /** Resolves rich-text markup, mapping tags through string renderers. */
|
|
22
39
|
markup<P extends ValidDotPathsFor<N>>(key: P, values?: Record<string, MarkupChunkRenderer | string | number>): string;
|
|
23
40
|
};
|
|
24
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The translation function returned for a nested `'dictionary.scope'`
|
|
43
|
+
* namespace: keys are relative dot-paths under the scope, and return types are
|
|
44
|
+
* resolved against the absolute path in the dictionary.
|
|
45
|
+
*/
|
|
46
|
+
type ScopedTranslateFunction<D extends DictionaryKeys, Prefix extends string> = {
|
|
47
|
+
/** Translate a scoped key to a string, with optional ICU interpolation params. */<P extends ScopedDotPaths<D, Prefix>>(key: P, params?: Record<string, unknown>): TranslatedValue<D, `${Prefix}.${P}`>; /** Returns `true` if the given key exists in the scoped namespace. */
|
|
48
|
+
has<P extends ScopedDotPaths<D, Prefix>>(key: P): boolean; /** Returns the raw unprocessed content for the given scoped key. */
|
|
49
|
+
raw<P extends ScopedDotPaths<D, Prefix>>(key: P): ContentAtPath<D, `${Prefix}.${P}`>; /** Resolves rich-text markup, mapping tags through React renderers. */
|
|
50
|
+
rich<P extends ScopedDotPaths<D, Prefix>>(key: P, values?: Record<string, RichChunkRenderer | ReactNode>): ReactNode; /** Resolves rich-text markup, mapping tags through string renderers. */
|
|
51
|
+
markup<P extends ScopedDotPaths<D, Prefix>>(key: P, values?: Record<string, MarkupChunkRenderer | string | number>): string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Resolves the translation function type for a namespace argument: a bare
|
|
55
|
+
* dictionary key keeps the fully-typed dot-paths, a nested
|
|
56
|
+
* `'dictionary.scope'` namespace is split at the first dot and typed
|
|
57
|
+
* relative to the scope, anything else falls back to loose typing.
|
|
58
|
+
*/
|
|
59
|
+
type TranslateFunctionForNamespace<N extends string> = N extends DictionaryKeys ? TranslateFunction<N> : N extends `${infer D extends DictionaryKeys & string}.${infer Prefix}` ? ScopedTranslateFunction<D, Prefix> : LooseTranslateFunction;
|
|
60
|
+
/** Loosely-typed function returned for untyped namespaces (root scope). */
|
|
25
61
|
type LooseTranslateFunction = {
|
|
26
62
|
(key: string, params?: Record<string, unknown>): string;
|
|
27
63
|
has(key: string): boolean;
|
|
@@ -30,5 +66,5 @@ type LooseTranslateFunction = {
|
|
|
30
66
|
markup(key: string, values?: Record<string, MarkupChunkRenderer | string | number>): string;
|
|
31
67
|
};
|
|
32
68
|
//#endregion
|
|
33
|
-
export { LooseTranslateFunction, TranslateFunction };
|
|
69
|
+
export { ContentAtPath, LooseTranslateFunction, ScopedDotPaths, ScopedTranslateFunction, TranslateFunction, TranslateFunctionForNamespace, TranslatedValue };
|
|
34
70
|
//# sourceMappingURL=translateFunctionTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translateFunctionTypes.d.ts","names":[],"sources":["../../../src/shared/translateFunctionTypes.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"translateFunctionTypes.d.ts","names":[],"sources":["../../../src/shared/translateFunctionTypes.ts"],"mappings":";;;;;;;;;AAaA;;KAAY,aAAA,WAAwB,cAAA,OAAqB,gBAAA,CAAiB,CAAA,EAAG,CAAA;;;;;;KAOjE,eAAA,WAA0B,cAAA,OACpC,aAAA,CAAc,CAAA,EAAG,CAAA,mBAAoB,aAAA,CAAc,CAAA,EAAG,CAAA;;;;;KAM5C,cAAA,WAAyB,cAAA,2BACnC,gBAAA,CAAiB,CAAA,2BACb,QAAA,YAAoB,MAAA,2BAClB,YAAA;;;;AAVR;;;;;;;KAwBY,iBAAA,WAA4B,cAAA;EAvBgB,sFAyB3C,gBAAA,CAAiB,CAAA,GAC1B,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,oBACR,eAAA,CAAgB,CAAA,EAAG,CAAA,GA5B4B;EA8BlD,GAAA,WAAc,gBAAA,CAAiB,CAAA,GAAI,GAAA,EAAK,CAAA,YA/Bd;EAiC1B,GAAA,WAAc,gBAAA,CAAiB,CAAA,GAAI,GAAA,EAAK,CAAA,GAAI,aAAA,CAAc,CAAA,EAAG,CAAA,GAjCT;EAmCpD,IAAA,WAAe,gBAAA,CAAiB,CAAA,GAC9B,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,SAAe,iBAAA,GAAoB,SAAA,IAC3C,SAAA,EArCW;EAuCd,MAAA,WAAiB,gBAAA,CAAiB,CAAA,GAChC,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,SAAe,mBAAA;AAAA;;;;;AAnC5B;KA4CY,uBAAA,WACA,cAAA;EA7Cc,6FAiDb,cAAA,CAAe,CAAA,EAAG,MAAA,GAC3B,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,oBACR,eAAA,CAAgB,CAAA,KAAM,MAAA,IAAU,CAAA,KAnDlB;EAqDjB,GAAA,WAAc,cAAA,CAAe,CAAA,EAAG,MAAA,GAAS,GAAA,EAAK,CAAA,YApDtB;EAsDxB,GAAA,WAAc,cAAA,CAAe,CAAA,EAAG,MAAA,GAC9B,GAAA,EAAK,CAAA,GACJ,aAAA,CAAc,CAAA,KAAM,MAAA,IAAU,CAAA,KAxDH;EA0D9B,IAAA,WAAe,cAAA,CAAe,CAAA,EAAG,MAAA,GAC/B,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,SAAe,iBAAA,GAAoB,SAAA,IAC3C,SAAA,EA/DgC;EAiEnC,MAAA,WAAiB,cAAA,CAAe,CAAA,EAAG,MAAA,GACjC,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,SAAe,mBAAA;AAAA;;;;;;;KAUhB,6BAAA,qBACV,CAAA,SAAU,cAAA,GACN,iBAAA,CAAkB,CAAA,IAClB,CAAA,4BAA6B,cAAA,8BAC3B,uBAAA,CAAwB,CAAA,EAAG,MAAA,IAC3B,sBAAA;;KAGI,sBAAA;EAAA,CACT,GAAA,UAAa,MAAA,GAAS,MAAA;EACvB,GAAA,CAAI,GAAA;EACJ,GAAA,CAAI,GAAA;EACJ,IAAA,CACE,GAAA,UACA,MAAA,GAAS,MAAA,SAAe,iBAAA,GAAoB,SAAA,IAC3C,SAAA;EACH,MAAA,CACE,GAAA,UACA,MAAA,GAAS,MAAA,SAAe,mBAAA;AAAA"}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ScopedTranslateFunction, TranslateFunction } from "./shared/translateFunctionTypes.js";
|
|
2
|
+
import { DictionaryKeys } from "@intlayer/types/module_augmentation";
|
|
2
3
|
import { Dictionary } from "@intlayer/types/dictionary";
|
|
3
4
|
|
|
4
5
|
//#region src/useDictionary.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Overload set for {@link useDictionary}: without a prefix the translator is
|
|
8
|
+
* typed against the dictionary's dot-paths; with a prefix the keys are
|
|
9
|
+
* relative dot-paths under that scope.
|
|
10
|
+
*/
|
|
11
|
+
type UseDictionary = {
|
|
12
|
+
<T extends Dictionary>(dictionary: T): TranslateFunction<T['key'] & DictionaryKeys>;
|
|
13
|
+
<T extends Dictionary, Prefix extends string>(dictionary: T, namespacePrefix: Prefix): ScopedTranslateFunction<T['key'] & DictionaryKeys, Prefix>;
|
|
14
|
+
};
|
|
5
15
|
/**
|
|
6
16
|
* Dictionary-accepting variant of `useTranslations`.
|
|
7
17
|
*
|
|
@@ -10,14 +20,14 @@ import { Dictionary } from "@intlayer/types/dictionary";
|
|
|
10
20
|
* JSON at build time and passes it directly here. This enables tree-shaking of
|
|
11
21
|
* unused locale content.
|
|
12
22
|
*
|
|
23
|
+
* The returned translator matches `useTranslations` exactly (ICU messages,
|
|
24
|
+
* `has`, `raw`, `rich`, `markup`).
|
|
25
|
+
*
|
|
13
26
|
* @example (generated by the plugin, not written manually)
|
|
14
27
|
* import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
|
|
15
28
|
* const t = useDictionary(_abc);
|
|
16
29
|
*/
|
|
17
|
-
declare const useDictionary:
|
|
18
|
-
has: <P extends ValidDotPathsFor<string>>(lookup: P) => boolean;
|
|
19
|
-
raw: <P extends ValidDotPathsFor<string>>(lookup: P) => unknown;
|
|
20
|
-
};
|
|
30
|
+
declare const useDictionary: UseDictionary;
|
|
21
31
|
//#endregion
|
|
22
32
|
export { useDictionary };
|
|
23
33
|
//# sourceMappingURL=useDictionary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.d.ts","names":[],"sources":["../../src/useDictionary.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","names":[],"sources":["../../src/useDictionary.ts"],"mappings":";;;;;;;AAgByC;;;KAOpC,aAAA;EAAA,WACQ,UAAA,EACT,UAAA,EAAY,CAAA,GACX,iBAAA,CAAkB,CAAA,UAAW,cAAA;EAAA,WACrB,UAAA,yBACT,UAAA,EAAY,CAAA,EACZ,eAAA,EAAiB,MAAA,GAChB,uBAAA,CAAwB,CAAA,UAAW,cAAA,EAAgB,MAAA;AAAA;;;;;;;;;;;;;;;;cAkB3C,aAAA,EAYP,aAAA"}
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ScopedTranslateFunction, TranslateFunction } from "./shared/translateFunctionTypes.js";
|
|
2
|
+
import { DictionaryKeys, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
3
3
|
import { Dictionary } from "@intlayer/types/dictionary";
|
|
4
4
|
|
|
5
5
|
//#region src/useDictionaryDynamic.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Overload set for {@link useDictionaryDynamic}: without a prefix the
|
|
8
|
+
* translator is typed against the dictionary's dot-paths; with a prefix the
|
|
9
|
+
* keys are relative dot-paths under that scope.
|
|
10
|
+
*/
|
|
11
|
+
type UseDictionaryDynamic = {
|
|
12
|
+
<T extends Dictionary, K extends DictionaryKeys>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>, key: K): TranslateFunction<K>;
|
|
13
|
+
<T extends Dictionary, K extends DictionaryKeys, Prefix extends string>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>, key: K, namespacePrefix: Prefix): ScopedTranslateFunction<K, Prefix>;
|
|
14
|
+
};
|
|
6
15
|
/**
|
|
7
16
|
* Dynamic dictionary-accepting variant of `useTranslations`.
|
|
8
17
|
*
|
|
9
18
|
* Counterpart to {@link useDictionary} for dictionaries imported lazily per
|
|
10
19
|
* locale. Used internally by the build-time optimization.
|
|
11
20
|
*/
|
|
12
|
-
declare const useDictionaryDynamic:
|
|
13
|
-
has: <P extends ValidDotPathsFor<string>>(lookup: P) => boolean;
|
|
14
|
-
raw: <P extends ValidDotPathsFor<string>>(lookup: P) => unknown;
|
|
15
|
-
};
|
|
21
|
+
declare const useDictionaryDynamic: UseDictionaryDynamic;
|
|
16
22
|
//#endregion
|
|
17
23
|
export { useDictionaryDynamic };
|
|
18
24
|
//# sourceMappingURL=useDictionaryDynamic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.d.ts","names":[],"sources":["../../src/useDictionaryDynamic.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.d.ts","names":[],"sources":["../../src/useDictionaryDynamic.ts"],"mappings":";;;;;;;AAiByC;;;KAOpC,oBAAA;EAAA,WACQ,UAAA,YAAsB,cAAA,EAC/B,iBAAA,EAAmB,mBAAA,OAA0B,OAAA,CAAQ,CAAA,IACrD,GAAA,EAAK,CAAA,GACJ,iBAAA,CAAkB,CAAA;EAAA,WACV,UAAA,YAAsB,cAAA,yBAC/B,iBAAA,EAAmB,mBAAA,OAA0B,OAAA,CAAQ,CAAA,IACrD,GAAA,EAAK,CAAA,EACL,eAAA,EAAiB,MAAA,GAChB,uBAAA,CAAwB,CAAA,EAAG,MAAA;AAAA;;;;;;;cASnB,oBAAA,EAgBP,oBAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/use-intl",
|
|
3
|
-
"version": "9.0.0-canary.
|
|
3
|
+
"version": "9.0.0-canary.12",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "use-intl API adapter for intlayer — useTranslations, useLocale, useFormatter, IntlProvider, createTranslator backed by react-intlayer",
|
|
6
6
|
"keywords": [
|
|
@@ -89,13 +89,13 @@
|
|
|
89
89
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
-
"@intlayer/
|
|
93
|
-
"@intlayer/
|
|
94
|
-
"@intlayer/
|
|
95
|
-
"@intlayer/
|
|
96
|
-
"@intlayer/types": "9.0.0-canary.
|
|
97
|
-
"react-intlayer": "9.0.0-canary.
|
|
98
|
-
"vite-intlayer": "9.0.0-canary.
|
|
92
|
+
"@intlayer/config": "9.0.0-canary.12",
|
|
93
|
+
"@intlayer/core": "9.0.0-canary.12",
|
|
94
|
+
"@intlayer/dictionaries-entry": "9.0.0-canary.12",
|
|
95
|
+
"@intlayer/engine": "9.0.0-canary.12",
|
|
96
|
+
"@intlayer/types": "9.0.0-canary.12",
|
|
97
|
+
"react-intlayer": "9.0.0-canary.12",
|
|
98
|
+
"vite-intlayer": "9.0.0-canary.12"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@types/node": "25.9.4",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"tsdown": "0.21.10",
|
|
108
108
|
"typescript": "6.0.3",
|
|
109
109
|
"use-intl": "4.13.0",
|
|
110
|
-
"vite": "8.1.
|
|
110
|
+
"vite": "8.1.2",
|
|
111
111
|
"vitest": "4.1.9"
|
|
112
112
|
},
|
|
113
113
|
"peerDependencies": {
|