@intlayer/use-intl 9.0.0-canary.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +330 -0
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/client/IntlProvider.cjs +30 -0
- package/dist/cjs/client/IntlProvider.cjs.map +1 -0
- package/dist/cjs/client/helpers.cjs +49 -0
- package/dist/cjs/client/helpers.cjs.map +1 -0
- package/dist/cjs/client/index.cjs +27 -0
- package/dist/cjs/client/index.cjs.map +1 -0
- package/dist/cjs/client/useLocale.cjs +20 -0
- package/dist/cjs/client/useLocale.cjs.map +1 -0
- package/dist/cjs/client/useTranslations.cjs +39 -0
- package/dist/cjs/client/useTranslations.cjs.map +1 -0
- package/dist/cjs/core/createFormatter.cjs +23 -0
- package/dist/cjs/core/createFormatter.cjs.map +1 -0
- package/dist/cjs/core/createTranslator.cjs +30 -0
- package/dist/cjs/core/createTranslator.cjs.map +1 -0
- package/dist/cjs/core/errors.cjs +42 -0
- package/dist/cjs/core/errors.cjs.map +1 -0
- package/dist/cjs/core/hasLocale.cjs +23 -0
- package/dist/cjs/core/hasLocale.cjs.map +1 -0
- package/dist/cjs/core/index.cjs +13 -0
- package/dist/cjs/core/initializeConfig.cjs +25 -0
- package/dist/cjs/core/initializeConfig.cjs.map +1 -0
- package/dist/cjs/core/types.cjs +0 -0
- package/dist/cjs/index.cjs +30 -0
- package/dist/cjs/plugin/index.cjs +80 -0
- package/dist/cjs/plugin/index.cjs.map +1 -0
- package/dist/cjs/shared/intlFormatter.cjs +63 -0
- package/dist/cjs/shared/intlFormatter.cjs.map +1 -0
- package/dist/cjs/shared/namespaceTranslator.cjs +122 -0
- package/dist/cjs/shared/namespaceTranslator.cjs.map +1 -0
- package/dist/cjs/shared/translateFunctionTypes.cjs +0 -0
- package/dist/cjs/useDictionary.cjs +37 -0
- package/dist/cjs/useDictionary.cjs.map +1 -0
- package/dist/cjs/useDictionaryDynamic.cjs +31 -0
- package/dist/cjs/useDictionaryDynamic.cjs.map +1 -0
- package/dist/esm/client/IntlProvider.mjs +28 -0
- package/dist/esm/client/IntlProvider.mjs.map +1 -0
- package/dist/esm/client/helpers.mjs +44 -0
- package/dist/esm/client/helpers.mjs.map +1 -0
- package/dist/esm/client/index.mjs +17 -0
- package/dist/esm/client/index.mjs.map +1 -0
- package/dist/esm/client/useLocale.mjs +18 -0
- package/dist/esm/client/useLocale.mjs.map +1 -0
- package/dist/esm/client/useTranslations.mjs +37 -0
- package/dist/esm/client/useTranslations.mjs.map +1 -0
- package/dist/esm/core/createFormatter.mjs +22 -0
- package/dist/esm/core/createFormatter.mjs.map +1 -0
- package/dist/esm/core/createTranslator.mjs +28 -0
- package/dist/esm/core/createTranslator.mjs.map +1 -0
- package/dist/esm/core/errors.mjs +39 -0
- package/dist/esm/core/errors.mjs.map +1 -0
- package/dist/esm/core/hasLocale.mjs +21 -0
- package/dist/esm/core/hasLocale.mjs.map +1 -0
- package/dist/esm/core/index.mjs +7 -0
- package/dist/esm/core/initializeConfig.mjs +23 -0
- package/dist/esm/core/initializeConfig.mjs.map +1 -0
- package/dist/esm/core/types.mjs +0 -0
- package/dist/esm/index.mjs +14 -0
- package/dist/esm/plugin/index.mjs +76 -0
- package/dist/esm/plugin/index.mjs.map +1 -0
- package/dist/esm/shared/intlFormatter.mjs +61 -0
- package/dist/esm/shared/intlFormatter.mjs.map +1 -0
- package/dist/esm/shared/namespaceTranslator.mjs +129 -0
- package/dist/esm/shared/namespaceTranslator.mjs.map +1 -0
- package/dist/esm/shared/translateFunctionTypes.mjs +0 -0
- package/dist/esm/useDictionary.mjs +35 -0
- package/dist/esm/useDictionary.mjs.map +1 -0
- package/dist/esm/useDictionaryDynamic.mjs +29 -0
- package/dist/esm/useDictionaryDynamic.mjs.map +1 -0
- package/dist/types/client/IntlProvider.d.ts +29 -0
- package/dist/types/client/IntlProvider.d.ts.map +1 -0
- package/dist/types/client/helpers.d.ts +31 -0
- package/dist/types/client/helpers.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +16 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/client/useLocale.d.ts +12 -0
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/client/useTranslations.d.ts +44 -0
- package/dist/types/client/useTranslations.d.ts.map +1 -0
- package/dist/types/core/createFormatter.d.ts +21 -0
- package/dist/types/core/createFormatter.d.ts.map +1 -0
- package/dist/types/core/createTranslator.d.ts +56 -0
- package/dist/types/core/createTranslator.d.ts.map +1 -0
- package/dist/types/core/errors.d.ts +31 -0
- package/dist/types/core/errors.d.ts.map +1 -0
- package/dist/types/core/hasLocale.d.ts +18 -0
- package/dist/types/core/hasLocale.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +7 -0
- package/dist/types/core/initializeConfig.d.ts +14 -0
- package/dist/types/core/initializeConfig.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +2 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/plugin/index.d.ts +22 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/shared/intlFormatter.d.ts +19 -0
- package/dist/types/shared/intlFormatter.d.ts.map +1 -0
- package/dist/types/shared/namespaceTranslator.d.ts +51 -0
- package/dist/types/shared/namespaceTranslator.d.ts.map +1 -0
- package/dist/types/shared/translateFunctionTypes.d.ts +34 -0
- package/dist/types/shared/translateFunctionTypes.d.ts.map +1 -0
- package/dist/types/useDictionary.d.ts +23 -0
- package/dist/types/useDictionary.d.ts.map +1 -0
- package/dist/types/useDictionaryDynamic.d.ts +18 -0
- package/dist/types/useDictionaryDynamic.d.ts.map +1 -0
- package/package.json +127 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { getIntlayer } from "@intlayer/core/interpreter";
|
|
2
|
+
import { parseTaggedMessage, resolveMessage } from "@intlayer/core/messageFormat";
|
|
3
|
+
import { getDictionaries } from "@intlayer/dictionaries-entry";
|
|
4
|
+
import { Fragment } from "react";
|
|
5
|
+
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
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
|
+
/** Splits rich values into scalar interpolation values and tag renderers. */
|
|
30
|
+
const splitRichValues = (values = {}) => {
|
|
31
|
+
const scalarValues = {};
|
|
32
|
+
const renderers = {};
|
|
33
|
+
for (const [valueKey, value] of Object.entries(values)) if (typeof value === "function") renderers[valueKey] = value;
|
|
34
|
+
else scalarValues[valueKey] = value;
|
|
35
|
+
return {
|
|
36
|
+
scalarValues,
|
|
37
|
+
renderers
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const renderRichTokens = (tokens, renderers) => tokens.map((token, tokenIndex) => {
|
|
41
|
+
if (typeof token === "string") return token;
|
|
42
|
+
const children = renderRichTokens(token.children, renderers);
|
|
43
|
+
const renderer = renderers[token.tag];
|
|
44
|
+
if (typeof renderer === "function") return /* @__PURE__ */ jsx(Fragment, { children: renderer(children) }, tokenIndex);
|
|
45
|
+
return /* @__PURE__ */ jsx(Fragment, { children }, tokenIndex);
|
|
46
|
+
});
|
|
47
|
+
const renderMarkupTokens = (tokens, renderers) => tokens.map((token) => {
|
|
48
|
+
if (typeof token === "string") return token;
|
|
49
|
+
const children = renderMarkupTokens(token.children, renderers);
|
|
50
|
+
const renderer = renderers[token.tag];
|
|
51
|
+
if (typeof renderer === "function") return renderer(children);
|
|
52
|
+
return children;
|
|
53
|
+
}).join("");
|
|
54
|
+
/**
|
|
55
|
+
* The untyped runtime translator shared by `useTranslations` (React hook) and
|
|
56
|
+
* `createTranslator` (non-React core).
|
|
57
|
+
*
|
|
58
|
+
* Behaviour matches use-intl / next-intl:
|
|
59
|
+
* - namespace `'about'` → keys resolved inside the `about` dictionary
|
|
60
|
+
* - namespace `'about.counter'` → dictionary `about`, key prefix `counter`
|
|
61
|
+
* - no namespace → the first segment of each key is the dictionary key
|
|
62
|
+
* - messages support ICU syntax (plural, select, `#`, formatted arguments)
|
|
63
|
+
* - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided
|
|
64
|
+
* renderers; `t.raw` returns the raw value; `t.has` checks existence
|
|
65
|
+
*
|
|
66
|
+
* @param locale - The locale dictionaries are resolved for.
|
|
67
|
+
* @param namespace - Optional dictionary key, optionally with a nested scope.
|
|
68
|
+
* @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.
|
|
69
|
+
*/
|
|
70
|
+
const createNamespaceTranslator = (locale, namespace) => {
|
|
71
|
+
const [dictionaryKey, ...prefixSegments] = (namespace ?? "").split(".");
|
|
72
|
+
const keyPrefix = prefixSegments.join(".");
|
|
73
|
+
const lookup = (key) => {
|
|
74
|
+
let targetDictionaryKey = dictionaryKey;
|
|
75
|
+
let path = keyPrefix ? `${keyPrefix}.${key}` : key;
|
|
76
|
+
const dictionaries = getDictionaries();
|
|
77
|
+
if (!targetDictionaryKey) {
|
|
78
|
+
const [firstSegment, ...restSegments] = key.split(".");
|
|
79
|
+
targetDictionaryKey = firstSegment;
|
|
80
|
+
path = restSegments.join(".");
|
|
81
|
+
if (!dictionaries[targetDictionaryKey]) for (const dictKey of Object.keys(dictionaries)) try {
|
|
82
|
+
const result = navigatePath(getIntlayer(dictKey, locale), key);
|
|
83
|
+
if (result !== void 0) return result;
|
|
84
|
+
} catch {}
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
return navigatePath(getIntlayer(targetDictionaryKey, locale), path);
|
|
88
|
+
} catch {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const resolveToString = (key, values = {}) => {
|
|
93
|
+
const rawValue = lookup(key);
|
|
94
|
+
if (rawValue === null || rawValue === void 0) return void 0;
|
|
95
|
+
return resolveMessage(rawValue, values, locale, "icu");
|
|
96
|
+
};
|
|
97
|
+
const missingKeyFallback = (key) => namespace ? `${namespace}.${key}` : key;
|
|
98
|
+
const translate = (key, values) => resolveToString(key, values) ?? missingKeyFallback(key);
|
|
99
|
+
return Object.assign(translate, {
|
|
100
|
+
/** Returns `true` if the given key exists in the namespace. */
|
|
101
|
+
has: (key) => lookup(key) !== void 0,
|
|
102
|
+
/** Returns the raw unprocessed content for the given key. */
|
|
103
|
+
raw: (key) => lookup(key),
|
|
104
|
+
/**
|
|
105
|
+
* Resolves a message containing `<tag>chunks</tag>` markup, mapping each
|
|
106
|
+
* tag through the matching renderer in `values`.
|
|
107
|
+
*/
|
|
108
|
+
rich: (key, values) => {
|
|
109
|
+
const { scalarValues, renderers } = splitRichValues(values);
|
|
110
|
+
const message = resolveToString(key, scalarValues);
|
|
111
|
+
if (message === void 0) return missingKeyFallback(key);
|
|
112
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: renderRichTokens(parseTaggedMessage(message), renderers) });
|
|
113
|
+
},
|
|
114
|
+
/**
|
|
115
|
+
* Resolves a message containing `<tag>chunks</tag>` markup into a string,
|
|
116
|
+
* mapping each tag through the matching string renderer in `values`.
|
|
117
|
+
*/
|
|
118
|
+
markup: (key, values) => {
|
|
119
|
+
const { scalarValues, renderers } = splitRichValues(values);
|
|
120
|
+
const message = resolveToString(key, scalarValues);
|
|
121
|
+
if (message === void 0) return missingKeyFallback(key);
|
|
122
|
+
return renderMarkupTokens(parseTaggedMessage(message), renderers);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
export { createNamespaceTranslator, navigatePath };
|
|
129
|
+
//# sourceMappingURL=namespaceTranslator.mjs.map
|
|
@@ -0,0 +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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"}
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { navigatePath } from "./shared/namespaceTranslator.mjs";
|
|
4
|
+
import { useDictionary as useDictionary$1 } from "react-intlayer";
|
|
5
|
+
|
|
6
|
+
//#region src/useDictionary.ts
|
|
7
|
+
/**
|
|
8
|
+
* Dictionary-accepting variant of `useTranslations`.
|
|
9
|
+
*
|
|
10
|
+
* Used internally by the build-time optimization: instead of looking up the
|
|
11
|
+
* dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary
|
|
12
|
+
* JSON at build time and passes it directly here. This enables tree-shaking of
|
|
13
|
+
* unused locale content.
|
|
14
|
+
*
|
|
15
|
+
* @example (generated by the plugin, not written manually)
|
|
16
|
+
* import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
|
|
17
|
+
* const t = useDictionary(_abc);
|
|
18
|
+
*/
|
|
19
|
+
const useDictionary = (dictionary, namespacePrefix) => {
|
|
20
|
+
const content = useDictionary$1(dictionary);
|
|
21
|
+
const resolveKey = (key) => namespacePrefix ? `${namespacePrefix}.${key}` : key;
|
|
22
|
+
return Object.assign((lookup, params) => {
|
|
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
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { useDictionary };
|
|
35
|
+
//# sourceMappingURL=useDictionary.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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';\nimport { navigatePath } from './shared/namespaceTranslator';\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 * @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 content = useDictionaryBase(dictionary);\n\n const resolveKey = (key: string): string =>\n namespacePrefix ? `${namespacePrefix}.${key}` : key;\n\n return Object.assign(\n <P extends ValidDotPathsFor<string>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const text = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return text;\n return text.replace(/\\{(\\w+)\\}/g, (_match, key) =>\n params[key] != null ? String(params[key]) : `{${key}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<string>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<string>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,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,OAAO,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC3D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,KAAK,QAAQ,eAAe,QAAQ,QACzC,OAAO,QAAQ,OAAO,OAAO,OAAO,KAAK,GAAG,IAAI,IAAI,GACrD;IAEH;EACE,MAA0C,WACxC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAA0C,WACxC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { navigatePath } from "./shared/namespaceTranslator.mjs";
|
|
4
|
+
import { useDictionaryDynamic as useDictionaryDynamic$1 } from "react-intlayer";
|
|
5
|
+
|
|
6
|
+
//#region src/useDictionaryDynamic.ts
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic dictionary-accepting variant of `useTranslations`.
|
|
9
|
+
*
|
|
10
|
+
* Counterpart to {@link useDictionary} for dictionaries imported lazily per
|
|
11
|
+
* locale. Used internally by the build-time optimization.
|
|
12
|
+
*/
|
|
13
|
+
const useDictionaryDynamic = (dictionaryPromise, key, namespacePrefix) => {
|
|
14
|
+
const content = useDictionaryDynamic$1(dictionaryPromise, key);
|
|
15
|
+
const resolveKey = (lookupKey) => namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;
|
|
16
|
+
return Object.assign((lookup, params) => {
|
|
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
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { useDictionaryDynamic };
|
|
29
|
+
//# sourceMappingURL=useDictionaryDynamic.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":["useDictionaryDynamicBase"],"sources":["../../src/useDictionaryDynamic.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 as useDictionaryDynamicBase } from 'react-intlayer';\nimport { navigatePath } from './shared/namespaceTranslator';\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 string,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix?: string\n) => {\n const content = useDictionaryDynamicBase<T, K>(dictionaryPromise, key);\n\n const resolveKey = (lookupKey: string): string =>\n namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;\n\n return Object.assign(\n <P extends ValidDotPathsFor<string>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const text = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return text;\n return text.replace(/\\{(\\w+)\\}/g, (_match, key) =>\n params[key] != null ? String(params[key]) : `{${key}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<string>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<string>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,wBAIX,mBACA,KACA,oBACG;CACH,MAAM,UAAUA,uBAA+B,mBAAmB,IAAI;CAEtE,MAAM,cAAc,cAClB,kBAAkB,GAAG,gBAAgB,GAAG,cAAc;AAExD,QAAO,OAAO,QAEV,QACA,WACW;EACX,MAAM,WAAW,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EAClE,MAAM,OAAO,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC3D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,KAAK,QAAQ,eAAe,QAAQ,QACzC,OAAO,QAAQ,OAAO,OAAO,OAAO,KAAK,GAAG,IAAI,IAAI,GACrD;IAEH;EACE,MAA0C,WACxC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAA0C,WACxC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
import { IntlProvider as IntlProvider$1 } from "use-intl";
|
|
4
|
+
|
|
5
|
+
//#region src/client/IntlProvider.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Drop-in for use-intl's `IntlProvider`.
|
|
8
|
+
*
|
|
9
|
+
* Wraps Intlayer's `IntlayerProvider`, seeding the client locale from the
|
|
10
|
+
* `locale` prop. `messages`, `formats`, `now`, `timeZone`, `onError`, and
|
|
11
|
+
* `getMessageFallback` are accepted for API compatibility but have no effect —
|
|
12
|
+
* Intlayer uses its own compiled dictionaries.
|
|
13
|
+
*/
|
|
14
|
+
declare const IntlProvider: typeof IntlProvider$1;
|
|
15
|
+
/**
|
|
16
|
+
* Props accepted by {@link IntlProvider}. `messages` is deprecated — Intlayer
|
|
17
|
+
* loads content from compiled dictionaries automatically.
|
|
18
|
+
*/
|
|
19
|
+
type IntlProviderProps = Omit<ComponentProps<typeof IntlProvider$1>, 'messages' | 'locale'> & {
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated has no use case with intlayer. Messages are loaded
|
|
22
|
+
* automatically under the hood for bundle optimization reason.
|
|
23
|
+
*/
|
|
24
|
+
messages?: never; /** The active locale. */
|
|
25
|
+
locale: LocalesValues;
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { IntlProvider, IntlProviderProps };
|
|
29
|
+
//# sourceMappingURL=IntlProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlProvider.d.ts","names":[],"sources":["../../../src/client/IntlProvider.tsx"],"mappings":";;;;;;;AAkBA;;;;;AAiCA;cAjCa,YAAA,SAAqB,cAAA;;;;;KAiCtB,iBAAA,GAAoB,IAAA,CAC9B,cAAA,QAAsB,cAAA;EASD;;;;EAFrB,QAAA;EAEA,MAAA,EAAQ,aAAA;AAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useFormatter as useFormatter$1, useMessages as useMessages$1, useNow as useNow$1, useTimeZone as useTimeZone$1 } from "use-intl";
|
|
2
|
+
|
|
3
|
+
//#region src/client/helpers.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Drop-in for use-intl's `useNow`.
|
|
6
|
+
* Returns the current `Date`. The `updateInterval` option is ignored.
|
|
7
|
+
*/
|
|
8
|
+
declare const useNow: typeof useNow$1;
|
|
9
|
+
/**
|
|
10
|
+
* Drop-in for use-intl's `useTimeZone`.
|
|
11
|
+
* Returns the system time zone resolved from `Intl.DateTimeFormat`.
|
|
12
|
+
*/
|
|
13
|
+
declare const useTimeZone: typeof useTimeZone$1;
|
|
14
|
+
/**
|
|
15
|
+
* Drop-in for use-intl's `useMessages`.
|
|
16
|
+
*
|
|
17
|
+
* @deprecated useMessages has no use case with intlayer.
|
|
18
|
+
* Messages are loaded automatically under the hood.
|
|
19
|
+
* @returns An empty object.
|
|
20
|
+
*/
|
|
21
|
+
declare const useMessages: typeof useMessages$1;
|
|
22
|
+
/**
|
|
23
|
+
* Drop-in for use-intl's `useFormatter`.
|
|
24
|
+
* Returns locale-aware formatters backed by the native `Intl.*` APIs:
|
|
25
|
+
* `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and
|
|
26
|
+
* `displayName`.
|
|
27
|
+
*/
|
|
28
|
+
declare const useFormatter: typeof useFormatter$1;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { useFormatter, useMessages, useNow, useTimeZone };
|
|
31
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","names":[],"sources":["../../../src/client/helpers.ts"],"mappings":";;;;;AAkBA;;cAAa,MAAA,SAAe,QAAA;;;AAM5B;;cAAa,WAAA,SAAoB,aAAA;;;AAUjC;;;;;cAAa,WAAA,SAAoB,aAAA;;;;;;;cAiBpB,YAAA,SAAqB,cAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IntlProvider, IntlProviderProps } from "./IntlProvider.js";
|
|
2
|
+
import { useFormatter, useMessages, useNow, useTimeZone } from "./helpers.js";
|
|
3
|
+
import { useDictionary } from "../useDictionary.js";
|
|
4
|
+
import { useDictionaryDynamic } from "../useDictionaryDynamic.js";
|
|
5
|
+
import { useLocale } from "./useLocale.js";
|
|
6
|
+
import { useTranslations } from "./useTranslations.js";
|
|
7
|
+
|
|
8
|
+
//#region src/client/index.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* @internal Private use-intl export, kept so aliased `_useExtracted` imports
|
|
11
|
+
* resolve. Not part of the supported public surface.
|
|
12
|
+
*/
|
|
13
|
+
declare const _useExtracted: () => Record<string, never>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { IntlProvider, type IntlProviderProps, _useExtracted, useDictionary, useDictionaryDynamic, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/client/index.ts"],"mappings":";;;;;;;;;;AAWA;;cAAa,aAAA,QAAoB,MAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useLocale as useLocale$1 } from "use-intl";
|
|
2
|
+
|
|
3
|
+
//#region src/client/useLocale.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Drop-in for use-intl's `useLocale`.
|
|
6
|
+
*
|
|
7
|
+
* Returns the active locale string from Intlayer's client context.
|
|
8
|
+
*/
|
|
9
|
+
declare const useLocale: typeof useLocale$1;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { useLocale };
|
|
12
|
+
//# sourceMappingURL=useLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;;;;AAUA;;;cAAa,SAAA,SAAkB,WAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { LooseTranslateFunction, TranslateFunction } from "../shared/translateFunctionTypes.js";
|
|
2
|
+
import { DictionaryKeys } from "@intlayer/types/module_augmentation";
|
|
3
|
+
|
|
4
|
+
//#region src/client/useTranslations.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Overload set for {@link useTranslations}:
|
|
7
|
+
*
|
|
8
|
+
* 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).
|
|
9
|
+
* 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative
|
|
10
|
+
* `string` paths, matching use-intl's scoped-namespace behaviour.
|
|
11
|
+
* 3. No namespace → root scope; the first segment of each key designates
|
|
12
|
+
* the dictionary (`t('about.title')`).
|
|
13
|
+
*/
|
|
14
|
+
type UseTranslations = {
|
|
15
|
+
<N extends DictionaryKeys>(namespace: N): TranslateFunction<N>;
|
|
16
|
+
(namespace: `${string}.${string}`): LooseTranslateFunction;
|
|
17
|
+
(): LooseTranslateFunction;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Drop-in for use-intl's `useTranslations`.
|
|
21
|
+
*
|
|
22
|
+
* Messages support ICU MessageFormat syntax: simple arguments (`{name}`),
|
|
23
|
+
* plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted
|
|
24
|
+
* arguments (`{value, number}`). Rich text is available through `t.rich()`
|
|
25
|
+
* and `t.markup()`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* const t = useTranslations('about');
|
|
30
|
+
* t('counter.label'); // ✓ typed
|
|
31
|
+
* t('items', { count: 3 }); // ICU plural
|
|
32
|
+
*
|
|
33
|
+
* // Scoped to a nested object (use-intl idiom)
|
|
34
|
+
* const t = useTranslations('about.counter');
|
|
35
|
+
* t('label'); // resolves about → counter.label
|
|
36
|
+
*
|
|
37
|
+
* // Rich text
|
|
38
|
+
* t.rich('terms', { link: (chunks) => <a href="/terms">{chunks}</a> });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare const useTranslations: UseTranslations;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { useTranslations };
|
|
44
|
+
//# sourceMappingURL=useTranslations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTranslations.d.ts","names":[],"sources":["../../../src/client/useTranslations.ts"],"mappings":";;;;;;AAY0C;;;;;;;KAWrC,eAAA;EAAA,WACQ,cAAA,EAAgB,SAAA,EAAW,CAAA,GAAI,iBAAA,CAAkB,CAAA;EAAA,CAC3D,SAAA,0BAAmC,sBAAA;EAAA,IAChC,sBAAA;AAAA;;;;;;;;;;;AAyBN;;;;;;;;;;;;cAAa,eAAA,EAOP,eAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createFormatter as createFormatter$1 } from "use-intl";
|
|
2
|
+
|
|
3
|
+
//#region src/core/createFormatter.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Drop-in for use-intl's `createFormatter`.
|
|
6
|
+
*
|
|
7
|
+
* Returns locale-aware formatters backed by the native `Intl.*` APIs:
|
|
8
|
+
* `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and
|
|
9
|
+
* `displayName`. `now`, `timeZone`, `formats`, and `onError` are accepted for
|
|
10
|
+
* API compatibility but only `locale` influences the output.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const format = createFormatter({ locale: 'en' });
|
|
15
|
+
* format.number(1234.5, { style: 'currency', currency: 'USD' });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare const createFormatter: typeof createFormatter$1;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { createFormatter };
|
|
21
|
+
//# sourceMappingURL=createFormatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFormatter.d.ts","names":[],"sources":["../../../src/core/createFormatter.ts"],"mappings":";;;;;AAiBA;;;;;;;;;;;;cAAa,eAAA,SAAwB,iBAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { LooseTranslateFunction, TranslateFunction } from "../shared/translateFunctionTypes.js";
|
|
2
|
+
import { DictionaryKeys, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
|
+
|
|
4
|
+
//#region src/core/createTranslator.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Configuration accepted by {@link createTranslator}.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors use-intl's `IntlConfig`, but `messages`, `formats`, `now`,
|
|
9
|
+
* `timeZone`, `onError`, and `getMessageFallback` have no effect — Intlayer
|
|
10
|
+
* resolves content from its own compiled dictionaries.
|
|
11
|
+
*/
|
|
12
|
+
type CreateTranslatorConfig<N extends DictionaryKeys> = {
|
|
13
|
+
/** The locale dictionaries are resolved for. */locale: LocalesValues; /** A bare dictionary key, or a nested `'dictionary.scope'` namespace. */
|
|
14
|
+
namespace?: N | (string & {});
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated has no use case with intlayer. Messages are loaded
|
|
17
|
+
* automatically under the hood for bundle optimization reason.
|
|
18
|
+
*/
|
|
19
|
+
messages?: never;
|
|
20
|
+
} & Record<string, unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* Overload set for {@link createTranslator}:
|
|
23
|
+
*
|
|
24
|
+
* 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).
|
|
25
|
+
* 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative
|
|
26
|
+
* `string` paths, matching use-intl's scoped-namespace behaviour.
|
|
27
|
+
* 3. No namespace → root scope; the first segment of each key designates
|
|
28
|
+
* the dictionary (`t('about.title')`).
|
|
29
|
+
*/
|
|
30
|
+
type CreateTranslator = {
|
|
31
|
+
<N extends DictionaryKeys>(config: CreateTranslatorConfig<N> & {
|
|
32
|
+
namespace: N;
|
|
33
|
+
}): TranslateFunction<N>;
|
|
34
|
+
(config: CreateTranslatorConfig<DictionaryKeys> & {
|
|
35
|
+
namespace: `${string}.${string}`;
|
|
36
|
+
}): LooseTranslateFunction;
|
|
37
|
+
(config: CreateTranslatorConfig<DictionaryKeys>): LooseTranslateFunction;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Drop-in for use-intl's `createTranslator`.
|
|
41
|
+
*
|
|
42
|
+
* Returns a translate function (with `rich`, `markup`, `raw`, `has`) that
|
|
43
|
+
* resolves messages from Intlayer's compiled dictionaries for the given
|
|
44
|
+
* `locale`. Messages support ICU MessageFormat syntax.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const t = createTranslator({ locale: 'en', namespace: 'about' });
|
|
49
|
+
* t('counter.label'); // ✓ typed
|
|
50
|
+
* t('items', { count: 3 }); // ICU plural
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare const createTranslator: CreateTranslator;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { CreateTranslatorConfig, createTranslator };
|
|
56
|
+
//# sourceMappingURL=createTranslator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTranslator.d.ts","names":[],"sources":["../../../src/core/createTranslator.ts"],"mappings":";;;;;;AAoBA;;;;;KAAY,sBAAA,WAAiC,cAAA;EAUzC,gDARF,MAAA,EAAQ,aAAA,EAQA;EANR,SAAA,GAAY,CAAA;EAJ+B;;;;EAS3C,QAAA;AAAA,IACE,MAAA;;;;AAAwB;;;;;;KAWvB,gBAAA;EAAA,WACQ,cAAA,EACT,MAAA,EAAQ,sBAAA,CAAuB,CAAA;IAAO,SAAA,EAAW,CAAA;EAAA,IAChD,iBAAA,CAAkB,CAAA;EAAA,CAEnB,MAAA,EAAQ,sBAAA,CAAuB,cAAA;IAC7B,SAAA;EAAA,IAED,sBAAA;EAAA,CACF,MAAA,EAAQ,sBAAA,CAAuB,cAAA,IAAkB,sBAAA;AAAA;;;;;;;;;;;;;;;cAiBvC,gBAAA,EAaP,gBAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/core/errors.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Drop-in for use-intl's `IntlErrorCode` enum.
|
|
4
|
+
*
|
|
5
|
+
* Re-implemented locally (rather than re-exported) because `use-intl` is
|
|
6
|
+
* aliased to this package at build time, so importing its runtime value would
|
|
7
|
+
* be circular.
|
|
8
|
+
*/
|
|
9
|
+
declare enum IntlErrorCode {
|
|
10
|
+
MISSING_MESSAGE = "MISSING_MESSAGE",
|
|
11
|
+
MISSING_FORMAT = "MISSING_FORMAT",
|
|
12
|
+
ENVIRONMENT_FALLBACK = "ENVIRONMENT_FALLBACK",
|
|
13
|
+
INSUFFICIENT_PATH = "INSUFFICIENT_PATH",
|
|
14
|
+
INVALID_MESSAGE = "INVALID_MESSAGE",
|
|
15
|
+
INVALID_KEY = "INVALID_KEY",
|
|
16
|
+
FORMATTING_ERROR = "FORMATTING_ERROR"
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Drop-in for use-intl's `IntlError`.
|
|
20
|
+
*
|
|
21
|
+
* Carries the {@link IntlErrorCode} and the original message, matching
|
|
22
|
+
* use-intl's error shape so consumer `onError` handlers keep working.
|
|
23
|
+
*/
|
|
24
|
+
declare class IntlError extends Error {
|
|
25
|
+
readonly code: IntlErrorCode;
|
|
26
|
+
readonly originalMessage: string | undefined;
|
|
27
|
+
constructor(code: IntlErrorCode, originalMessage?: string);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { IntlError, IntlErrorCode };
|
|
31
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":[],"sources":["../../../src/core/errors.ts"],"mappings":";;AAOA;;;;;;aAAY,aAAA;EACV,eAAA;EACA,cAAA;EACA,oBAAA;EACA,iBAAA;EACA,eAAA;EACA,WAAA;EACA,gBAAA;AAAA;;;;;;;cASW,SAAA,SAAkB,KAAA;EAAA,SACb,IAAA,EAAM,aAAA;EAAA,SACN,eAAA;cAEJ,IAAA,EAAM,aAAA,EAAe,eAAA;AAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { hasLocale as hasLocale$1 } from "use-intl";
|
|
2
|
+
|
|
3
|
+
//#region src/core/hasLocale.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Drop-in for use-intl's `hasLocale`.
|
|
6
|
+
*
|
|
7
|
+
* Narrows a locale candidate to the given locales list. When the list is
|
|
8
|
+
* omitted, the locales configured in intlayer are used.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* if (hasLocale(['en', 'fr'], requested)) { … }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
declare const hasLocale: typeof hasLocale$1;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { hasLocale };
|
|
18
|
+
//# sourceMappingURL=hasLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasLocale.d.ts","names":[],"sources":["../../../src/core/hasLocale.ts"],"mappings":";;;;;AAcA;;;;;;;;;cAAa,SAAA,SAAkB,WAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createFormatter } from "./createFormatter.js";
|
|
2
|
+
import { CreateTranslatorConfig, createTranslator } from "./createTranslator.js";
|
|
3
|
+
import { IntlError, IntlErrorCode } from "./errors.js";
|
|
4
|
+
import { hasLocale } from "./hasLocale.js";
|
|
5
|
+
import { initializeConfig } from "./initializeConfig.js";
|
|
6
|
+
import { AbstractIntlMessages, AppConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, Locale, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, RichTagsFunction, RichTranslationValues, Timezone, TranslationValues } from "./types.js";
|
|
7
|
+
export { AbstractIntlMessages, AppConfig, type CreateTranslatorConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, IntlError, IntlErrorCode, Locale, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, RichTagsFunction, RichTranslationValues, Timezone, TranslationValues, createFormatter, createTranslator, hasLocale, initializeConfig };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { initializeConfig as initializeConfig$1 } from "use-intl";
|
|
2
|
+
|
|
3
|
+
//#region src/core/initializeConfig.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Drop-in for use-intl's `initializeConfig`.
|
|
6
|
+
*
|
|
7
|
+
* Enhances an incoming config with defaults. With intlayer, `messages` and
|
|
8
|
+
* `formats` are not consumed at runtime (content comes from compiled
|
|
9
|
+
* dictionaries) but the shape is preserved so callers keep type-checking.
|
|
10
|
+
*/
|
|
11
|
+
declare const initializeConfig: typeof initializeConfig$1;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { initializeConfig };
|
|
14
|
+
//# sourceMappingURL=initializeConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializeConfig.d.ts","names":[],"sources":["../../../src/core/initializeConfig.ts"],"mappings":";;;;;AASA;;;;;cAAa,gBAAA,SAAyB,kBAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AbstractIntlMessages, AppConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, Locale, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, RichTagsFunction, RichTranslationValues, Timezone, TranslationValues } from "use-intl";
|
|
2
|
+
export { type AbstractIntlMessages, type AppConfig, type DateTimeFormatOptions, type Formats, type ICUArgs, type ICUTags, type IntlConfig, type Locale, type MarkupTagsFunction, type MarkupTranslationValues, type MessageKeys, type Messages, type NamespaceKeys, type NestedKeyOf, type NestedValueOf, type NumberFormatOptions, type RelativeTimeFormatOptions, type RichTagsFunction, type RichTranslationValues, type Timezone, type TranslationValues };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IntlProvider, IntlProviderProps } from "./client/IntlProvider.js";
|
|
2
|
+
import { useFormatter, useMessages, useNow, useTimeZone } from "./client/helpers.js";
|
|
3
|
+
import { useDictionary } from "./useDictionary.js";
|
|
4
|
+
import { useDictionaryDynamic } from "./useDictionaryDynamic.js";
|
|
5
|
+
import { useLocale } from "./client/useLocale.js";
|
|
6
|
+
import { MarkupChunkRenderer, RichChunkRenderer } from "./shared/namespaceTranslator.js";
|
|
7
|
+
import { LooseTranslateFunction, TranslateFunction } from "./shared/translateFunctionTypes.js";
|
|
8
|
+
import { useTranslations } from "./client/useTranslations.js";
|
|
9
|
+
import { _useExtracted } from "./client/index.js";
|
|
10
|
+
import { createFormatter } from "./core/createFormatter.js";
|
|
11
|
+
import { CreateTranslatorConfig, createTranslator } from "./core/createTranslator.js";
|
|
12
|
+
import { IntlError, IntlErrorCode } from "./core/errors.js";
|
|
13
|
+
import { hasLocale } from "./core/hasLocale.js";
|
|
14
|
+
import { initializeConfig } from "./core/initializeConfig.js";
|
|
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 };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PluginOption } from "vite";
|
|
2
|
+
import { intlayer } from "vite-intlayer";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A Vite plugin for use-intl compat that wraps vite-intlayer and configures
|
|
7
|
+
* resolve aliases so `use-intl` imports are served by `@intlayer/use-intl`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // vite.config.ts
|
|
12
|
+
* import useIntlVitePlugin from '@intlayer/use-intl/plugin';
|
|
13
|
+
*
|
|
14
|
+
* export default defineConfig({
|
|
15
|
+
* plugins: [useIntlVitePlugin()],
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare const useIntlVitePlugin: (options?: Parameters<typeof intlayer>[0]) => PluginOption[];
|
|
20
|
+
//#endregion
|
|
21
|
+
export { useIntlVitePlugin as default, useIntlVitePlugin };
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":";;;;;;AA6CA;;;;;;;;;;;;cAAa,iBAAA,GACX,OAAA,GAAU,UAAA,QAAkB,QAAA,SAC3B,YAAA"}
|