@intlayer/react-i18next 9.9.3 → 9.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/I18nextProvider.mjs +2 -2
- package/dist/esm/IcuTrans.mjs +138 -0
- package/dist/esm/IcuTrans.mjs.map +1 -0
- package/dist/esm/IcuTransWithoutContext.mjs +5 -0
- package/dist/esm/Trans.mjs +6 -6
- package/dist/esm/Trans.mjs.map +1 -1
- package/dist/esm/TransWithoutContext.mjs +6 -0
- package/dist/esm/augment-react.mjs +0 -0
- package/dist/esm/createTranslationApi.mjs +16 -7
- package/dist/esm/createTranslationApi.mjs.map +1 -1
- package/dist/esm/helpers.mjs +1 -1
- package/dist/esm/htmlEntities.mjs +217 -0
- package/dist/esm/htmlEntities.mjs.map +1 -0
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/useDictionary.mjs +1 -1
- package/dist/esm/useDictionaryDynamic.mjs +1 -1
- package/dist/esm/useTranslation.mjs +1 -1
- package/dist/types/IcuTrans.d.ts +23 -0
- package/dist/types/IcuTrans.d.ts.map +1 -0
- package/dist/types/IcuTransWithoutContext.d.ts +3 -0
- package/dist/types/Trans.d.ts +1 -1
- package/dist/types/TransWithoutContext.d.ts +4 -0
- package/dist/types/augment-react.d.ts +9 -0
- package/dist/types/augment-react.d.ts.map +1 -0
- package/dist/types/createTranslationApi.d.ts +4 -3
- package/dist/types/createTranslationApi.d.ts.map +1 -1
- package/dist/types/htmlEntities.d.ts +6 -0
- package/dist/types/htmlEntities.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/useDictionary.d.ts +2 -2
- package/dist/types/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/useTranslation.d.ts +2 -2
- package/package.json +41 -9
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { IntlayerProvider } from "react-intlayer";
|
|
4
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
3
|
import { log } from "@intlayer/config/built";
|
|
6
4
|
import { CYAN } from "@intlayer/config/colors";
|
|
7
5
|
import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
6
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
|
|
9
9
|
// src/I18nextProvider.tsx
|
|
10
10
|
/**
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { getI18n } from "./globalI18n.mjs";
|
|
4
|
+
import { HTML_ENTITIES } from "./htmlEntities.mjs";
|
|
5
|
+
import { useTranslationLoose } from "./useTranslation.mjs";
|
|
6
|
+
import { Fragment, createElement } from "react";
|
|
7
|
+
|
|
8
|
+
// src/IcuTrans.tsx
|
|
9
|
+
const ENTITY_PATTERN = /&(?:#(\d+)|#x([0-9a-fA-F]+)|[A-Za-z][A-Za-z0-9]*);/g;
|
|
10
|
+
/** The character of a code point, or the entity itself when out of range. */
|
|
11
|
+
const decodeCodePoint = (entity, codePoint) => codePoint <= 1114111 ? String.fromCodePoint(codePoint) : entity;
|
|
12
|
+
/** Decodes numeric (`'`, `/`) and named (`&`) HTML entities. */
|
|
13
|
+
const decodeHtmlEntities = (text) => text.replace(ENTITY_PATTERN, (entity, decimal, hexadecimal) => {
|
|
14
|
+
if (decimal) return decodeCodePoint(entity, Number.parseInt(decimal, 10));
|
|
15
|
+
if (hexadecimal) return decodeCodePoint(entity, Number.parseInt(hexadecimal, 16));
|
|
16
|
+
const name = entity.slice(1, -1);
|
|
17
|
+
return Object.hasOwn(HTML_ENTITIES, name) ? HTML_ENTITIES[name] : entity;
|
|
18
|
+
});
|
|
19
|
+
/** Creates the element of a closed tag from its declaration. */
|
|
20
|
+
const renderDeclaration = ({ type, props = {} }, children) => {
|
|
21
|
+
if (Array.isArray(props.children)) {
|
|
22
|
+
const { children: _nestedDeclarations, ...ownProps } = props;
|
|
23
|
+
return createElement(type, ownProps, ...children);
|
|
24
|
+
}
|
|
25
|
+
return createElement(type, props, ...children);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Renders a translation, mapping each numbered tag `<n>…</n>` to
|
|
29
|
+
* `declarations[n]`; a declaration whose `props.children` is an array
|
|
30
|
+
* declares the tags nested in it. Only exact `<n>` / `</n>` tags are read, a
|
|
31
|
+
* tag without declaration stays literal text.
|
|
32
|
+
*
|
|
33
|
+
* @throws On an unexpected, mismatched or unclosed tag.
|
|
34
|
+
*/
|
|
35
|
+
const renderTranslation = (translation, declarations) => {
|
|
36
|
+
const result = [];
|
|
37
|
+
const openTags = [];
|
|
38
|
+
const literalTagNumbers = /* @__PURE__ */ new Set();
|
|
39
|
+
let text = "";
|
|
40
|
+
const getTarget = () => openTags.at(-1)?.children ?? result;
|
|
41
|
+
const flushText = () => {
|
|
42
|
+
if (text) getTarget().push(decodeHtmlEntities(text));
|
|
43
|
+
text = "";
|
|
44
|
+
};
|
|
45
|
+
const getCurrentDeclarations = () => {
|
|
46
|
+
const parent = openTags.at(-1);
|
|
47
|
+
if (!parent) return declarations;
|
|
48
|
+
const nested = parent.declaration.props?.children;
|
|
49
|
+
return Array.isArray(nested) ? nested : parent.declarations;
|
|
50
|
+
};
|
|
51
|
+
let position = 0;
|
|
52
|
+
while (position < translation.length) {
|
|
53
|
+
const rest = translation.slice(position);
|
|
54
|
+
const tag = translation[position] === "<" && rest.match(/^<(\/?)(\d+)>/);
|
|
55
|
+
if (!tag) {
|
|
56
|
+
text += translation[position];
|
|
57
|
+
position += 1;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
flushText();
|
|
61
|
+
position += tag[0].length;
|
|
62
|
+
const tagNumber = Number.parseInt(tag[2], 10);
|
|
63
|
+
if (!tag[1]) {
|
|
64
|
+
const currentDeclarations = getCurrentDeclarations();
|
|
65
|
+
const declaration = currentDeclarations[tagNumber];
|
|
66
|
+
if (!declaration) {
|
|
67
|
+
literalTagNumbers.add(tagNumber);
|
|
68
|
+
getTarget().push(`<${tagNumber}>`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
openTags.push({
|
|
72
|
+
tagNumber,
|
|
73
|
+
children: [],
|
|
74
|
+
declaration,
|
|
75
|
+
declarations: currentDeclarations
|
|
76
|
+
});
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (literalTagNumbers.has(tagNumber)) {
|
|
80
|
+
literalTagNumbers.delete(tagNumber);
|
|
81
|
+
getTarget().push(`</${tagNumber}>`);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const openTag = openTags.pop();
|
|
85
|
+
if (!openTag || openTag.tagNumber !== tagNumber) throw new Error(`Unexpected closing tag </${tagNumber}>`);
|
|
86
|
+
getTarget().push(renderDeclaration(openTag.declaration, openTag.children));
|
|
87
|
+
}
|
|
88
|
+
flushText();
|
|
89
|
+
if (openTags.length > 0) throw new Error(`Unclosed tag <${openTags.at(-1).tagNumber}>`);
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Drop-in for react-i18next's `IcuTransWithoutContext`: translates
|
|
94
|
+
* `i18nKey` (falling back to `defaultTranslation`) with `values`, then maps
|
|
95
|
+
* its numbered tags (`<0>…</0>`) to the `content` declarations.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* <IcuTransWithoutContext
|
|
100
|
+
* i18nKey="welcome"
|
|
101
|
+
* defaultTranslation="Hello <0>{name}</0>"
|
|
102
|
+
* content={[{ type: 'strong' }]}
|
|
103
|
+
* values={{ name: 'Ann' }}
|
|
104
|
+
* />
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
const IcuTransWithoutContext = ({ i18nKey, defaultTranslation, content, ns, values = {}, i18n: i18nFromProps, t: tFromProps }) => {
|
|
108
|
+
const i18n = i18nFromProps ?? getI18n();
|
|
109
|
+
const translate = tFromProps ?? i18n?.t?.bind(i18n) ?? ((key) => key);
|
|
110
|
+
const namespaces = ns ?? i18n?.options?.defaultNS ?? "translation";
|
|
111
|
+
const translation = String(translate(i18nKey || defaultTranslation, {
|
|
112
|
+
defaultValue: defaultTranslation,
|
|
113
|
+
...i18n?.options?.interpolation?.defaultVariables,
|
|
114
|
+
...values,
|
|
115
|
+
interpolation: { escapeValue: true },
|
|
116
|
+
ns: namespaces
|
|
117
|
+
}));
|
|
118
|
+
try {
|
|
119
|
+
return createElement(Fragment, null, ...renderTranslation(translation, content ?? []));
|
|
120
|
+
} catch {
|
|
121
|
+
return createElement(Fragment, null, translation);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Drop-in for react-i18next's `IcuTrans`: `IcuTransWithoutContext` with the
|
|
126
|
+
* translation function of the current locale.
|
|
127
|
+
*/
|
|
128
|
+
const IcuTrans = (props) => {
|
|
129
|
+
const namespace = Array.isArray(props.ns) ? props.ns[0] : props.ns;
|
|
130
|
+
const { t } = useTranslationLoose(namespace);
|
|
131
|
+
return createElement(IcuTransWithoutContext, {
|
|
132
|
+
...props,
|
|
133
|
+
t: props.t ?? t
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export { IcuTrans, IcuTransWithoutContext };
|
|
138
|
+
//# sourceMappingURL=IcuTrans.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IcuTrans.mjs","names":[],"sources":["../../src/IcuTrans.tsx"],"sourcesContent":["'use client';\n\nimport type { TOptions } from 'i18next';\nimport {\n type ComponentType,\n createElement,\n Fragment,\n type ReactNode,\n} from 'react';\nimport type {\n IcuTrans as UpstreamIcuTrans,\n IcuTransWithoutContext as UpstreamIcuTransWithoutContext,\n} from 'react-i18next';\nimport { getI18n } from './globalI18n';\nimport { HTML_ENTITIES } from './htmlEntities';\nimport { useTranslationLoose } from './useTranslation';\n\n/** One `content` entry: the element a numbered tag `<n>` renders. */\ntype ContentDeclaration = {\n type: string | ComponentType<Record<string, unknown>>;\n props?: { children?: unknown; [prop: string]: unknown };\n};\n\ntype IcuTransProps = Parameters<typeof UpstreamIcuTransWithoutContext>[0];\n\n/** An open numbered tag being filled while the translation is read. */\ntype OpenTag = {\n tagNumber: number;\n children: ReactNode[];\n declaration: ContentDeclaration;\n declarations: readonly ContentDeclaration[];\n};\n\nconst ENTITY_PATTERN = /&(?:#(\\d+)|#x([0-9a-fA-F]+)|[A-Za-z][A-Za-z0-9]*);/g;\n\n/** The character of a code point, or the entity itself when out of range. */\nconst decodeCodePoint = (entity: string, codePoint: number): string =>\n codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : entity;\n\n/** Decodes numeric (`'`, `/`) and named (`&`) HTML entities. */\nconst decodeHtmlEntities = (text: string): string =>\n text.replace(\n ENTITY_PATTERN,\n (entity, decimal: string | undefined, hexadecimal: string | undefined) => {\n if (decimal) return decodeCodePoint(entity, Number.parseInt(decimal, 10));\n if (hexadecimal) {\n return decodeCodePoint(entity, Number.parseInt(hexadecimal, 16));\n }\n const name = entity.slice(1, -1);\n return Object.hasOwn(HTML_ENTITIES, name) ? HTML_ENTITIES[name]! : entity;\n }\n );\n\n/** Creates the element of a closed tag from its declaration. */\nconst renderDeclaration = (\n { type, props = {} }: ContentDeclaration,\n children: ReactNode[]\n): ReactNode => {\n if (Array.isArray(props.children)) {\n const { children: _nestedDeclarations, ...ownProps } = props;\n return createElement(type, ownProps, ...children);\n }\n return createElement(type, props, ...children);\n};\n\n/**\n * Renders a translation, mapping each numbered tag `<n>…</n>` to\n * `declarations[n]`; a declaration whose `props.children` is an array\n * declares the tags nested in it. Only exact `<n>` / `</n>` tags are read, a\n * tag without declaration stays literal text.\n *\n * @throws On an unexpected, mismatched or unclosed tag.\n */\nconst renderTranslation = (\n translation: string,\n declarations: readonly ContentDeclaration[]\n): ReactNode[] => {\n const result: ReactNode[] = [];\n const openTags: OpenTag[] = [];\n const literalTagNumbers = new Set<number>();\n let text = '';\n\n const getTarget = (): ReactNode[] => openTags.at(-1)?.children ?? result;\n\n const flushText = () => {\n if (text) getTarget().push(decodeHtmlEntities(text));\n text = '';\n };\n\n const getCurrentDeclarations = (): readonly ContentDeclaration[] => {\n const parent = openTags.at(-1);\n if (!parent) return declarations;\n\n const nested = parent.declaration.props?.children;\n return Array.isArray(nested)\n ? (nested as ContentDeclaration[])\n : parent.declarations;\n };\n\n let position = 0;\n while (position < translation.length) {\n const rest = translation.slice(position);\n const tag = translation[position] === '<' && rest.match(/^<(\\/?)(\\d+)>/);\n\n if (!tag) {\n text += translation[position];\n position += 1;\n continue;\n }\n\n flushText();\n position += tag[0].length;\n const tagNumber = Number.parseInt(tag[2]!, 10);\n\n if (!tag[1]) {\n const currentDeclarations = getCurrentDeclarations();\n const declaration = currentDeclarations[tagNumber];\n\n if (!declaration) {\n literalTagNumbers.add(tagNumber);\n getTarget().push(`<${tagNumber}>`);\n continue;\n }\n\n openTags.push({\n tagNumber,\n children: [],\n declaration,\n declarations: currentDeclarations,\n });\n continue;\n }\n\n if (literalTagNumbers.has(tagNumber)) {\n literalTagNumbers.delete(tagNumber);\n getTarget().push(`</${tagNumber}>`);\n continue;\n }\n\n const openTag = openTags.pop();\n if (!openTag || openTag.tagNumber !== tagNumber) {\n throw new Error(`Unexpected closing tag </${tagNumber}>`);\n }\n getTarget().push(renderDeclaration(openTag.declaration, openTag.children));\n }\n\n flushText();\n if (openTags.length > 0) {\n throw new Error(`Unclosed tag <${openTags.at(-1)!.tagNumber}>`);\n }\n\n return result;\n};\n\n/**\n * Drop-in for react-i18next's `IcuTransWithoutContext`: translates\n * `i18nKey` (falling back to `defaultTranslation`) with `values`, then maps\n * its numbered tags (`<0>…</0>`) to the `content` declarations.\n *\n * @example\n * ```tsx\n * <IcuTransWithoutContext\n * i18nKey=\"welcome\"\n * defaultTranslation=\"Hello <0>{name}</0>\"\n * content={[{ type: 'strong' }]}\n * values={{ name: 'Ann' }}\n * />\n * ```\n */\nexport const IcuTransWithoutContext: typeof UpstreamIcuTransWithoutContext = ({\n i18nKey,\n defaultTranslation,\n content,\n ns,\n values = {},\n i18n: i18nFromProps,\n t: tFromProps,\n}: IcuTransProps) => {\n const i18n = i18nFromProps ?? getI18n();\n const translate = (tFromProps ??\n i18n?.t?.bind(i18n) ??\n ((key: string) => key)) as (key: string, options: TOptions) => unknown;\n const namespaces =\n ns ??\n (i18n?.options?.defaultNS as string | string[] | undefined) ??\n 'translation';\n\n const translation = String(\n translate(i18nKey || defaultTranslation, {\n defaultValue: defaultTranslation,\n ...(i18n?.options?.interpolation?.defaultVariables as\n | Record<string, unknown>\n | undefined),\n ...values,\n // Values are escaped so their markup is never read as tags, then\n // decoded with the surrounding text.\n interpolation: { escapeValue: true },\n ns: namespaces,\n })\n );\n\n try {\n return createElement(\n Fragment,\n null,\n ...renderTranslation(\n translation,\n (content ?? []) as readonly ContentDeclaration[]\n )\n );\n } catch {\n // Malformed tags: the translation is shown as written, like upstream.\n return createElement(Fragment, null, translation);\n }\n};\n\n/**\n * Drop-in for react-i18next's `IcuTrans`: `IcuTransWithoutContext` with the\n * translation function of the current locale.\n */\nexport const IcuTrans: typeof UpstreamIcuTrans = (props: IcuTransProps) => {\n const namespace = Array.isArray(props.ns) ? props.ns[0] : props.ns;\n const { t } = useTranslationLoose(namespace);\n\n return createElement(IcuTransWithoutContext, {\n ...props,\n t: props.t ?? (t as IcuTransProps['t']),\n });\n};\n"],"mappings":"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"}
|
package/dist/esm/Trans.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useTranslationLoose } from "./useTranslation.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
5
|
+
import { Children, Fragment as Fragment$1, cloneElement, isValidElement } from "react";
|
|
5
6
|
import { parseTaggedMessage } from "@intlayer/core/messageFormat";
|
|
6
|
-
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
7
7
|
|
|
8
8
|
// src/Trans.tsx
|
|
9
9
|
/**
|
|
@@ -22,7 +22,7 @@ const renderTokens = (tokens, components, childrenArray) => tokens.map((token, t
|
|
|
22
22
|
const NativeTag = token.tag;
|
|
23
23
|
return /* @__PURE__ */ jsx(NativeTag, { children: renderedChildren }, tokenIndex);
|
|
24
24
|
}
|
|
25
|
-
return /* @__PURE__ */ jsx(Fragment, { children: renderedChildren }, tokenIndex);
|
|
25
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: renderedChildren }, tokenIndex);
|
|
26
26
|
});
|
|
27
27
|
/**
|
|
28
28
|
* Drop-in for react-i18next's `<Trans>`.
|
|
@@ -50,11 +50,11 @@ const Trans = function Trans({ i18nKey, ns, values, count, context, defaults, co
|
|
|
50
50
|
if (typeof defaults === "string") translateOptions.defaultValue = defaults;
|
|
51
51
|
const message = i18nKey ? t(i18nKey, translateOptions) : defaults ?? "";
|
|
52
52
|
const resolvedMessage = typeof message === "string" && message !== i18nKey ? message : defaults ?? message;
|
|
53
|
-
if (typeof resolvedMessage !== "string") return /* @__PURE__ */ jsx(Fragment
|
|
53
|
+
if (typeof resolvedMessage !== "string") return /* @__PURE__ */ jsx(Fragment, { children: children ?? resolvedMessage });
|
|
54
54
|
const childrenArray = Children.toArray(children);
|
|
55
55
|
const tokens = parseTaggedMessage(resolvedMessage);
|
|
56
|
-
if (!tokens.some((token) => typeof token !== "string") && !components) return /* @__PURE__ */ jsx(Fragment
|
|
57
|
-
return /* @__PURE__ */ jsx(Fragment
|
|
56
|
+
if (!tokens.some((token) => typeof token !== "string") && !components) return /* @__PURE__ */ jsx(Fragment, { children: resolvedMessage });
|
|
57
|
+
return /* @__PURE__ */ jsx(Fragment, { children: renderTokens(tokens, components ?? {}, childrenArray) });
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
export { Trans };
|
package/dist/esm/Trans.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Trans.mjs","names":[],"sources":["../../src/Trans.tsx"],"sourcesContent":["'use client';\n\nimport {\n parseTaggedMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { DictionaryKeys } from '@intlayer/types/module_augmentation';\nimport type { Namespace, TOptions } from 'i18next';\nimport {\n Children,\n cloneElement,\n Fragment,\n isValidElement,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { TransProps } from 'react-i18next';\nimport { useTranslationLoose } from './useTranslation';\n\n/**\n * `<Trans>` props for a known dictionary namespace: `i18nKey` is validated\n * against the dictionary's dot-paths, matching the strength of `useIntlayer`.\n */\ntype TypedTransProps<N extends DictionaryKeys, P extends string> = Omit<\n TransProps<string>,\n 'i18nKey' | 'ns'\n> & {\n /** Dictionary namespace the `i18nKey` is validated against. */\n ns: N | readonly N[];\n /** Typed dot-path key into the `ns` dictionary. */\n i18nKey: P;\n};\n\n/**\n * Overload set for {@link Trans}: with a `ns` prop the `i18nKey` is a typed\n * dot-path of that dictionary; without one the key falls back to the default\n * namespace and stays loosely typed.\n */\ntype TypedTrans = {\n <N extends DictionaryKeys, P extends ValidDotPathsFor<N>>(\n props: TypedTransProps<N, P>\n ): ReactElement;\n (props: TransProps<string> & { ns?: undefined }): ReactElement;\n};\n\n/**\n * Renders parsed message tokens to React nodes, mapping tags to the\n * `components` prop (object or array form) or to the JSX children\n * (numbered tags `<1>…</1>` index into the children, react-i18next style).\n */\nconst renderTokens = (\n tokens: TaggedMessageToken[],\n components: Record<string, ReactElement> | readonly ReactElement[],\n childrenArray: ReactNode[]\n): ReactNode[] =>\n tokens.map((token, tokenIndex) => {\n if (typeof token === 'string') return token;\n\n const renderedChildren = renderTokens(\n token.children,\n components,\n childrenArray\n );\n\n const mappedComponent = Array.isArray(components)\n ? components[Number(token.tag)]\n : (components as Record<string, ReactElement>)[token.tag];\n\n const fallbackChild = /^\\d+$/.test(token.tag)\n ? childrenArray[Number(token.tag)]\n : undefined;\n\n const elementToClone = mappedComponent ?? fallbackChild;\n\n if (isValidElement(elementToClone)) {\n return cloneElement(\n elementToClone as ReactElement<{ children?: ReactNode }>,\n { key: tokenIndex },\n ...(renderedChildren.length\n ? renderedChildren\n : [\n (elementToClone as ReactElement<{ children?: ReactNode }>).props\n .children,\n ])\n );\n }\n\n // Native HTML tag in the message without a mapping — render it as-is\n if (/^[a-z][\\w-]*$/.test(token.tag)) {\n const NativeTag = token.tag as keyof React.JSX.IntrinsicElements;\n return <NativeTag key={tokenIndex}>{renderedChildren}</NativeTag>;\n }\n\n // Unknown numbered tag — render its children unwrapped\n return <Fragment key={tokenIndex}>{renderedChildren}</Fragment>;\n });\n\n/**\n * Drop-in for react-i18next's `<Trans>`.\n *\n * Supports `values` interpolation, `count` plural resolution, `context`,\n * `defaults` fallback, and component interpolation through the `components`\n * prop (object or array form) or numbered tags mapped onto JSX children.\n *\n * @example\n * ```tsx\n * <Trans i18nKey=\"richText\" components={{ bold: <strong /> }} />\n * <Trans i18nKey=\"hello\" count={2} values={{ name: 'John' }}>\n * Hello <b>{'{{name}}'}</b>\n * </Trans>\n * ```\n */\nexport const Trans = function Trans<\n Key extends string = string,\n Ns extends Namespace = Namespace,\n>({\n i18nKey,\n ns,\n values,\n count,\n context,\n defaults,\n components,\n tOptions,\n children,\n}: TransProps<Key, Ns>): React.ReactElement {\n const { t } = useTranslationLoose(Array.isArray(ns) ? ns[0] : ns);\n\n const translateOptions: TOptions = {\n ...((tOptions ?? {}) as TOptions),\n ...((values ?? {}) as Record<string, unknown>),\n };\n if (count !== undefined) translateOptions.count = count;\n if (context !== undefined) translateOptions.context = context;\n if (typeof defaults === 'string') translateOptions.defaultValue = defaults;\n\n const message = i18nKey\n ? t(i18nKey as string, translateOptions)\n : (defaults ?? '');\n\n const resolvedMessage =\n typeof message === 'string' && message !== i18nKey\n ? message\n : (defaults ?? message);\n\n if (typeof resolvedMessage !== 'string') {\n return <>{children ?? resolvedMessage}</>;\n }\n\n const childrenArray = Children.toArray(children);\n\n const tokens = parseTaggedMessage(resolvedMessage);\n const hasTags = tokens.some((token) => typeof token !== 'string');\n\n if (!hasTags && !components) {\n return <>{resolvedMessage}</>;\n }\n\n return (\n <>\n {renderTokens(\n tokens,\n (components ?? {}) as Record<string, ReactElement>,\n childrenArray\n )}\n </>\n );\n} as TypedTrans;\n"],"mappings":";;;;;;;;;;;;;AAmDA,MAAM,gBACJ,QACA,YACA,kBAEA,OAAO,KAAK,OAAO,eAAe;CAChC,IAAI,OAAO,UAAU,UAAU,OAAO;CAEtC,MAAM,mBAAmB,aACvB,MAAM,UACN,YACA,aACF;CAEA,MAAM,kBAAkB,MAAM,QAAQ,UAAU,IAC5C,WAAW,OAAO,MAAM,GAAG,KAC1B,WAA4C,MAAM;CAEvD,MAAM,gBAAgB,QAAQ,KAAK,MAAM,GAAG,IACxC,cAAc,OAAO,MAAM,GAAG,KAC9B;CAEJ,MAAM,iBAAiB,mBAAmB;CAE1C,IAAI,eAAe,cAAc,GAC/B,OAAO,aACL,gBACA,EAAE,KAAK,WAAW,GAClB,GAAI,iBAAiB,SACjB,mBACA,CACG,eAA0D,MACxD,QACL,CACN;CAIF,IAAI,gBAAgB,KAAK,MAAM,GAAG,GAAG;EACnC,MAAM,YAAY,MAAM;EACxB,OAAO,oBAAC,WAAD,YAA6B,iBAA4B,GAAzC,UAAyC;CAClE;CAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"Trans.mjs","names":["Fragment"],"sources":["../../src/Trans.tsx"],"sourcesContent":["'use client';\n\nimport {\n parseTaggedMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { DictionaryKeys } from '@intlayer/types/module_augmentation';\nimport type { Namespace, TOptions } from 'i18next';\nimport {\n Children,\n cloneElement,\n Fragment,\n isValidElement,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { TransProps } from 'react-i18next';\nimport { useTranslationLoose } from './useTranslation';\n\n/**\n * `<Trans>` props for a known dictionary namespace: `i18nKey` is validated\n * against the dictionary's dot-paths, matching the strength of `useIntlayer`.\n */\ntype TypedTransProps<N extends DictionaryKeys, P extends string> = Omit<\n TransProps<string>,\n 'i18nKey' | 'ns'\n> & {\n /** Dictionary namespace the `i18nKey` is validated against. */\n ns: N | readonly N[];\n /** Typed dot-path key into the `ns` dictionary. */\n i18nKey: P;\n};\n\n/**\n * Overload set for {@link Trans}: with a `ns` prop the `i18nKey` is a typed\n * dot-path of that dictionary; without one the key falls back to the default\n * namespace and stays loosely typed.\n */\ntype TypedTrans = {\n <N extends DictionaryKeys, P extends ValidDotPathsFor<N>>(\n props: TypedTransProps<N, P>\n ): ReactElement;\n (props: TransProps<string> & { ns?: undefined }): ReactElement;\n};\n\n/**\n * Renders parsed message tokens to React nodes, mapping tags to the\n * `components` prop (object or array form) or to the JSX children\n * (numbered tags `<1>…</1>` index into the children, react-i18next style).\n */\nconst renderTokens = (\n tokens: TaggedMessageToken[],\n components: Record<string, ReactElement> | readonly ReactElement[],\n childrenArray: ReactNode[]\n): ReactNode[] =>\n tokens.map((token, tokenIndex) => {\n if (typeof token === 'string') return token;\n\n const renderedChildren = renderTokens(\n token.children,\n components,\n childrenArray\n );\n\n const mappedComponent = Array.isArray(components)\n ? components[Number(token.tag)]\n : (components as Record<string, ReactElement>)[token.tag];\n\n const fallbackChild = /^\\d+$/.test(token.tag)\n ? childrenArray[Number(token.tag)]\n : undefined;\n\n const elementToClone = mappedComponent ?? fallbackChild;\n\n if (isValidElement(elementToClone)) {\n return cloneElement(\n elementToClone as ReactElement<{ children?: ReactNode }>,\n { key: tokenIndex },\n ...(renderedChildren.length\n ? renderedChildren\n : [\n (elementToClone as ReactElement<{ children?: ReactNode }>).props\n .children,\n ])\n );\n }\n\n // Native HTML tag in the message without a mapping — render it as-is\n if (/^[a-z][\\w-]*$/.test(token.tag)) {\n const NativeTag = token.tag as keyof React.JSX.IntrinsicElements;\n return <NativeTag key={tokenIndex}>{renderedChildren}</NativeTag>;\n }\n\n // Unknown numbered tag — render its children unwrapped\n return <Fragment key={tokenIndex}>{renderedChildren}</Fragment>;\n });\n\n/**\n * Drop-in for react-i18next's `<Trans>`.\n *\n * Supports `values` interpolation, `count` plural resolution, `context`,\n * `defaults` fallback, and component interpolation through the `components`\n * prop (object or array form) or numbered tags mapped onto JSX children.\n *\n * @example\n * ```tsx\n * <Trans i18nKey=\"richText\" components={{ bold: <strong /> }} />\n * <Trans i18nKey=\"hello\" count={2} values={{ name: 'John' }}>\n * Hello <b>{'{{name}}'}</b>\n * </Trans>\n * ```\n */\nexport const Trans = function Trans<\n Key extends string = string,\n Ns extends Namespace = Namespace,\n>({\n i18nKey,\n ns,\n values,\n count,\n context,\n defaults,\n components,\n tOptions,\n children,\n}: TransProps<Key, Ns>): React.ReactElement {\n const { t } = useTranslationLoose(Array.isArray(ns) ? ns[0] : ns);\n\n const translateOptions: TOptions = {\n ...((tOptions ?? {}) as TOptions),\n ...((values ?? {}) as Record<string, unknown>),\n };\n if (count !== undefined) translateOptions.count = count;\n if (context !== undefined) translateOptions.context = context;\n if (typeof defaults === 'string') translateOptions.defaultValue = defaults;\n\n const message = i18nKey\n ? t(i18nKey as string, translateOptions)\n : (defaults ?? '');\n\n const resolvedMessage =\n typeof message === 'string' && message !== i18nKey\n ? message\n : (defaults ?? message);\n\n if (typeof resolvedMessage !== 'string') {\n return <>{children ?? resolvedMessage}</>;\n }\n\n const childrenArray = Children.toArray(children);\n\n const tokens = parseTaggedMessage(resolvedMessage);\n const hasTags = tokens.some((token) => typeof token !== 'string');\n\n if (!hasTags && !components) {\n return <>{resolvedMessage}</>;\n }\n\n return (\n <>\n {renderTokens(\n tokens,\n (components ?? {}) as Record<string, ReactElement>,\n childrenArray\n )}\n </>\n );\n} as TypedTrans;\n"],"mappings":";;;;;;;;;;;;;AAmDA,MAAM,gBACJ,QACA,YACA,kBAEA,OAAO,KAAK,OAAO,eAAe;CAChC,IAAI,OAAO,UAAU,UAAU,OAAO;CAEtC,MAAM,mBAAmB,aACvB,MAAM,UACN,YACA,aACF;CAEA,MAAM,kBAAkB,MAAM,QAAQ,UAAU,IAC5C,WAAW,OAAO,MAAM,GAAG,KAC1B,WAA4C,MAAM;CAEvD,MAAM,gBAAgB,QAAQ,KAAK,MAAM,GAAG,IACxC,cAAc,OAAO,MAAM,GAAG,KAC9B;CAEJ,MAAM,iBAAiB,mBAAmB;CAE1C,IAAI,eAAe,cAAc,GAC/B,OAAO,aACL,gBACA,EAAE,KAAK,WAAW,GAClB,GAAI,iBAAiB,SACjB,mBACA,CACG,eAA0D,MACxD,QACL,CACN;CAIF,IAAI,gBAAgB,KAAK,MAAM,GAAG,GAAG;EACnC,MAAM,YAAY,MAAM;EACxB,OAAO,oBAAC,WAAD,YAA6B,iBAA4B,GAAzC,UAAyC;CAClE;CAGA,OAAO,oBAACA,YAAD,YAA4B,iBAA2B,GAAxC,UAAwC;AAChE,CAAC;;;;;;;;;;;;;;;;AAiBH,MAAa,QAAQ,SAAS,MAG5B,EACA,SACA,IACA,QACA,OACA,SACA,UACA,YACA,UACA,YAC0C;CAC1C,MAAM,EAAE,MAAM,oBAAoB,MAAM,QAAQ,EAAE,IAAI,GAAG,KAAK,EAAE;CAEhE,MAAM,mBAA6B;EACjC,GAAK,YAAY,CAAC;EAClB,GAAK,UAAU,CAAC;CAClB;CACA,IAAI,UAAU,QAAW,iBAAiB,QAAQ;CAClD,IAAI,YAAY,QAAW,iBAAiB,UAAU;CACtD,IAAI,OAAO,aAAa,UAAU,iBAAiB,eAAe;CAElE,MAAM,UAAU,UACZ,EAAE,SAAmB,gBAAgB,IACpC,YAAY;CAEjB,MAAM,kBACJ,OAAO,YAAY,YAAY,YAAY,UACvC,UACC,YAAY;CAEnB,IAAI,OAAO,oBAAoB,UAC7B,OAAO,0CAAG,YAAY,gBAAkB;CAG1C,MAAM,gBAAgB,SAAS,QAAQ,QAAQ;CAE/C,MAAM,SAAS,mBAAmB,eAAe;CAGjD,IAAI,CAFY,OAAO,MAAM,UAAU,OAAO,UAAU,QAE7C,KAAK,CAAC,YACf,OAAO,0CAAG,gBAAkB;CAG9B,OACE,0CACG,aACC,QACC,cAAc,CAAC,GAChB,aACF,EACA;AAEN"}
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getI18n } from "./globalI18n.mjs";
|
|
2
|
+
import { getInterpolationValues, resolveTranslation, toTranslationKey } from "@intlayer/i18next";
|
|
2
3
|
import { getHTMLTextDir } from "@intlayer/core/localization";
|
|
3
4
|
import { resolveMessageNodeToString } from "@intlayer/core/messageFormat";
|
|
4
|
-
import { getInterpolationValues, resolveTranslation } from "@intlayer/i18next";
|
|
5
5
|
|
|
6
6
|
// src/createTranslationApi.ts
|
|
7
7
|
/**
|
|
@@ -18,11 +18,19 @@ import { getInterpolationValues, resolveTranslation } from "@intlayer/i18next";
|
|
|
18
18
|
* rendered text already.
|
|
19
19
|
*/
|
|
20
20
|
const createTranslationApi = ({ locale, setLocale, availableLocales, namespace, keyPrefix, dictionaryContent }) => {
|
|
21
|
-
const
|
|
21
|
+
const instanceOptions = getI18n()?.options;
|
|
22
|
+
const fallbackNamespaces = instanceOptions?.fallbackNS;
|
|
23
|
+
/** A key as written, or the key a selector (`$ => $.a.b`) designates. */
|
|
24
|
+
const toKey = (key, options) => toTranslationKey(key, {
|
|
25
|
+
...instanceOptions,
|
|
26
|
+
ns: namespace,
|
|
27
|
+
...options
|
|
28
|
+
});
|
|
29
|
+
const resolvedKeyPrefix = keyPrefix === void 0 || keyPrefix === "" ? void 0 : toKey(keyPrefix);
|
|
22
30
|
const resolveSingleKey = (key, translateOptions) => resolveTranslation({
|
|
23
31
|
locale,
|
|
24
32
|
namespace,
|
|
25
|
-
key:
|
|
33
|
+
key: resolvedKeyPrefix ? `${resolvedKeyPrefix}.${key}` : key,
|
|
26
34
|
options: translateOptions,
|
|
27
35
|
fallbackNamespaces,
|
|
28
36
|
dictionaryContent
|
|
@@ -32,7 +40,7 @@ const createTranslationApi = ({ locale, setLocale, availableLocales, namespace,
|
|
|
32
40
|
defaultValue: optionsOrDefaultValue,
|
|
33
41
|
...extraOptions
|
|
34
42
|
} : optionsOrDefaultValue ?? {};
|
|
35
|
-
const keys = Array.isArray(key) ? key : [key];
|
|
43
|
+
const keys = (Array.isArray(key) ? key : [key]).map((candidate) => toKey(candidate, translateOptions));
|
|
36
44
|
for (const candidateKey of keys) {
|
|
37
45
|
const resolved = resolveSingleKey(candidateKey, translateOptions);
|
|
38
46
|
if (resolved !== void 0) return resolved;
|
|
@@ -57,22 +65,23 @@ const createTranslationApi = ({ locale, setLocale, availableLocales, namespace,
|
|
|
57
65
|
exists: (key, existsOptions) => resolveTranslation({
|
|
58
66
|
locale,
|
|
59
67
|
namespace,
|
|
60
|
-
key,
|
|
68
|
+
key: toKey(key, existsOptions),
|
|
61
69
|
options: existsOptions,
|
|
62
70
|
fallbackNamespaces,
|
|
63
71
|
dictionaryContent
|
|
64
72
|
}) !== void 0,
|
|
65
73
|
t: translate,
|
|
66
74
|
getFixedT: (language, fixedNamespace) => (key, fixedOptions) => {
|
|
75
|
+
const resolvedKey = toKey(key, fixedOptions);
|
|
67
76
|
const resolved = resolveTranslation({
|
|
68
77
|
locale: language ?? locale,
|
|
69
78
|
namespace: fixedNamespace ?? namespace,
|
|
70
|
-
key,
|
|
79
|
+
key: resolvedKey,
|
|
71
80
|
options: fixedOptions,
|
|
72
81
|
fallbackNamespaces,
|
|
73
82
|
dictionaryContent: (language ?? locale) === locale && (fixedNamespace ?? namespace) === namespace ? dictionaryContent : void 0
|
|
74
83
|
});
|
|
75
|
-
return resolved !== void 0 ? resolved :
|
|
84
|
+
return resolved !== void 0 ? resolved : resolvedKey;
|
|
76
85
|
}
|
|
77
86
|
}
|
|
78
87
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTranslationApi.mjs","names":[],"sources":["../../src/createTranslationApi.ts"],"sourcesContent":["import { getHTMLTextDir } from '@intlayer/core/localization';\nimport { resolveMessageNodeToString } from '@intlayer/core/messageFormat';\nimport {\n getInterpolationValues,\n resolveTranslation,\n type TypedTFunction,\n} from '@intlayer/i18next';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { TOptions } from 'i18next';\nimport { getI18n } from './globalI18n';\n\n/** Untyped runtime `t()` produced by {@link createTranslationApi}. */\nexport type TranslateFunction = (\n key: string | string[],\n optionsOrDefaultValue?: TOptions | string,\n extraOptions?: TOptions\n) => string;\n\n/**\n * The `i18n` facade with `t` and `getFixedT` typed against the dictionary the\n * hook is bound to: `t` is the hook's translate function type `TFn`, and\n * `getFixedT` returns a fully-typed `t()` for the requested namespace (or the\n * hook's own `t()` when no namespace is given).\n */\nexport type TypedI18nFacade<TFn = TranslateFunction> = Omit<\n I18nFacade,\n 't' | 'getFixedT'\n> & {\n t: TFn;\n getFixedT: {\n <N extends DictionaryKeys>(\n language: string | null | undefined,\n fixedNamespace: N\n ): TypedTFunction<N>;\n (language?: string | null, fixedNamespace?: null): TFn;\n };\n};\n\n/** Result shape of the typed translation hooks: `{ t, i18n, ready }`. */\nexport type TypedTranslationResult<TFn = TranslateFunction> = {\n t: TFn;\n i18n: TypedI18nFacade<TFn>;\n ready: true;\n};\n\n/** `i18n` facade shape produced by {@link createTranslationApi}. */\nexport type I18nFacade = {\n language: string;\n languages: string[];\n resolvedLanguage: string;\n isInitialized: boolean;\n changeLanguage: (newLanguage: string) => Promise<void>;\n dir: (language?: string) => 'ltr' | 'rtl';\n exists: (key: string, existsOptions?: TOptions) => boolean;\n t: TranslateFunction;\n getFixedT: (\n language?: string | null,\n fixedNamespace?: string | null\n ) => (key: string, fixedOptions?: TOptions) => string;\n};\n\nexport type CreateTranslationApiParams = {\n /** Active locale. */\n locale: LocalesValues;\n /** Locale setter backing `i18n.changeLanguage`. */\n setLocale: (newLocale: LocalesValues) => void;\n /** Configured locales backing `i18n.languages`. */\n availableLocales: LocalesValues[];\n /** Default namespace (dictionary key) for `t()` lookups. */\n namespace: string;\n /** Optional prefix prepended to every `t()` key. */\n keyPrefix?:
|
|
1
|
+
{"version":3,"file":"createTranslationApi.mjs","names":[],"sources":["../../src/createTranslationApi.ts"],"sourcesContent":["import { getHTMLTextDir } from '@intlayer/core/localization';\nimport { resolveMessageNodeToString } from '@intlayer/core/messageFormat';\nimport {\n getInterpolationValues,\n resolveTranslation,\n type SelectorOptions,\n type TypedTFunction,\n toTranslationKey,\n} from '@intlayer/i18next';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { TOptions } from 'i18next';\nimport { getI18n } from './globalI18n';\n\n/** Untyped runtime `t()` produced by {@link createTranslationApi}. */\nexport type TranslateFunction = (\n key: string | string[],\n optionsOrDefaultValue?: TOptions | string,\n extraOptions?: TOptions\n) => string;\n\n/**\n * The `i18n` facade with `t` and `getFixedT` typed against the dictionary the\n * hook is bound to: `t` is the hook's translate function type `TFn`, and\n * `getFixedT` returns a fully-typed `t()` for the requested namespace (or the\n * hook's own `t()` when no namespace is given).\n */\nexport type TypedI18nFacade<TFn = TranslateFunction> = Omit<\n I18nFacade,\n 't' | 'getFixedT'\n> & {\n t: TFn;\n getFixedT: {\n <N extends DictionaryKeys>(\n language: string | null | undefined,\n fixedNamespace: N\n ): TypedTFunction<N>;\n (language?: string | null, fixedNamespace?: null): TFn;\n };\n};\n\n/** Result shape of the typed translation hooks: `{ t, i18n, ready }`. */\nexport type TypedTranslationResult<TFn = TranslateFunction> = {\n t: TFn;\n i18n: TypedI18nFacade<TFn>;\n ready: true;\n};\n\n/** `i18n` facade shape produced by {@link createTranslationApi}. */\nexport type I18nFacade = {\n language: string;\n languages: string[];\n resolvedLanguage: string;\n isInitialized: boolean;\n changeLanguage: (newLanguage: string) => Promise<void>;\n dir: (language?: string) => 'ltr' | 'rtl';\n exists: (key: string, existsOptions?: TOptions) => boolean;\n t: TranslateFunction;\n getFixedT: (\n language?: string | null,\n fixedNamespace?: string | null\n ) => (key: string, fixedOptions?: TOptions) => string;\n};\n\nexport type CreateTranslationApiParams = {\n /** Active locale. */\n locale: LocalesValues;\n /** Locale setter backing `i18n.changeLanguage`. */\n setLocale: (newLocale: LocalesValues) => void;\n /** Configured locales backing `i18n.languages`. */\n availableLocales: LocalesValues[];\n /** Default namespace (dictionary key) for `t()` lookups. */\n namespace: string;\n /** Optional prefix prepended to every `t()` key. */\n /** Key prefix, or a selector designating it (`$ => $.hero`). */\n keyPrefix?: unknown;\n /**\n * Pre-resolved dictionary content for `namespace` — supplied by the\n * build-optimized `useDictionary` / `useDictionaryDynamic` variants so\n * lookups skip the runtime registry.\n */\n dictionaryContent?: unknown;\n};\n\n/**\n * Builds the `{ t, i18n }` pair shared by `useTranslation` (runtime\n * registry lookup) and `useDictionary` / `useDictionaryDynamic`\n * (build-time-imported dictionary content).\n *\n * Translation lookup goes through the shared i18next-dialect resolver:\n * namespace prefixes (`ns:key`), the `ns` option, plural suffixes\n * (`key_one`/`key_other` via `Intl.PluralRules`), context suffixes\n * (`key_male`), `$t()` nesting, `defaultValue` and `{{var}}` interpolation\n * are all supported, as is the `fallbackNS` of the i18n instance registered\n * through `initReactI18next`. Values are not HTML-escaped: React escapes\n * rendered text already.\n */\nexport const createTranslationApi = ({\n locale,\n setLocale,\n availableLocales,\n namespace,\n keyPrefix,\n dictionaryContent,\n}: CreateTranslationApiParams): {\n translate: TranslateFunction;\n i18n: I18nFacade;\n} => {\n const instanceOptions = getI18n()?.options;\n const fallbackNamespaces = instanceOptions?.fallbackNS;\n\n /** A key as written, or the key a selector (`$ => $.a.b`) designates. */\n const toKey = (key: unknown, options?: TOptions): string =>\n toTranslationKey(key, {\n ...(instanceOptions as SelectorOptions | undefined),\n ns: namespace,\n ...(options as SelectorOptions | undefined),\n });\n const resolvedKeyPrefix =\n keyPrefix === undefined || keyPrefix === '' ? undefined : toKey(keyPrefix);\n\n const resolveSingleKey = (\n key: string,\n translateOptions?: TOptions\n ): unknown =>\n resolveTranslation({\n locale,\n namespace,\n key: resolvedKeyPrefix ? `${resolvedKeyPrefix}.${key}` : key,\n options: translateOptions,\n fallbackNamespaces,\n dictionaryContent,\n });\n\n const translate: TranslateFunction = (\n key,\n optionsOrDefaultValue,\n extraOptions\n ) => {\n const translateOptions: TOptions =\n typeof optionsOrDefaultValue === 'string'\n ? { defaultValue: optionsOrDefaultValue, ...extraOptions }\n : (optionsOrDefaultValue ?? {});\n\n const keys = (Array.isArray(key) ? key : [key]).map((candidate: unknown) =>\n toKey(candidate, translateOptions)\n );\n\n for (const candidateKey of keys) {\n const resolved = resolveSingleKey(candidateKey, translateOptions);\n if (resolved !== undefined) return resolved as string;\n }\n\n const defaultValue = translateOptions.defaultValue;\n if (typeof defaultValue === 'string') {\n return resolveMessageNodeToString(\n defaultValue,\n getInterpolationValues(translateOptions),\n locale,\n undefined,\n 'double-brace'\n );\n }\n\n return keys[keys.length - 1] as string;\n };\n\n const i18n: I18nFacade = {\n language: locale as string,\n languages: (availableLocales ?? []) as string[],\n resolvedLanguage: locale as string,\n isInitialized: true,\n changeLanguage: async (newLanguage: string) => {\n setLocale(newLanguage as LocalesValues);\n },\n dir: (language?: string): 'ltr' | 'rtl' => {\n const direction = getHTMLTextDir((language ?? locale) as LocalesValues);\n return direction === 'rtl' ? 'rtl' : 'ltr';\n },\n exists: (key: string, existsOptions?: TOptions): boolean =>\n resolveTranslation({\n locale,\n namespace,\n key: toKey(key, existsOptions),\n options: existsOptions,\n fallbackNamespaces,\n dictionaryContent,\n }) !== undefined,\n t: translate,\n getFixedT:\n (language?: string | null, fixedNamespace?: string | null) =>\n (key: string, fixedOptions?: TOptions): string => {\n const resolvedKey = toKey(key, fixedOptions);\n const resolved = resolveTranslation({\n locale: (language ?? locale) as LocalesValues,\n namespace: fixedNamespace ?? namespace,\n key: resolvedKey,\n options: fixedOptions,\n fallbackNamespaces,\n dictionaryContent:\n (language ?? locale) === locale &&\n (fixedNamespace ?? namespace) === namespace\n ? dictionaryContent\n : undefined,\n });\n return resolved !== undefined ? (resolved as string) : resolvedKey;\n },\n };\n\n return { translate, i18n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmGA,MAAa,wBAAwB,EACnC,QACA,WACA,kBACA,WACA,WACA,wBAIG;CACH,MAAM,kBAAkB,QAAQ,CAAC,EAAE;CACnC,MAAM,qBAAqB,iBAAiB;;CAG5C,MAAM,SAAS,KAAc,YAC3B,iBAAiB,KAAK;EACpB,GAAI;EACJ,IAAI;EACJ,GAAI;CACN,CAAC;CACH,MAAM,oBACJ,cAAc,UAAa,cAAc,KAAK,SAAY,MAAM,SAAS;CAE3E,MAAM,oBACJ,KACA,qBAEA,mBAAmB;EACjB;EACA;EACA,KAAK,oBAAoB,GAAG,kBAAkB,GAAG,QAAQ;EACzD,SAAS;EACT;EACA;CACF,CAAC;CAEH,MAAM,aACJ,KACA,uBACA,iBACG;EACH,MAAM,mBACJ,OAAO,0BAA0B,WAC7B;GAAE,cAAc;GAAuB,GAAG;EAAa,IACtD,yBAAyB,CAAC;EAEjC,MAAM,QAAQ,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG,EAAC,CAAE,KAAK,cACnD,MAAM,WAAW,gBAAgB,CACnC;EAEA,KAAK,MAAM,gBAAgB,MAAM;GAC/B,MAAM,WAAW,iBAAiB,cAAc,gBAAgB;GAChE,IAAI,aAAa,QAAW,OAAO;EACrC;EAEA,MAAM,eAAe,iBAAiB;EACtC,IAAI,OAAO,iBAAiB,UAC1B,OAAO,2BACL,cACA,uBAAuB,gBAAgB,GACvC,QACA,QACA,cACF;EAGF,OAAO,KAAK,KAAK,SAAS;CAC5B;CA4CA,OAAO;EAAE;EAAW;GAzClB,UAAU;GACV,WAAY,oBAAoB,CAAC;GACjC,kBAAkB;GAClB,eAAe;GACf,gBAAgB,OAAO,gBAAwB;IAC7C,UAAU,WAA4B;GACxC;GACA,MAAM,aAAqC;IAEzC,OADkB,eAAgB,YAAY,MAC/B,MAAM,QAAQ,QAAQ;GACvC;GACA,SAAS,KAAa,kBACpB,mBAAmB;IACjB;IACA;IACA,KAAK,MAAM,KAAK,aAAa;IAC7B,SAAS;IACT;IACA;GACF,CAAC,MAAM;GACT,GAAG;GACH,YACG,UAA0B,oBAC1B,KAAa,iBAAoC;IAChD,MAAM,cAAc,MAAM,KAAK,YAAY;IAC3C,MAAM,WAAW,mBAAmB;KAClC,QAAS,YAAY;KACrB,WAAW,kBAAkB;KAC7B,KAAK;KACL,SAAS;KACT;KACA,oBACG,YAAY,YAAY,WACxB,kBAAkB,eAAe,YAC9B,oBACA;IACR,CAAC;IACD,OAAO,aAAa,SAAa,WAAsB;GACzD;EAGmB;CAAE;AAC3B"}
|
package/dist/esm/helpers.mjs
CHANGED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// src/htmlEntities.ts
|
|
2
|
+
/**
|
|
3
|
+
* Named HTML entities decoded in `IcuTrans` text, the same set as
|
|
4
|
+
* react-i18next. Only bundled by apps rendering `IcuTrans`.
|
|
5
|
+
*/
|
|
6
|
+
const HTML_ENTITIES = {
|
|
7
|
+
nbsp: "\xA0",
|
|
8
|
+
amp: "&",
|
|
9
|
+
lt: "<",
|
|
10
|
+
gt: ">",
|
|
11
|
+
quot: "\"",
|
|
12
|
+
apos: "'",
|
|
13
|
+
copy: "©",
|
|
14
|
+
reg: "®",
|
|
15
|
+
trade: "™",
|
|
16
|
+
hellip: "…",
|
|
17
|
+
ndash: "–",
|
|
18
|
+
mdash: "—",
|
|
19
|
+
lsquo: "‘",
|
|
20
|
+
rsquo: "’",
|
|
21
|
+
sbquo: "‚",
|
|
22
|
+
ldquo: "“",
|
|
23
|
+
rdquo: "”",
|
|
24
|
+
bdquo: "„",
|
|
25
|
+
dagger: "†",
|
|
26
|
+
Dagger: "‡",
|
|
27
|
+
bull: "•",
|
|
28
|
+
prime: "′",
|
|
29
|
+
Prime: "″",
|
|
30
|
+
lsaquo: "‹",
|
|
31
|
+
rsaquo: "›",
|
|
32
|
+
sect: "§",
|
|
33
|
+
para: "¶",
|
|
34
|
+
middot: "·",
|
|
35
|
+
ensp: " ",
|
|
36
|
+
emsp: " ",
|
|
37
|
+
thinsp: " ",
|
|
38
|
+
euro: "€",
|
|
39
|
+
pound: "£",
|
|
40
|
+
yen: "¥",
|
|
41
|
+
cent: "¢",
|
|
42
|
+
curren: "¤",
|
|
43
|
+
times: "×",
|
|
44
|
+
divide: "÷",
|
|
45
|
+
minus: "−",
|
|
46
|
+
plusmn: "±",
|
|
47
|
+
ne: "≠",
|
|
48
|
+
le: "≤",
|
|
49
|
+
ge: "≥",
|
|
50
|
+
asymp: "≈",
|
|
51
|
+
equiv: "≡",
|
|
52
|
+
infin: "∞",
|
|
53
|
+
int: "∫",
|
|
54
|
+
sum: "∑",
|
|
55
|
+
prod: "∏",
|
|
56
|
+
radic: "√",
|
|
57
|
+
part: "∂",
|
|
58
|
+
permil: "‰",
|
|
59
|
+
deg: "°",
|
|
60
|
+
micro: "µ",
|
|
61
|
+
larr: "←",
|
|
62
|
+
uarr: "↑",
|
|
63
|
+
rarr: "→",
|
|
64
|
+
darr: "↓",
|
|
65
|
+
harr: "↔",
|
|
66
|
+
crarr: "↵",
|
|
67
|
+
lArr: "⇐",
|
|
68
|
+
uArr: "⇑",
|
|
69
|
+
rArr: "⇒",
|
|
70
|
+
dArr: "⇓",
|
|
71
|
+
hArr: "⇔",
|
|
72
|
+
alpha: "α",
|
|
73
|
+
beta: "β",
|
|
74
|
+
gamma: "γ",
|
|
75
|
+
delta: "δ",
|
|
76
|
+
epsilon: "ε",
|
|
77
|
+
zeta: "ζ",
|
|
78
|
+
eta: "η",
|
|
79
|
+
theta: "θ",
|
|
80
|
+
iota: "ι",
|
|
81
|
+
kappa: "κ",
|
|
82
|
+
lambda: "λ",
|
|
83
|
+
mu: "μ",
|
|
84
|
+
nu: "ν",
|
|
85
|
+
xi: "ξ",
|
|
86
|
+
omicron: "ο",
|
|
87
|
+
pi: "π",
|
|
88
|
+
rho: "ρ",
|
|
89
|
+
sigma: "σ",
|
|
90
|
+
tau: "τ",
|
|
91
|
+
upsilon: "υ",
|
|
92
|
+
phi: "φ",
|
|
93
|
+
chi: "χ",
|
|
94
|
+
psi: "ψ",
|
|
95
|
+
omega: "ω",
|
|
96
|
+
Alpha: "Α",
|
|
97
|
+
Beta: "Β",
|
|
98
|
+
Gamma: "Γ",
|
|
99
|
+
Delta: "Δ",
|
|
100
|
+
Epsilon: "Ε",
|
|
101
|
+
Zeta: "Ζ",
|
|
102
|
+
Eta: "Η",
|
|
103
|
+
Theta: "Θ",
|
|
104
|
+
Iota: "Ι",
|
|
105
|
+
Kappa: "Κ",
|
|
106
|
+
Lambda: "Λ",
|
|
107
|
+
Mu: "Μ",
|
|
108
|
+
Nu: "Ν",
|
|
109
|
+
Xi: "Ξ",
|
|
110
|
+
Omicron: "Ο",
|
|
111
|
+
Pi: "Π",
|
|
112
|
+
Rho: "Ρ",
|
|
113
|
+
Sigma: "Σ",
|
|
114
|
+
Tau: "Τ",
|
|
115
|
+
Upsilon: "Υ",
|
|
116
|
+
Phi: "Φ",
|
|
117
|
+
Chi: "Χ",
|
|
118
|
+
Psi: "Ψ",
|
|
119
|
+
Omega: "Ω",
|
|
120
|
+
Agrave: "À",
|
|
121
|
+
Aacute: "Á",
|
|
122
|
+
Acirc: "Â",
|
|
123
|
+
Atilde: "Ã",
|
|
124
|
+
Auml: "Ä",
|
|
125
|
+
Aring: "Å",
|
|
126
|
+
AElig: "Æ",
|
|
127
|
+
Ccedil: "Ç",
|
|
128
|
+
Egrave: "È",
|
|
129
|
+
Eacute: "É",
|
|
130
|
+
Ecirc: "Ê",
|
|
131
|
+
Euml: "Ë",
|
|
132
|
+
Igrave: "Ì",
|
|
133
|
+
Iacute: "Í",
|
|
134
|
+
Icirc: "Î",
|
|
135
|
+
Iuml: "Ï",
|
|
136
|
+
ETH: "Ð",
|
|
137
|
+
Ntilde: "Ñ",
|
|
138
|
+
Ograve: "Ò",
|
|
139
|
+
Oacute: "Ó",
|
|
140
|
+
Ocirc: "Ô",
|
|
141
|
+
Otilde: "Õ",
|
|
142
|
+
Ouml: "Ö",
|
|
143
|
+
Oslash: "Ø",
|
|
144
|
+
Ugrave: "Ù",
|
|
145
|
+
Uacute: "Ú",
|
|
146
|
+
Ucirc: "Û",
|
|
147
|
+
Uuml: "Ü",
|
|
148
|
+
Yacute: "Ý",
|
|
149
|
+
THORN: "Þ",
|
|
150
|
+
szlig: "ß",
|
|
151
|
+
agrave: "à",
|
|
152
|
+
aacute: "á",
|
|
153
|
+
acirc: "â",
|
|
154
|
+
atilde: "ã",
|
|
155
|
+
auml: "ä",
|
|
156
|
+
aring: "å",
|
|
157
|
+
aelig: "æ",
|
|
158
|
+
ccedil: "ç",
|
|
159
|
+
egrave: "è",
|
|
160
|
+
eacute: "é",
|
|
161
|
+
ecirc: "ê",
|
|
162
|
+
euml: "ë",
|
|
163
|
+
igrave: "ì",
|
|
164
|
+
iacute: "í",
|
|
165
|
+
icirc: "î",
|
|
166
|
+
iuml: "ï",
|
|
167
|
+
eth: "ð",
|
|
168
|
+
ntilde: "ñ",
|
|
169
|
+
ograve: "ò",
|
|
170
|
+
oacute: "ó",
|
|
171
|
+
ocirc: "ô",
|
|
172
|
+
otilde: "õ",
|
|
173
|
+
ouml: "ö",
|
|
174
|
+
oslash: "ø",
|
|
175
|
+
ugrave: "ù",
|
|
176
|
+
uacute: "ú",
|
|
177
|
+
ucirc: "û",
|
|
178
|
+
uuml: "ü",
|
|
179
|
+
yacute: "ý",
|
|
180
|
+
thorn: "þ",
|
|
181
|
+
yuml: "ÿ",
|
|
182
|
+
iexcl: "¡",
|
|
183
|
+
iquest: "¿",
|
|
184
|
+
fnof: "ƒ",
|
|
185
|
+
circ: "ˆ",
|
|
186
|
+
tilde: "˜",
|
|
187
|
+
OElig: "Œ",
|
|
188
|
+
oelig: "œ",
|
|
189
|
+
Scaron: "Š",
|
|
190
|
+
scaron: "š",
|
|
191
|
+
Yuml: "Ÿ",
|
|
192
|
+
ordf: "ª",
|
|
193
|
+
ordm: "º",
|
|
194
|
+
macr: "¯",
|
|
195
|
+
acute: "´",
|
|
196
|
+
cedil: "¸",
|
|
197
|
+
sup1: "¹",
|
|
198
|
+
sup2: "²",
|
|
199
|
+
sup3: "³",
|
|
200
|
+
frac14: "¼",
|
|
201
|
+
frac12: "½",
|
|
202
|
+
frac34: "¾",
|
|
203
|
+
spades: "♠",
|
|
204
|
+
clubs: "♣",
|
|
205
|
+
hearts: "♥",
|
|
206
|
+
diams: "♦",
|
|
207
|
+
loz: "◊",
|
|
208
|
+
oline: "‾",
|
|
209
|
+
frasl: "⁄",
|
|
210
|
+
weierp: "℘",
|
|
211
|
+
image: "ℑ",
|
|
212
|
+
real: "ℜ",
|
|
213
|
+
alefsym: "ℵ"
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export { HTML_ENTITIES };
|
|
217
|
+
//# sourceMappingURL=htmlEntities.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlEntities.mjs","names":[],"sources":["../../src/htmlEntities.ts"],"sourcesContent":["/**\n * Named HTML entities decoded in `IcuTrans` text, the same set as\n * react-i18next. Only bundled by apps rendering `IcuTrans`.\n */\nexport const HTML_ENTITIES: Record<string, string> = {\n nbsp: '\\u00A0',\n amp: '&',\n lt: '<',\n gt: '>',\n quot: '\"',\n apos: \"'\",\n copy: '©',\n reg: '®',\n trade: '™',\n hellip: '…',\n ndash: '–',\n mdash: '—',\n lsquo: '\\u2018',\n rsquo: '\\u2019',\n sbquo: '\\u201A',\n ldquo: '\\u201C',\n rdquo: '\\u201D',\n bdquo: '\\u201E',\n dagger: '†',\n Dagger: '‡',\n bull: '•',\n prime: '′',\n Prime: '″',\n lsaquo: '‹',\n rsaquo: '›',\n sect: '§',\n para: '¶',\n middot: '·',\n ensp: '\\u2002',\n emsp: '\\u2003',\n thinsp: '\\u2009',\n euro: '€',\n pound: '£',\n yen: '¥',\n cent: '¢',\n curren: '¤',\n times: '×',\n divide: '÷',\n minus: '−',\n plusmn: '±',\n ne: '≠',\n le: '≤',\n ge: '≥',\n asymp: '≈',\n equiv: '≡',\n infin: '∞',\n int: '∫',\n sum: '∑',\n prod: '∏',\n radic: '√',\n part: '∂',\n permil: '‰',\n deg: '°',\n micro: 'µ',\n larr: '←',\n uarr: '↑',\n rarr: '→',\n darr: '↓',\n harr: '↔',\n crarr: '↵',\n lArr: '⇐',\n uArr: '⇑',\n rArr: '⇒',\n dArr: '⇓',\n hArr: '⇔',\n alpha: 'α',\n beta: 'β',\n gamma: 'γ',\n delta: 'δ',\n epsilon: 'ε',\n zeta: 'ζ',\n eta: 'η',\n theta: 'θ',\n iota: 'ι',\n kappa: 'κ',\n lambda: 'λ',\n mu: 'μ',\n nu: 'ν',\n xi: 'ξ',\n omicron: 'ο',\n pi: 'π',\n rho: 'ρ',\n sigma: 'σ',\n tau: 'τ',\n upsilon: 'υ',\n phi: 'φ',\n chi: 'χ',\n psi: 'ψ',\n omega: 'ω',\n Alpha: 'Α',\n Beta: 'Β',\n Gamma: 'Γ',\n Delta: 'Δ',\n Epsilon: 'Ε',\n Zeta: 'Ζ',\n Eta: 'Η',\n Theta: 'Θ',\n Iota: 'Ι',\n Kappa: 'Κ',\n Lambda: 'Λ',\n Mu: 'Μ',\n Nu: 'Ν',\n Xi: 'Ξ',\n Omicron: 'Ο',\n Pi: 'Π',\n Rho: 'Ρ',\n Sigma: 'Σ',\n Tau: 'Τ',\n Upsilon: 'Υ',\n Phi: 'Φ',\n Chi: 'Χ',\n Psi: 'Ψ',\n Omega: 'Ω',\n Agrave: 'À',\n Aacute: 'Á',\n Acirc: 'Â',\n Atilde: 'Ã',\n Auml: 'Ä',\n Aring: 'Å',\n AElig: 'Æ',\n Ccedil: 'Ç',\n Egrave: 'È',\n Eacute: 'É',\n Ecirc: 'Ê',\n Euml: 'Ë',\n Igrave: 'Ì',\n Iacute: 'Í',\n Icirc: 'Î',\n Iuml: 'Ï',\n ETH: 'Ð',\n Ntilde: 'Ñ',\n Ograve: 'Ò',\n Oacute: 'Ó',\n Ocirc: 'Ô',\n Otilde: 'Õ',\n Ouml: 'Ö',\n Oslash: 'Ø',\n Ugrave: 'Ù',\n Uacute: 'Ú',\n Ucirc: 'Û',\n Uuml: 'Ü',\n Yacute: 'Ý',\n THORN: 'Þ',\n szlig: 'ß',\n agrave: 'à',\n aacute: 'á',\n acirc: 'â',\n atilde: 'ã',\n auml: 'ä',\n aring: 'å',\n aelig: 'æ',\n ccedil: 'ç',\n egrave: 'è',\n eacute: 'é',\n ecirc: 'ê',\n euml: 'ë',\n igrave: 'ì',\n iacute: 'í',\n icirc: 'î',\n iuml: 'ï',\n eth: 'ð',\n ntilde: 'ñ',\n ograve: 'ò',\n oacute: 'ó',\n ocirc: 'ô',\n otilde: 'õ',\n ouml: 'ö',\n oslash: 'ø',\n ugrave: 'ù',\n uacute: 'ú',\n ucirc: 'û',\n uuml: 'ü',\n yacute: 'ý',\n thorn: 'þ',\n yuml: 'ÿ',\n iexcl: '¡',\n iquest: '¿',\n fnof: 'ƒ',\n circ: 'ˆ',\n tilde: '˜',\n OElig: 'Œ',\n oelig: 'œ',\n Scaron: 'Š',\n scaron: 'š',\n Yuml: 'Ÿ',\n ordf: 'ª',\n ordm: 'º',\n macr: '¯',\n acute: '´',\n cedil: '¸',\n sup1: '¹',\n sup2: '²',\n sup3: '³',\n frac14: '¼',\n frac12: '½',\n frac34: '¾',\n spades: '♠',\n clubs: '♣',\n hearts: '♥',\n diams: '♦',\n loz: '◊',\n oline: '‾',\n frasl: '⁄',\n weierp: '℘',\n image: 'ℑ',\n real: 'ℜ',\n alefsym: 'ℵ',\n};\n"],"mappings":"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"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { useDictionary } from "./useDictionary.mjs";
|
|
|
7
7
|
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
8
8
|
import { useTranslation } from "./useTranslation.mjs";
|
|
9
9
|
import { withTranslation } from "./withTranslation.mjs";
|
|
10
|
+
import { IcuTrans, IcuTransWithoutContext } from "./IcuTrans.mjs";
|
|
10
11
|
|
|
11
12
|
// src/index.ts
|
|
12
13
|
const nodesToString = nodesToString$1;
|
|
@@ -21,8 +22,6 @@ const withSSR = withSSR$1;
|
|
|
21
22
|
const Translation = Translation$1;
|
|
22
23
|
const I18nContext = I18nContext$1;
|
|
23
24
|
const TransWithoutContext = Trans;
|
|
24
|
-
const IcuTrans = Trans;
|
|
25
|
-
const IcuTransWithoutContext = Trans;
|
|
26
25
|
|
|
27
26
|
export { I18nContext, I18nextProvider, IcuTrans, IcuTransWithoutContext, Trans, TransWithoutContext, Translation, composeInitialProps, getDefaults, getI18n, getInitialProps, initReactI18next, nodesToString, setDefaults, setI18n, useDictionary, useDictionaryDynamic, useSSR, useTranslation, withSSR, withTranslation };
|
|
28
27
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["nodesToStringImpl","setDefaultsImpl","getDefaultsImpl","setI18nImpl","getI18nImpl","composeInitialPropsImpl","getInitialPropsImpl","useSSRImpl","withSSRImpl","TranslationImpl","I18nContextImpl"],"sources":["../../src/index.ts"],"sourcesContent":["import type {\n composeInitialProps as _composeInitialProps,\n getDefaults as _getDefaults,\n getI18n as _getI18n,\n getInitialProps as _getInitialProps,\n I18nContext as _I18nContext,\n setDefaults as _setDefaults,\n setI18n as _setI18n,\n
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["nodesToStringImpl","setDefaultsImpl","getDefaultsImpl","setI18nImpl","getI18nImpl","composeInitialPropsImpl","getInitialPropsImpl","useSSRImpl","withSSRImpl","TranslationImpl","I18nContextImpl"],"sources":["../../src/index.ts"],"sourcesContent":["import type {\n composeInitialProps as _composeInitialProps,\n getDefaults as _getDefaults,\n getI18n as _getI18n,\n getInitialProps as _getInitialProps,\n I18nContext as _I18nContext,\n setDefaults as _setDefaults,\n setI18n as _setI18n,\n Translation as _Translation,\n TransWithoutContext as _TransWithoutContext,\n useSSR as _useSSR,\n withSSR as _withSSR,\n} from 'react-i18next';\nimport { getI18n as getI18nImpl, setI18n as setI18nImpl } from './globalI18n';\nimport {\n composeInitialProps as composeInitialPropsImpl,\n getDefaults as getDefaultsImpl,\n getInitialProps as getInitialPropsImpl,\n I18nContext as I18nContextImpl,\n nodesToString as nodesToStringImpl,\n setDefaults as setDefaultsImpl,\n Translation as TranslationImpl,\n useSSR as useSSRImpl,\n withSSR as withSSRImpl,\n} from './helpers';\nimport { Trans } from './Trans';\n\n// Re-export common types from react-i18next so consumers don't need both packages\nexport type {\n I18nextProviderProps,\n TransProps,\n UseTranslationOptions,\n UseTranslationResponse,\n WithTranslation,\n WithTranslationProps,\n} from 'react-i18next';\nexport { I18nextProvider } from './I18nextProvider';\nexport { initReactI18next } from './initReactI18next';\nexport { useDictionary } from './useDictionary';\nexport { useDictionaryDynamic } from './useDictionaryDynamic';\nexport { useTranslation } from './useTranslation';\nexport { withTranslation } from './withTranslation';\nexport { Trans };\n\n// Wrap and export all implementation functions.\n// `nodesToString` is not part of react-i18next's public type surface in all\n// supported versions, so the local implementation's inferred type is exposed.\nexport const nodesToString = nodesToStringImpl;\nexport const setDefaults = setDefaultsImpl as typeof _setDefaults;\nexport const getDefaults = getDefaultsImpl as typeof _getDefaults;\nexport const setI18n = setI18nImpl as typeof _setI18n;\nexport const getI18n = getI18nImpl as typeof _getI18n;\nexport const composeInitialProps =\n composeInitialPropsImpl as typeof _composeInitialProps;\nexport const getInitialProps = getInitialPropsImpl as typeof _getInitialProps;\nexport const useSSR = useSSRImpl as typeof _useSSR;\nexport const withSSR = withSSRImpl as typeof _withSSR;\nexport const Translation = TranslationImpl as typeof _Translation;\nexport const I18nContext = I18nContextImpl as typeof _I18nContext;\n\nexport const TransWithoutContext = Trans as typeof _TransWithoutContext;\nexport { IcuTrans, IcuTransWithoutContext } from './IcuTrans';\n"],"mappings":";;;;;;;;;;;;AA+CA,MAAa,gBAAgBA;AAC7B,MAAa,cAAcC;AAC3B,MAAa,cAAcC;AAC3B,MAAa,UAAUC;AACvB,MAAa,UAAUC;AACvB,MAAa,sBACXC;AACF,MAAa,kBAAkBC;AAC/B,MAAa,SAASC;AACtB,MAAa,UAAUC;AACvB,MAAa,cAAcC;AAC3B,MAAa,cAAcC;AAE3B,MAAa,sBAAsB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { createTranslationApi } from "./createTranslationApi.mjs";
|
|
4
|
-
import { useMemo } from "react";
|
|
5
4
|
import { useDictionary as useDictionary$1, useLocale } from "react-intlayer";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
6
|
|
|
7
7
|
// src/useDictionary.ts
|
|
8
8
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { createTranslationApi } from "./createTranslationApi.mjs";
|
|
4
|
-
import { useMemo } from "react";
|
|
5
4
|
import { useDictionaryDynamic as useDictionaryDynamic$1, useLocale } from "react-intlayer";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
6
|
|
|
7
7
|
// src/useDictionaryDynamic.ts
|
|
8
8
|
/**
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { createTranslationApi } from "./createTranslationApi.mjs";
|
|
4
4
|
import { getI18n } from "./globalI18n.mjs";
|
|
5
|
-
import { useMemo } from "react";
|
|
6
5
|
import { useLocale } from "react-intlayer";
|
|
6
|
+
import { useMemo } from "react";
|
|
7
7
|
import { toNamespaceList } from "@intlayer/i18next";
|
|
8
8
|
|
|
9
9
|
// src/useTranslation.ts
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IcuTrans as IcuTrans$1, IcuTransWithoutContext as IcuTransWithoutContext$1 } from "react-i18next";
|
|
2
|
+
/**
|
|
3
|
+
* Drop-in for react-i18next's `IcuTransWithoutContext`: translates
|
|
4
|
+
* `i18nKey` (falling back to `defaultTranslation`) with `values`, then maps
|
|
5
|
+
* its numbered tags (`<0>…</0>`) to the `content` declarations.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* <IcuTransWithoutContext
|
|
10
|
+
* i18nKey="welcome"
|
|
11
|
+
* defaultTranslation="Hello <0>{name}</0>"
|
|
12
|
+
* content={[{ type: 'strong' }]}
|
|
13
|
+
* values={{ name: 'Ann' }}
|
|
14
|
+
* />
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const IcuTransWithoutContext: typeof IcuTransWithoutContext$1;
|
|
18
|
+
/**
|
|
19
|
+
* Drop-in for react-i18next's `IcuTrans`: `IcuTransWithoutContext` with the
|
|
20
|
+
* translation function of the current locale.
|
|
21
|
+
*/
|
|
22
|
+
export declare const IcuTrans: typeof IcuTrans$1;
|
|
23
|
+
//# sourceMappingURL=IcuTrans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IcuTrans.d.ts","names":["UpstreamIcuTransWithoutContext","UpstreamIcuTrans"],"sources":["../../src/IcuTrans.tsx"],"mappings":";;;;;;;;;;;;;;;;qBAyKa,+BAA+BA;;;;;qBAmD/B,iBAAiBC"}
|
package/dist/types/Trans.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DictionaryKeys } from "@intlayer/types/module_augmentation";
|
|
2
1
|
import { TransProps } from "react-i18next";
|
|
3
2
|
import { ReactElement } from "react";
|
|
4
3
|
import { ValidDotPathsFor } from "@intlayer/core/transpiler";
|
|
4
|
+
import { DictionaryKeys } from "@intlayer/types/module_augmentation";
|
|
5
5
|
/**
|
|
6
6
|
* `<Trans>` props for a known dictionary namespace: `i18nKey` is validated
|
|
7
7
|
* against the dictionary's dot-paths, matching the strength of `useIntlayer`.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `react-i18next/augment-react`: type-only module widening React's HTML
|
|
3
|
+
* `children` so `<Trans>` can nest interpolation objects. It keeps
|
|
4
|
+
* react-i18next's augmentation and has no runtime code.
|
|
5
|
+
*/
|
|
6
|
+
import * as UpstreamAugmentReact from "react-i18next/augment-react";
|
|
7
|
+
/** The upstream augmentation module, kept so its declarations apply. */
|
|
8
|
+
export type AugmentReact = typeof UpstreamAugmentReact;
|
|
9
|
+
//# sourceMappingURL=augment-react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"augment-react.d.ts","names":[],"sources":["../../src/augment-react.ts"],"mappings":";;;;;;;YAQY,sBAAsB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TypedTFunction } from "@intlayer/i18next";
|
|
2
|
-
import { DictionaryKeys, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
1
|
import { TOptions } from "i18next";
|
|
2
|
+
import { DictionaryKeys, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
|
+
import { TypedTFunction } from "@intlayer/i18next";
|
|
4
4
|
/** Untyped runtime `t()` produced by {@link createTranslationApi}. */
|
|
5
5
|
export type TranslateFunction = (key: string | string[], optionsOrDefaultValue?: TOptions | string, extraOptions?: TOptions) => string;
|
|
6
6
|
/**
|
|
@@ -44,7 +44,8 @@ export type CreateTranslationApiParams = {
|
|
|
44
44
|
/** Default namespace (dictionary key) for `t()` lookups. */
|
|
45
45
|
namespace: string;
|
|
46
46
|
/** Optional prefix prepended to every `t()` key. */
|
|
47
|
-
|
|
47
|
+
/** Key prefix, or a selector designating it (`$ => $.hero`). */
|
|
48
|
+
keyPrefix?: unknown;
|
|
48
49
|
/**
|
|
49
50
|
* Pre-resolved dictionary content for `namespace` — supplied by the
|
|
50
51
|
* build-optimized `useDictionary` / `useDictionaryDynamic` variants so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTranslationApi.d.ts","names":[],"sources":["../../src/createTranslationApi.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"createTranslationApi.d.ts","names":[],"sources":["../../src/createTranslationApi.ts"],"mappings":";;;;YAiBY,qBACV,wBACA,wBAAwB,mBACxB,eAAe;;;;;;;YASL,gBAAgB,MAAM,qBAAqB,KACrD;EAGA,GAAG;EACH;KACG,UAAU,gBACT,qCACA,gBAAgB,IACf,eAAe;KACjB,0BAA0B,wBAAwB;;;;YAK3C,uBAAuB,MAAM;EACvC,GAAG;EACH,MAAM,gBAAgB;EACtB;;;YAIU;EACV;EACA;EACA;EACA;EACA,iBAAiB,wBAAwB;EACzC,MAAM;EACN,SAAS,aAAa,gBAAgB;EACtC,GAAG;EACH,YACE,0BACA,oCACI,aAAa,eAAe;;YAGxB;;EAEV,QAAQ;;EAER,YAAY,WAAW;;EAEvB,kBAAkB;;EAElB;;;EAGA;;;;;;EAMA;;;;;;;;;;;;;;;qBAgBW,yBAAoB,QAAA,WAAA,kBAAA,WAAA,WAAA,qBAO9B;EACD,WAAW;EACX,MAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlEntities.d.ts","names":[],"sources":["../../src/htmlEntities.ts"],"mappings":";;;;qBAIa,eAAe"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ import { useDictionary } from "./useDictionary.js";
|
|
|
6
6
|
import { useDictionaryDynamic } from "./useDictionaryDynamic.js";
|
|
7
7
|
import { useTranslation } from "./useTranslation.js";
|
|
8
8
|
import { withTranslation } from "./withTranslation.js";
|
|
9
|
-
import {
|
|
9
|
+
import { IcuTrans, IcuTransWithoutContext } from "./IcuTrans.js";
|
|
10
|
+
import { I18nContext as I18nContext$1, I18nextProviderProps, TransProps, TransWithoutContext as TransWithoutContext$1, Translation as Translation$1, UseTranslationOptions, UseTranslationResponse, WithTranslation, WithTranslationProps, composeInitialProps as composeInitialProps$1, getDefaults as getDefaults$1, getI18n as getI18n$1, getInitialProps as getInitialProps$1, setDefaults as setDefaults$1, setI18n as setI18n$1, useSSR as useSSR$1, withSSR as withSSR$1 } from "react-i18next";
|
|
10
11
|
export declare const nodesToString: typeof nodesToString$1;
|
|
11
12
|
export declare const setDefaults: typeof setDefaults$1;
|
|
12
13
|
export declare const getDefaults: typeof getDefaults$1;
|
|
@@ -19,7 +20,5 @@ export declare const withSSR: typeof withSSR$1;
|
|
|
19
20
|
export declare const Translation: typeof Translation$1;
|
|
20
21
|
export declare const I18nContext: typeof I18nContext$1;
|
|
21
22
|
export declare const TransWithoutContext: typeof TransWithoutContext$1;
|
|
22
|
-
export
|
|
23
|
-
export declare const IcuTransWithoutContext: typeof Trans$1;
|
|
24
|
-
export { I18nextProvider, type I18nextProviderProps, Trans, type TransProps, type UseTranslationOptions, type UseTranslationResponse, type WithTranslation, type WithTranslationProps, initReactI18next, useDictionary, useDictionaryDynamic, useTranslation, withTranslation };
|
|
23
|
+
export { I18nextProvider, type I18nextProviderProps, IcuTrans, IcuTransWithoutContext, Trans, type TransProps, type UseTranslationOptions, type UseTranslationResponse, type WithTranslation, type WithTranslationProps, initReactI18next, useDictionary, useDictionaryDynamic, useTranslation, withTranslation };
|
|
25
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["nodesToStringImpl","_setDefaults","_getDefaults","_setI18n","_getI18n","_composeInitialProps","_getInitialProps","_useSSR","_withSSR","_Translation","_I18nContext","_TransWithoutContext"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["nodesToStringImpl","_setDefaults","_getDefaults","_setI18n","_getI18n","_composeInitialProps","_getInitialProps","_useSSR","_withSSR","_Translation","_I18nContext","_TransWithoutContext"],"sources":["../../src/index.ts"],"mappings":";;;;;;;;;;qBA+Ca,sBAAaA;qBACb,oBAAwCC;qBACxC,oBAAwCC;qBACxC,gBAAgCC;qBAChC,gBAAgCC;qBAChC,4BACuBC;qBACvB,wBAAgDC;qBAChD,eAA8BC;qBAC9B,gBAAgCC;qBAChC,oBAAwCC;qBACxC,oBAAwCC;qBAExC,4BAAsCC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TypedTranslationResult } from "./createTranslationApi.js";
|
|
2
|
+
import { UseTranslationOptions } from "react-i18next";
|
|
3
|
+
import { DictionaryKeys } from "@intlayer/types/module_augmentation";
|
|
2
4
|
import { ScopedTFunction, TypedTFunction } from "@intlayer/i18next";
|
|
3
5
|
import { Dictionary } from "@intlayer/types/dictionary";
|
|
4
|
-
import { DictionaryKeys } from "@intlayer/types/module_augmentation";
|
|
5
|
-
import { UseTranslationOptions } from "react-i18next";
|
|
6
6
|
/**
|
|
7
7
|
* Overload set for {@link useDictionary}: without a key prefix the returned
|
|
8
8
|
* `t()` is typed against the dictionary's dot-paths; with a prefix (string or
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TypedTranslationResult } from "./createTranslationApi.js";
|
|
2
|
+
import { UseTranslationOptions } from "react-i18next";
|
|
3
|
+
import { DictionaryKeys, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
2
4
|
import { ScopedTFunction, TypedTFunction } from "@intlayer/i18next";
|
|
3
5
|
import { Dictionary } from "@intlayer/types/dictionary";
|
|
4
|
-
import { DictionaryKeys, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
5
|
-
import { UseTranslationOptions } from "react-i18next";
|
|
6
6
|
/**
|
|
7
7
|
* Overload set for {@link useDictionaryDynamic}: without a key prefix the
|
|
8
8
|
* returned `t()` is typed against the dictionary's dot-paths; with a prefix
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TypedTranslationResult } from "./createTranslationApi.js";
|
|
2
|
-
import { ScopedTFunction, TypedTFunction } from "@intlayer/i18next";
|
|
3
|
-
import { DictionaryKeys } from "@intlayer/types/module_augmentation";
|
|
4
2
|
import { UseTranslationOptions } from "react-i18next";
|
|
3
|
+
import { DictionaryKeys } from "@intlayer/types/module_augmentation";
|
|
4
|
+
import { ScopedTFunction, TypedTFunction } from "@intlayer/i18next";
|
|
5
5
|
/**
|
|
6
6
|
* Overload set for {@link useTranslation}: with a `keyPrefix` option the
|
|
7
7
|
* returned `t()` accepts relative dot-paths under the prefix; otherwise keys
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/react-i18next",
|
|
3
|
-
"version": "9.9.
|
|
3
|
+
"version": "9.9.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "react-i18next API adapter for intlayer — useTranslation, Trans, withTranslation, I18nextProvider backed by react-intlayer",
|
|
6
6
|
"keywords": [
|
|
@@ -42,6 +42,18 @@
|
|
|
42
42
|
"types": "dist/types/index.d.ts",
|
|
43
43
|
"typesVersions": {
|
|
44
44
|
"*": {
|
|
45
|
+
"TransWithoutContext": [
|
|
46
|
+
"./dist/types/TransWithoutContext.d.ts"
|
|
47
|
+
],
|
|
48
|
+
"IcuTransWithoutContext": [
|
|
49
|
+
"./dist/types/IcuTransWithoutContext.d.ts"
|
|
50
|
+
],
|
|
51
|
+
"initReactI18next": [
|
|
52
|
+
"./dist/types/initReactI18next.d.ts"
|
|
53
|
+
],
|
|
54
|
+
"augment-react": [
|
|
55
|
+
"./dist/types/augment-react.d.ts"
|
|
56
|
+
],
|
|
45
57
|
"plugin": [
|
|
46
58
|
"./dist/types/plugin/index.d.ts"
|
|
47
59
|
]
|
|
@@ -52,6 +64,26 @@
|
|
|
52
64
|
"types": "./dist/types/index.d.ts",
|
|
53
65
|
"import": "./dist/esm/index.mjs"
|
|
54
66
|
},
|
|
67
|
+
"./TransWithoutContext": {
|
|
68
|
+
"types": "./dist/types/TransWithoutContext.d.ts",
|
|
69
|
+
"require": "./dist/cjs/TransWithoutContext.cjs",
|
|
70
|
+
"import": "./dist/esm/TransWithoutContext.mjs"
|
|
71
|
+
},
|
|
72
|
+
"./IcuTransWithoutContext": {
|
|
73
|
+
"types": "./dist/types/IcuTransWithoutContext.d.ts",
|
|
74
|
+
"require": "./dist/cjs/IcuTransWithoutContext.cjs",
|
|
75
|
+
"import": "./dist/esm/IcuTransWithoutContext.mjs"
|
|
76
|
+
},
|
|
77
|
+
"./initReactI18next": {
|
|
78
|
+
"types": "./dist/types/initReactI18next.d.ts",
|
|
79
|
+
"require": "./dist/cjs/initReactI18next.cjs",
|
|
80
|
+
"import": "./dist/esm/initReactI18next.mjs"
|
|
81
|
+
},
|
|
82
|
+
"./augment-react": {
|
|
83
|
+
"types": "./dist/types/augment-react.d.ts",
|
|
84
|
+
"require": "./dist/cjs/augment-react.cjs",
|
|
85
|
+
"import": "./dist/esm/augment-react.mjs"
|
|
86
|
+
},
|
|
55
87
|
"./plugin": {
|
|
56
88
|
"types": "./dist/types/plugin/index.d.ts",
|
|
57
89
|
"import": "./dist/esm/plugin/index.mjs"
|
|
@@ -77,16 +109,16 @@
|
|
|
77
109
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
78
110
|
},
|
|
79
111
|
"dependencies": {
|
|
80
|
-
"@intlayer/config": "9.9.
|
|
81
|
-
"@intlayer/core": "9.9.
|
|
82
|
-
"@intlayer/engine": "9.9.
|
|
83
|
-
"@intlayer/i18next": "9.9.
|
|
84
|
-
"@intlayer/types": "9.9.
|
|
85
|
-
"react-intlayer": "9.9.
|
|
86
|
-
"vite-intlayer": "9.9.
|
|
112
|
+
"@intlayer/config": "9.9.4",
|
|
113
|
+
"@intlayer/core": "9.9.4",
|
|
114
|
+
"@intlayer/engine": "9.9.4",
|
|
115
|
+
"@intlayer/i18next": "9.9.4",
|
|
116
|
+
"@intlayer/types": "9.9.4",
|
|
117
|
+
"react-intlayer": "9.9.4",
|
|
118
|
+
"vite-intlayer": "9.9.4"
|
|
87
119
|
},
|
|
88
120
|
"devDependencies": {
|
|
89
|
-
"@intlayer/dictionaries-entry": "9.9.
|
|
121
|
+
"@intlayer/dictionaries-entry": "9.9.4",
|
|
90
122
|
"@types/node": "^26",
|
|
91
123
|
"@types/react": "19.3.3",
|
|
92
124
|
"@utils/compat-api-parity": "1.0.0",
|