@intlayer/react-intl 8.12.5-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +330 -0
- package/dist/cjs/FormattedComponents.cjs +131 -0
- package/dist/cjs/FormattedComponents.cjs.map +1 -0
- package/dist/cjs/FormattedMessage.cjs +45 -0
- package/dist/cjs/FormattedMessage.cjs.map +1 -0
- package/dist/cjs/IntlProvider.cjs +38 -0
- package/dist/cjs/IntlProvider.cjs.map +1 -0
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/context.cjs +16 -0
- package/dist/cjs/context.cjs.map +1 -0
- package/dist/cjs/createIntl.cjs +46 -0
- package/dist/cjs/createIntl.cjs.map +1 -0
- package/dist/cjs/createIntlObject.cjs +132 -0
- package/dist/cjs/createIntlObject.cjs.map +1 -0
- package/dist/cjs/defineMessages.cjs +20 -0
- package/dist/cjs/defineMessages.cjs.map +1 -0
- package/dist/cjs/errors.cjs +85 -0
- package/dist/cjs/errors.cjs.map +1 -0
- package/dist/cjs/index.cjs +40 -0
- package/dist/cjs/plugin/index.cjs +57 -0
- package/dist/cjs/plugin/index.cjs.map +1 -0
- package/dist/cjs/useIntl.cjs +33 -0
- package/dist/cjs/useIntl.cjs.map +1 -0
- package/dist/esm/FormattedComponents.mjs +119 -0
- package/dist/esm/FormattedComponents.mjs.map +1 -0
- package/dist/esm/FormattedMessage.mjs +44 -0
- package/dist/esm/FormattedMessage.mjs.map +1 -0
- package/dist/esm/IntlProvider.mjs +37 -0
- package/dist/esm/IntlProvider.mjs.map +1 -0
- package/dist/esm/context.mjs +14 -0
- package/dist/esm/context.mjs.map +1 -0
- package/dist/esm/createIntl.mjs +44 -0
- package/dist/esm/createIntl.mjs.map +1 -0
- package/dist/esm/createIntlObject.mjs +131 -0
- package/dist/esm/createIntlObject.mjs.map +1 -0
- package/dist/esm/defineMessages.mjs +17 -0
- package/dist/esm/defineMessages.mjs.map +1 -0
- package/dist/esm/errors.mjs +77 -0
- package/dist/esm/errors.mjs.map +1 -0
- package/dist/esm/index.mjs +12 -0
- package/dist/esm/plugin/index.mjs +53 -0
- package/dist/esm/plugin/index.mjs.map +1 -0
- package/dist/esm/useIntl.mjs +32 -0
- package/dist/esm/useIntl.mjs.map +1 -0
- package/dist/types/FormattedComponents.d.ts +67 -0
- package/dist/types/FormattedComponents.d.ts.map +1 -0
- package/dist/types/FormattedMessage.d.ts +28 -0
- package/dist/types/FormattedMessage.d.ts.map +1 -0
- package/dist/types/IntlProvider.d.ts +16 -0
- package/dist/types/IntlProvider.d.ts.map +1 -0
- package/dist/types/context.d.ts +13 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/createIntl.d.ts +35 -0
- package/dist/types/createIntl.d.ts.map +1 -0
- package/dist/types/createIntlObject.d.ts +15 -0
- package/dist/types/createIntlObject.d.ts.map +1 -0
- package/dist/types/defineMessages.d.ts +18 -0
- package/dist/types/defineMessages.d.ts.map +1 -0
- package/dist/types/errors.d.ts +56 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/plugin/index.d.ts +23 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/useIntl.d.ts +21 -0
- package/dist/types/useIntl.d.ts.map +1 -0
- package/package.json +117 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let react = require("react");
|
|
3
|
+
|
|
4
|
+
//#region src/context.tsx
|
|
5
|
+
/**
|
|
6
|
+
* React context holding the active intlayer-backed `IntlShape` instance.
|
|
7
|
+
* Populated by {@link IntlProvider}; consumed by {@link useIntl}.
|
|
8
|
+
*/
|
|
9
|
+
const IntlContext = (0, react.createContext)(null);
|
|
10
|
+
/** The raw `React.Provider<IntlShape>` — same as `IntlContext.Provider`. */
|
|
11
|
+
const RawIntlProvider = IntlContext.Provider;
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.IntlContext = IntlContext;
|
|
15
|
+
exports.RawIntlProvider = RawIntlProvider;
|
|
16
|
+
//# sourceMappingURL=context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.cjs","names":[],"sources":["../../src/context.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport type { IntlShape } from 'react-intl';\n\n/**\n * React context holding the active intlayer-backed `IntlShape` instance.\n * Populated by {@link IntlProvider}; consumed by {@link useIntl}.\n */\nexport const IntlContext = createContext<IntlShape>(\n null as unknown as IntlShape\n);\n\n/** The raw `React.Provider<IntlShape>` — same as `IntlContext.Provider`. */\nexport const RawIntlProvider = IntlContext.Provider;\n"],"mappings":";;;;;;;;AAOA,MAAa,uCACX,IACF;;AAGA,MAAa,kBAAkB,YAAY"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_createIntlObject = require('./createIntlObject.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/createIntl.ts
|
|
5
|
+
/**
|
|
6
|
+
* Drop-in for react-intl's `createIntlCache`.
|
|
7
|
+
*
|
|
8
|
+
* Returns an empty cache token. In the intlayer compat adapter, formatter
|
|
9
|
+
* instances are not pooled (all backed by native `Intl.*` constructors), so
|
|
10
|
+
* the cache object serves only as an API-compatibility token.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated
|
|
13
|
+
* Has no practical effect with intlayer — no formatter pooling is needed.
|
|
14
|
+
*/
|
|
15
|
+
const createIntlCache = () => ({
|
|
16
|
+
dateTime: {},
|
|
17
|
+
number: {},
|
|
18
|
+
message: {},
|
|
19
|
+
relativeTime: {},
|
|
20
|
+
pluralRules: {},
|
|
21
|
+
list: {},
|
|
22
|
+
displayNames: {}
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Drop-in for react-intl's `createIntl`.
|
|
26
|
+
*
|
|
27
|
+
* Creates an `IntlShape` instance backed by intlayer compiled dictionaries
|
|
28
|
+
* for the given `locale`. Use this in non-React contexts (e.g. server-side
|
|
29
|
+
* route handlers).
|
|
30
|
+
*
|
|
31
|
+
* `messages`, `formats`, `timeZone`, `onError`, and `cache` are accepted for
|
|
32
|
+
* API compatibility but have no effect — Intlayer uses its own compiled
|
|
33
|
+
* dictionaries.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const intl = createIntl({ locale: 'en' });
|
|
38
|
+
* intl.formatMessage({ id: 'home.title' });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
const createIntl = ({ locale }, _cache) => require_createIntlObject.createIntlObject(locale);
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
exports.createIntl = createIntl;
|
|
45
|
+
exports.createIntlCache = createIntlCache;
|
|
46
|
+
//# sourceMappingURL=createIntl.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createIntl.cjs","names":["createIntlObject"],"sources":["../../src/createIntl.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type {\n createIntl as _createIntl,\n createIntlCache as _createIntlCache,\n IntlCache,\n IntlConfig,\n IntlShape,\n} from 'react-intl';\nimport { createIntlObject } from './createIntlObject';\n\n/**\n * Drop-in for react-intl's `createIntlCache`.\n *\n * Returns an empty cache token. In the intlayer compat adapter, formatter\n * instances are not pooled (all backed by native `Intl.*` constructors), so\n * the cache object serves only as an API-compatibility token.\n *\n * @deprecated\n * Has no practical effect with intlayer — no formatter pooling is needed.\n */\nexport const createIntlCache: typeof _createIntlCache = (): IntlCache =>\n ({\n dateTime: {},\n number: {},\n message: {},\n relativeTime: {},\n pluralRules: {},\n list: {},\n displayNames: {},\n }) as IntlCache;\n\n/**\n * Drop-in for react-intl's `createIntl`.\n *\n * Creates an `IntlShape` instance backed by intlayer compiled dictionaries\n * for the given `locale`. Use this in non-React contexts (e.g. server-side\n * route handlers).\n *\n * `messages`, `formats`, `timeZone`, `onError`, and `cache` are accepted for\n * API compatibility but have no effect — Intlayer uses its own compiled\n * dictionaries.\n *\n * @example\n * ```ts\n * const intl = createIntl({ locale: 'en' });\n * intl.formatMessage({ id: 'home.title' });\n * ```\n */\nexport const createIntl: typeof _createIntl = (\n { locale }: IntlConfig,\n _cache?: IntlCache\n): IntlShape => createIntlObject(locale as LocalesValues);\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAa,yBACV;CACC,UAAU,CAAC;CACX,QAAQ,CAAC;CACT,SAAS,CAAC;CACV,cAAc,CAAC;CACf,aAAa,CAAC;CACd,MAAM,CAAC;CACP,cAAc,CAAC;AACjB;;;;;;;;;;;;;;;;;;AAmBF,MAAa,cACX,EAAE,UACF,WACcA,0CAAiB,MAAuB"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let react = require("react");
|
|
3
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
4
|
+
let _intlayer_core_messageFormat = require("@intlayer/core/messageFormat");
|
|
5
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
+
|
|
7
|
+
//#region src/createIntlObject.tsx
|
|
8
|
+
/** Splits a full dotted id into the dictionary key and remaining path. */
|
|
9
|
+
const splitId = (id) => {
|
|
10
|
+
const dotIndex = id.indexOf(".");
|
|
11
|
+
if (dotIndex === -1) return {
|
|
12
|
+
dictionaryKey: id,
|
|
13
|
+
path: ""
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
dictionaryKey: id.slice(0, dotIndex),
|
|
17
|
+
path: id.slice(dotIndex + 1)
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const navigatePath = (object, path) => {
|
|
21
|
+
if (!path) return object;
|
|
22
|
+
const parts = path.split(".");
|
|
23
|
+
let current = object;
|
|
24
|
+
for (const part of parts) {
|
|
25
|
+
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
26
|
+
current = current[part];
|
|
27
|
+
}
|
|
28
|
+
return current;
|
|
29
|
+
};
|
|
30
|
+
/** Looks up a message value by full dotted id; first segment = dictionary key. */
|
|
31
|
+
const lookupMessage = (id, locale) => {
|
|
32
|
+
const { dictionaryKey, path } = splitId(id);
|
|
33
|
+
if (!dictionaryKey) return void 0;
|
|
34
|
+
try {
|
|
35
|
+
return navigatePath((0, _intlayer_core_interpreter.getIntlayer)(dictionaryKey, locale), path);
|
|
36
|
+
} catch {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/** Maps tagged tokens to React nodes using the provided renderer functions. */
|
|
41
|
+
const renderRichTokens = (tokens, renderers) => tokens.map((token, tokenIndex) => {
|
|
42
|
+
if (typeof token === "string") return token;
|
|
43
|
+
const children = renderRichTokens(token.children, renderers);
|
|
44
|
+
const renderer = renderers[token.tag];
|
|
45
|
+
if (typeof renderer === "function") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: renderer(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children })) }, tokenIndex);
|
|
46
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children }, tokenIndex);
|
|
47
|
+
});
|
|
48
|
+
/** Partitions values into scalar interpolation params and tag renderers. */
|
|
49
|
+
const splitRichValues = (values) => {
|
|
50
|
+
const scalarValues = {};
|
|
51
|
+
const renderers = {};
|
|
52
|
+
for (const [key, value] of Object.entries(values)) if (typeof value === "function") renderers[key] = value;
|
|
53
|
+
else scalarValues[key] = value;
|
|
54
|
+
return {
|
|
55
|
+
scalarValues,
|
|
56
|
+
renderers
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const isRichValues = (values) => Object.values(values).some((value) => typeof value === "function");
|
|
60
|
+
/**
|
|
61
|
+
* Builds an intlayer-backed `IntlShape` object for the given locale.
|
|
62
|
+
*
|
|
63
|
+
* - Translation ids use the first dot-path segment as the dictionary key.
|
|
64
|
+
* - Full ICU MessageFormat syntax is supported via `@intlayer/core/messageFormat`.
|
|
65
|
+
* - Rich text tags (`<b>chunks</b>`) are resolved through render functions in `values`.
|
|
66
|
+
*/
|
|
67
|
+
const createIntlObject = (locale) => {
|
|
68
|
+
const localeString = locale;
|
|
69
|
+
const formatMessage = (descriptor, values) => {
|
|
70
|
+
const { id = "", defaultMessage } = descriptor;
|
|
71
|
+
const rawValue = lookupMessage(id, locale);
|
|
72
|
+
const messageTemplate = rawValue !== void 0 && rawValue !== null ? rawValue : typeof defaultMessage === "string" ? defaultMessage : id;
|
|
73
|
+
if (!values || !isRichValues(values)) return (0, _intlayer_core_messageFormat.resolveMessage)(messageTemplate, values ?? {}, locale, "icu") ?? id;
|
|
74
|
+
const { scalarValues, renderers } = splitRichValues(values);
|
|
75
|
+
return renderRichTokens((0, _intlayer_core_messageFormat.parseTaggedMessage)((0, _intlayer_core_messageFormat.resolveMessage)(messageTemplate, scalarValues, locale, "icu") ?? id), renderers);
|
|
76
|
+
};
|
|
77
|
+
const toDate = (value) => value instanceof Date ? value : new Date(value);
|
|
78
|
+
const formatDate = (value, options) => {
|
|
79
|
+
if (value === void 0 || value === null) return "";
|
|
80
|
+
return new Intl.DateTimeFormat(localeString, options).format(toDate(value));
|
|
81
|
+
};
|
|
82
|
+
const formatNumber = (value, options) => new Intl.NumberFormat(localeString, options).format(value);
|
|
83
|
+
const formatPlural = (value, options) => new Intl.PluralRules(localeString, options).select(value);
|
|
84
|
+
const formatList = (list, options) => {
|
|
85
|
+
const strings = Array.from(list).filter((item) => typeof item === "string");
|
|
86
|
+
return new Intl.ListFormat(localeString, options).format(strings);
|
|
87
|
+
};
|
|
88
|
+
const formatListToParts = (list, options) => {
|
|
89
|
+
const strings = Array.from(list).filter((item) => typeof item === "string");
|
|
90
|
+
return new Intl.ListFormat(localeString, options).formatToParts(strings);
|
|
91
|
+
};
|
|
92
|
+
const formatDisplayName = (value, options) => new Intl.DisplayNames([localeString], options ?? { type: "language" }).of(value);
|
|
93
|
+
const formatRelativeTime = (value, unit, options) => new Intl.RelativeTimeFormat(localeString, {
|
|
94
|
+
numeric: "auto",
|
|
95
|
+
...options
|
|
96
|
+
}).format(value, unit ?? "second");
|
|
97
|
+
const formatDateTimeRange = (from, to, options) => new Intl.DateTimeFormat(localeString, options).formatRange(toDate(from), toDate(to));
|
|
98
|
+
const formatDateToParts = (value, options) => new Intl.DateTimeFormat(localeString, options).formatToParts(typeof value === "string" ? new Date(value) : value);
|
|
99
|
+
const formatNumberToParts = (value, options) => new Intl.NumberFormat(localeString, options).formatToParts(value);
|
|
100
|
+
return {
|
|
101
|
+
locale: localeString,
|
|
102
|
+
defaultLocale: localeString,
|
|
103
|
+
messages: {},
|
|
104
|
+
formats: {},
|
|
105
|
+
defaultFormats: {},
|
|
106
|
+
timeZone: void 0,
|
|
107
|
+
textComponent: react.Fragment,
|
|
108
|
+
wrapRichTextChunksInFragment: false,
|
|
109
|
+
fallbackOnEmptyString: true,
|
|
110
|
+
onError: () => {},
|
|
111
|
+
onWarn: () => {},
|
|
112
|
+
formatters: {},
|
|
113
|
+
formatMessage,
|
|
114
|
+
$t: formatMessage,
|
|
115
|
+
formatDate,
|
|
116
|
+
formatTime: formatDate,
|
|
117
|
+
formatNumber,
|
|
118
|
+
formatPlural,
|
|
119
|
+
formatList,
|
|
120
|
+
formatListToParts,
|
|
121
|
+
formatDisplayName,
|
|
122
|
+
formatRelativeTime,
|
|
123
|
+
formatDateTimeRange,
|
|
124
|
+
formatDateToParts,
|
|
125
|
+
formatTimeToParts: formatDateToParts,
|
|
126
|
+
formatNumberToParts
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
exports.createIntlObject = createIntlObject;
|
|
132
|
+
//# sourceMappingURL=createIntlObject.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createIntlObject.cjs","names":["Fragment"],"sources":["../../src/createIntlObject.tsx"],"sourcesContent":["import { getIntlayer } from '@intlayer/core/interpreter';\nimport {\n type MessageValues,\n parseTaggedMessage,\n resolveMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { Fragment, type ReactNode } from 'react';\nimport type { IntlShape, MessageDescriptor } from 'react-intl';\n\ntype RichRenderer = (chunks: ReactNode) => ReactNode;\n\n/** Splits a full dotted id into the dictionary key and remaining path. */\nconst splitId = (id: string): { dictionaryKey: string; path: string } => {\n const dotIndex = id.indexOf('.');\n if (dotIndex === -1) return { dictionaryKey: id, path: '' };\n return {\n dictionaryKey: id.slice(0, dotIndex),\n path: id.slice(dotIndex + 1),\n };\n};\n\nconst navigatePath = (object: unknown, path: string): unknown => {\n if (!path) return object;\n const parts = path.split('.');\n let current: unknown = object;\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/** Looks up a message value by full dotted id; first segment = dictionary key. */\nconst lookupMessage = (id: string, locale: LocalesValues): unknown => {\n const { dictionaryKey, path } = splitId(id);\n if (!dictionaryKey) return undefined;\n try {\n const dictionary = getIntlayer(dictionaryKey as DictionaryKeys, locale);\n return navigatePath(dictionary, path);\n } catch {\n return undefined;\n }\n};\n\n/** Maps tagged tokens to React nodes using the provided renderer functions. */\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 const children = renderRichTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n if (typeof renderer === 'function') {\n return (\n <Fragment key={tokenIndex}>\n {(renderer as RichRenderer)(<>{children}</>)}\n </Fragment>\n );\n }\n return <Fragment key={tokenIndex}>{children}</Fragment>;\n });\n\n/** Partitions values into scalar interpolation params 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 for (const [key, value] of Object.entries(values)) {\n if (typeof value === 'function') renderers[key] = value;\n else scalarValues[key] = value as MessageValues[string];\n }\n return { scalarValues, renderers };\n};\n\nconst isRichValues = (values: Record<string, unknown>): boolean =>\n Object.values(values).some((value) => typeof value === 'function');\n\n/**\n * Builds an intlayer-backed `IntlShape` object for the given locale.\n *\n * - Translation ids use the first dot-path segment as the dictionary key.\n * - Full ICU MessageFormat syntax is supported via `@intlayer/core/messageFormat`.\n * - Rich text tags (`<b>chunks</b>`) are resolved through render functions in `values`.\n */\nexport const createIntlObject = (locale: LocalesValues): IntlShape => {\n const localeString = locale as string;\n\n const formatMessage = (\n descriptor: MessageDescriptor,\n values?: Record<string, unknown>\n ): string | ReactNode[] => {\n const { id = '', defaultMessage } = descriptor;\n const rawValue = lookupMessage(id, locale);\n const messageTemplate =\n rawValue !== undefined && rawValue !== null\n ? (rawValue as string)\n : typeof defaultMessage === 'string'\n ? defaultMessage\n : id;\n\n if (!values || !isRichValues(values)) {\n return (\n resolveMessage(\n messageTemplate,\n (values ?? {}) as MessageValues,\n locale,\n 'icu'\n ) ?? id\n );\n }\n\n const { scalarValues, renderers } = splitRichValues(values);\n const message =\n resolveMessage(messageTemplate, scalarValues, locale, 'icu') ?? id;\n return renderRichTokens(parseTaggedMessage(message), renderers);\n };\n\n const toDate = (value: Date | number | string): Date =>\n value instanceof Date ? value : new Date(value);\n\n const formatDate = (\n value: string | number | Date | undefined,\n options?: Intl.DateTimeFormatOptions\n ): string => {\n if (value === undefined || value === null) return '';\n return new Intl.DateTimeFormat(localeString, options).format(toDate(value));\n };\n\n const formatNumber = (\n value: number | bigint,\n options?: Intl.NumberFormatOptions\n ): string => new Intl.NumberFormat(localeString, options).format(value);\n\n const formatPlural = (\n value: number,\n options?: Intl.PluralRulesOptions\n ): Intl.LDMLPluralRule =>\n new Intl.PluralRules(localeString, options).select(value);\n\n const formatList = (\n list: Iterable<unknown> | readonly unknown[],\n options?: Intl.ListFormatOptions\n ): string => {\n const strings = Array.from(list).filter(\n (item): item is string => typeof item === 'string'\n );\n return new Intl.ListFormat(localeString, options).format(strings);\n };\n\n const formatListToParts = (\n list: Iterable<unknown> | readonly unknown[],\n options?: Intl.ListFormatOptions\n ): ReturnType<Intl.ListFormat['formatToParts']> => {\n const strings = Array.from(list).filter(\n (item): item is string => typeof item === 'string'\n );\n return new Intl.ListFormat(localeString, options).formatToParts(strings);\n };\n\n const formatDisplayName = (\n value: string,\n options?: Intl.DisplayNamesOptions\n ): string | undefined =>\n new Intl.DisplayNames([localeString], options ?? { type: 'language' }).of(\n value\n );\n\n const formatRelativeTime = (\n value: number,\n unit?: Intl.RelativeTimeFormatUnit,\n options?: Intl.RelativeTimeFormatOptions\n ): string =>\n new Intl.RelativeTimeFormat(localeString, {\n numeric: 'auto',\n ...options,\n }).format(value, unit ?? 'second');\n\n const formatDateTimeRange = (\n from: Date | number,\n to: Date | number,\n options?: Intl.DateTimeFormatOptions\n ): string =>\n new Intl.DateTimeFormat(localeString, options).formatRange(\n toDate(from),\n toDate(to)\n );\n\n const formatDateToParts = (\n value: Parameters<Intl.DateTimeFormat['format']>[0] | string,\n options?: Intl.DateTimeFormatOptions\n ): Intl.DateTimeFormatPart[] =>\n new Intl.DateTimeFormat(localeString, options).formatToParts(\n typeof value === 'string' ? new Date(value) : value\n );\n\n const formatNumberToParts = (\n value: number | bigint,\n options?: Intl.NumberFormatOptions\n ): Intl.NumberFormatPart[] =>\n new Intl.NumberFormat(localeString, options).formatToParts(value);\n\n /** Alias of `formatMessage` — provided for `@formatjs/intl` v4 compatibility. */\n const $t = formatMessage as IntlShape['$t'];\n\n return {\n locale: localeString,\n defaultLocale: localeString,\n messages: {},\n formats: {},\n defaultFormats: {},\n timeZone: undefined,\n textComponent: Fragment,\n wrapRichTextChunksInFragment: false,\n fallbackOnEmptyString: true,\n onError: () => {},\n onWarn: () => {},\n formatters: {} as IntlShape['formatters'],\n formatMessage: formatMessage as IntlShape['formatMessage'],\n $t,\n formatDate,\n formatTime: formatDate,\n formatNumber,\n formatPlural,\n formatList: formatList as IntlShape['formatList'],\n formatListToParts: formatListToParts as IntlShape['formatListToParts'],\n formatDisplayName: formatDisplayName as IntlShape['formatDisplayName'],\n formatRelativeTime,\n formatDateTimeRange,\n formatDateToParts: formatDateToParts as IntlShape['formatDateToParts'],\n formatTimeToParts: formatDateToParts as IntlShape['formatTimeToParts'],\n formatNumberToParts:\n formatNumberToParts as IntlShape['formatNumberToParts'],\n } as unknown as IntlShape;\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/defineMessages.ts
|
|
4
|
+
/**
|
|
5
|
+
* Drop-in for react-intl's `defineMessages`.
|
|
6
|
+
* Identity function — returns the map unchanged.
|
|
7
|
+
* Exists so that IDEs and the intlayer analyzer can locate message ids
|
|
8
|
+
* at source-analysis time.
|
|
9
|
+
*/
|
|
10
|
+
const defineMessages = (messages) => messages;
|
|
11
|
+
/**
|
|
12
|
+
* Drop-in for react-intl's `defineMessage`.
|
|
13
|
+
* Identity function — returns the descriptor unchanged.
|
|
14
|
+
*/
|
|
15
|
+
const defineMessage = (message) => message;
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.defineMessage = defineMessage;
|
|
19
|
+
exports.defineMessages = defineMessages;
|
|
20
|
+
//# sourceMappingURL=defineMessages.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineMessages.cjs","names":[],"sources":["../../src/defineMessages.ts"],"sourcesContent":["import type {\n defineMessage as _defineMessage,\n defineMessages as _defineMessages,\n} from 'react-intl';\n\n/**\n * Drop-in for react-intl's `defineMessages`.\n * Identity function — returns the map unchanged.\n * Exists so that IDEs and the intlayer analyzer can locate message ids\n * at source-analysis time.\n */\nexport const defineMessages: typeof _defineMessages = (messages) => messages;\n\n/**\n * Drop-in for react-intl's `defineMessage`.\n * Identity function — returns the descriptor unchanged.\n */\nexport const defineMessage: typeof _defineMessage = (message) => message;\n"],"mappings":";;;;;;;;;AAWA,MAAa,kBAA0C,aAAa;;;;;AAMpE,MAAa,iBAAwC,YAAY"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/errors.ts
|
|
4
|
+
/**
|
|
5
|
+
* Error code enum matching react-intl's `ReactIntlErrorCode`.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated These error codes are not raised by the intlayer compat adapter.
|
|
8
|
+
* Exported for API compatibility only.
|
|
9
|
+
*/
|
|
10
|
+
let ReactIntlErrorCode = /* @__PURE__ */ function(ReactIntlErrorCode) {
|
|
11
|
+
ReactIntlErrorCode["FORMAT_ERROR"] = "FORMAT_ERROR";
|
|
12
|
+
ReactIntlErrorCode["UNSUPPORTED_FORMATTER"] = "UNSUPPORTED_FORMATTER";
|
|
13
|
+
ReactIntlErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
|
|
14
|
+
ReactIntlErrorCode["MISSING_DATA"] = "MISSING_DATA";
|
|
15
|
+
ReactIntlErrorCode["MISSING_TRANSLATION"] = "MISSING_TRANSLATION";
|
|
16
|
+
return ReactIntlErrorCode;
|
|
17
|
+
}({});
|
|
18
|
+
/**
|
|
19
|
+
* Base error class matching react-intl's `ReactIntlError` shape.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
|
|
22
|
+
*/
|
|
23
|
+
var ReactIntlError = class extends Error {
|
|
24
|
+
code;
|
|
25
|
+
constructor(code, message) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = "ReactIntlError";
|
|
28
|
+
this.code = code;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
|
|
33
|
+
*/
|
|
34
|
+
var InvalidConfigError = class extends ReactIntlError {
|
|
35
|
+
constructor(message) {
|
|
36
|
+
super("INVALID_CONFIG", message);
|
|
37
|
+
this.name = "InvalidConfigError";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
|
|
42
|
+
*/
|
|
43
|
+
var MessageFormatError = class extends ReactIntlError {
|
|
44
|
+
constructor(message) {
|
|
45
|
+
super("FORMAT_ERROR", message);
|
|
46
|
+
this.name = "MessageFormatError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
|
|
51
|
+
*/
|
|
52
|
+
var MissingDataError = class extends ReactIntlError {
|
|
53
|
+
constructor(message) {
|
|
54
|
+
super("MISSING_DATA", message);
|
|
55
|
+
this.name = "MissingDataError";
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
|
|
60
|
+
*/
|
|
61
|
+
var MissingTranslationError = class extends ReactIntlError {
|
|
62
|
+
constructor(message) {
|
|
63
|
+
super("MISSING_TRANSLATION", message);
|
|
64
|
+
this.name = "MissingTranslationError";
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
|
|
69
|
+
*/
|
|
70
|
+
var UnsupportedFormatterError = class extends ReactIntlError {
|
|
71
|
+
constructor(message) {
|
|
72
|
+
super("UNSUPPORTED_FORMATTER", message);
|
|
73
|
+
this.name = "UnsupportedFormatterError";
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
exports.InvalidConfigError = InvalidConfigError;
|
|
79
|
+
exports.MessageFormatError = MessageFormatError;
|
|
80
|
+
exports.MissingDataError = MissingDataError;
|
|
81
|
+
exports.MissingTranslationError = MissingTranslationError;
|
|
82
|
+
exports.ReactIntlError = ReactIntlError;
|
|
83
|
+
exports.ReactIntlErrorCode = ReactIntlErrorCode;
|
|
84
|
+
exports.UnsupportedFormatterError = UnsupportedFormatterError;
|
|
85
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../../src/errors.ts"],"sourcesContent":["/**\n * Error code enum matching react-intl's `ReactIntlErrorCode`.\n *\n * @deprecated These error codes are not raised by the intlayer compat adapter.\n * Exported for API compatibility only.\n */\nexport enum ReactIntlErrorCode {\n FORMAT_ERROR = 'FORMAT_ERROR',\n UNSUPPORTED_FORMATTER = 'UNSUPPORTED_FORMATTER',\n INVALID_CONFIG = 'INVALID_CONFIG',\n MISSING_DATA = 'MISSING_DATA',\n MISSING_TRANSLATION = 'MISSING_TRANSLATION',\n}\n\n/**\n * Base error class matching react-intl's `ReactIntlError` shape.\n *\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class ReactIntlError extends Error {\n public readonly code: ReactIntlErrorCode;\n\n constructor(code: ReactIntlErrorCode, message: string) {\n super(message);\n this.name = 'ReactIntlError';\n this.code = code;\n }\n}\n\n/**\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class InvalidConfigError extends ReactIntlError {\n constructor(message: string) {\n super(ReactIntlErrorCode.INVALID_CONFIG, message);\n this.name = 'InvalidConfigError';\n }\n}\n\n/**\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class MessageFormatError extends ReactIntlError {\n constructor(message: string) {\n super(ReactIntlErrorCode.FORMAT_ERROR, message);\n this.name = 'MessageFormatError';\n }\n}\n\n/**\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class MissingDataError extends ReactIntlError {\n constructor(message: string) {\n super(ReactIntlErrorCode.MISSING_DATA, message);\n this.name = 'MissingDataError';\n }\n}\n\n/**\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class MissingTranslationError extends ReactIntlError {\n constructor(message: string) {\n super(ReactIntlErrorCode.MISSING_TRANSLATION, message);\n this.name = 'MissingTranslationError';\n }\n}\n\n/**\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class UnsupportedFormatterError extends ReactIntlError {\n constructor(message: string) {\n super(ReactIntlErrorCode.UNSUPPORTED_FORMATTER, message);\n this.name = 'UnsupportedFormatterError';\n }\n}\n"],"mappings":";;;;;;;;;AAMA,IAAY,qBAAL;CACL;CACA;CACA;CACA;CACA;;AACF;;;;;;AAOA,IAAa,iBAAb,cAAoC,MAAM;CACxC,AAAgB;CAEhB,YAAY,MAA0B,SAAiB;EACrD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;;AAKA,IAAa,qBAAb,cAAwC,eAAe;CACrD,YAAY,SAAiB;EAC3B,wBAAyC,OAAO;EAChD,KAAK,OAAO;CACd;AACF;;;;AAKA,IAAa,qBAAb,cAAwC,eAAe;CACrD,YAAY,SAAiB;EAC3B,sBAAuC,OAAO;EAC9C,KAAK,OAAO;CACd;AACF;;;;AAKA,IAAa,mBAAb,cAAsC,eAAe;CACnD,YAAY,SAAiB;EAC3B,sBAAuC,OAAO;EAC9C,KAAK,OAAO;CACd;AACF;;;;AAKA,IAAa,0BAAb,cAA6C,eAAe;CAC1D,YAAY,SAAiB;EAC3B,6BAA8C,OAAO;EACrD,KAAK,OAAO;CACd;AACF;;;;AAKA,IAAa,4BAAb,cAA+C,eAAe;CAC5D,YAAY,SAAiB;EAC3B,+BAAgD,OAAO;EACvD,KAAK,OAAO;CACd;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_context = require('./context.cjs');
|
|
5
|
+
const require_IntlProvider = require('./IntlProvider.cjs');
|
|
6
|
+
const require_useIntl = require('./useIntl.cjs');
|
|
7
|
+
const require_FormattedComponents = require('./FormattedComponents.cjs');
|
|
8
|
+
const require_errors = require('./errors.cjs');
|
|
9
|
+
const require_defineMessages = require('./defineMessages.cjs');
|
|
10
|
+
const require_createIntl = require('./createIntl.cjs');
|
|
11
|
+
const require_FormattedMessage = require('./FormattedMessage.cjs');
|
|
12
|
+
|
|
13
|
+
exports.FormattedDate = require_FormattedComponents.FormattedDate;
|
|
14
|
+
exports.FormattedDateParts = require_FormattedComponents.FormattedDateParts;
|
|
15
|
+
exports.FormattedDateTimeRange = require_FormattedComponents.FormattedDateTimeRange;
|
|
16
|
+
exports.FormattedDisplayName = require_FormattedComponents.FormattedDisplayName;
|
|
17
|
+
exports.FormattedList = require_FormattedComponents.FormattedList;
|
|
18
|
+
exports.FormattedListParts = require_FormattedComponents.FormattedListParts;
|
|
19
|
+
exports.FormattedMessage = require_FormattedMessage.FormattedMessage;
|
|
20
|
+
exports.FormattedNumber = require_FormattedComponents.FormattedNumber;
|
|
21
|
+
exports.FormattedNumberParts = require_FormattedComponents.FormattedNumberParts;
|
|
22
|
+
exports.FormattedPlural = require_FormattedComponents.FormattedPlural;
|
|
23
|
+
exports.FormattedRelativeTime = require_FormattedComponents.FormattedRelativeTime;
|
|
24
|
+
exports.FormattedTime = require_FormattedComponents.FormattedTime;
|
|
25
|
+
exports.FormattedTimeParts = require_FormattedComponents.FormattedTimeParts;
|
|
26
|
+
exports.IntlContext = require_context.IntlContext;
|
|
27
|
+
exports.IntlProvider = require_IntlProvider.IntlProvider;
|
|
28
|
+
exports.InvalidConfigError = require_errors.InvalidConfigError;
|
|
29
|
+
exports.MessageFormatError = require_errors.MessageFormatError;
|
|
30
|
+
exports.MissingDataError = require_errors.MissingDataError;
|
|
31
|
+
exports.MissingTranslationError = require_errors.MissingTranslationError;
|
|
32
|
+
exports.RawIntlProvider = require_context.RawIntlProvider;
|
|
33
|
+
exports.ReactIntlError = require_errors.ReactIntlError;
|
|
34
|
+
exports.ReactIntlErrorCode = require_errors.ReactIntlErrorCode;
|
|
35
|
+
exports.UnsupportedFormatterError = require_errors.UnsupportedFormatterError;
|
|
36
|
+
exports.createIntl = require_createIntl.createIntl;
|
|
37
|
+
exports.createIntlCache = require_createIntl.createIntlCache;
|
|
38
|
+
exports.defineMessage = require_defineMessages.defineMessage;
|
|
39
|
+
exports.defineMessages = require_defineMessages.defineMessages;
|
|
40
|
+
exports.useIntl = require_useIntl.useIntl;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
4
|
+
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
5
|
+
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
|
|
8
|
+
let _intlayer_config_node = require("@intlayer/config/node");
|
|
9
|
+
let vite_intlayer = require("vite-intlayer");
|
|
10
|
+
|
|
11
|
+
//#region src/plugin/index.ts
|
|
12
|
+
/**
|
|
13
|
+
* Caller configuration for react-intl's `useIntl()`.
|
|
14
|
+
*
|
|
15
|
+
* Tracks the `useIntl` call so its return value (the intl object) is marked
|
|
16
|
+
* as the translation accessor for the current component. Field-level pruning
|
|
17
|
+
* via `formatMessage({id})` requires `namespace: { from: 'path-first-segment' }`
|
|
18
|
+
* which is not yet supported by the babel/swc analyser — it will be added in
|
|
19
|
+
* a future release. For now, the alias mapping is the primary compat mechanism.
|
|
20
|
+
*/
|
|
21
|
+
const REACT_INTL_COMPAT_CALLERS = [];
|
|
22
|
+
/**
|
|
23
|
+
* A Vite plugin for react-intl compat that wraps vite-intlayer
|
|
24
|
+
* and injects a resolve alias mapping `react-intl` to
|
|
25
|
+
* `@intlayer/react-intl`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // vite.config.ts
|
|
30
|
+
* import reactIntlVitePlugin from '@intlayer/react-intl/plugin';
|
|
31
|
+
*
|
|
32
|
+
* export default defineConfig({
|
|
33
|
+
* plugins: [reactIntlVitePlugin()],
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
const reactIntlVitePlugin = (options) => {
|
|
38
|
+
const intlayerConfig = (0, _intlayer_config_node.getConfiguration)();
|
|
39
|
+
const appLogger = (0, _intlayer_config_logger.getAppLogger)(intlayerConfig);
|
|
40
|
+
(0, _intlayer_chokidar_utils.runOnce)((0, node_path.join)(intlayerConfig.system.baseDir, ".intlayer", "cache", "intlayer-issues-invitation.lock"), () => {
|
|
41
|
+
appLogger([(0, _intlayer_config_logger.colorize)("Please report any issues you met on GitHub:", _intlayer_config_colors.GREY), (0, _intlayer_config_logger.colorize)("https://github.com/aymericzip/intlayer/issues", _intlayer_config_colors.GREY_LIGHT)]);
|
|
42
|
+
}, { cacheTimeoutMs: 1e3 * 60 * 60 });
|
|
43
|
+
const basePlugins = (0, vite_intlayer.intlayer)({
|
|
44
|
+
...options,
|
|
45
|
+
compatCallers: [...options?.compatCallers ?? [], ...REACT_INTL_COMPAT_CALLERS]
|
|
46
|
+
});
|
|
47
|
+
const compatPlugin = {
|
|
48
|
+
name: "vite-react-intl-compat-plugin",
|
|
49
|
+
config: () => ({ resolve: { alias: { "react-intl": "@intlayer/react-intl" } } })
|
|
50
|
+
};
|
|
51
|
+
return [...Array.isArray(basePlugins) ? basePlugins : [basePlugins], compatPlugin];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
exports.default = reactIntlVitePlugin;
|
|
56
|
+
exports.reactIntlVitePlugin = reactIntlVitePlugin;
|
|
57
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ANSIColors"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { PluginOption } from 'vite';\nimport { type CompatCallerConfig, intlayer } from 'vite-intlayer';\n\n/**\n * Caller configuration for react-intl's `useIntl()`.\n *\n * Tracks the `useIntl` call so its return value (the intl object) is marked\n * as the translation accessor for the current component. Field-level pruning\n * via `formatMessage({id})` requires `namespace: { from: 'path-first-segment' }`\n * which is not yet supported by the babel/swc analyser — it will be added in\n * a future release. For now, the alias mapping is the primary compat mechanism.\n */\nconst REACT_INTL_COMPAT_CALLERS: CompatCallerConfig[] = [];\n\n/**\n * A Vite plugin for react-intl compat that wraps vite-intlayer\n * and injects a resolve alias mapping `react-intl` to\n * `@intlayer/react-intl`.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import reactIntlVitePlugin from '@intlayer/react-intl/plugin';\n *\n * export default defineConfig({\n * plugins: [reactIntlVitePlugin()],\n * });\n * ```\n */\nexport const reactIntlVitePlugin = (\n options?: Parameters<typeof intlayer>[0]\n): PluginOption[] => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const basePlugins = intlayer({\n ...options,\n compatCallers: [\n ...(options?.compatCallers ?? []),\n ...REACT_INTL_COMPAT_CALLERS,\n ],\n });\n\n const compatPlugin: PluginOption = {\n name: 'vite-react-intl-compat-plugin',\n config: () => ({\n resolve: {\n alias: {\n 'react-intl': '@intlayer/react-intl',\n },\n },\n }),\n };\n\n return [\n ...(Array.isArray(basePlugins) ? basePlugins : [basePlugins]),\n compatPlugin,\n ];\n};\n\nexport default reactIntlVitePlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,4BAAkD,CAAC;;;;;;;;;;;;;;;;AAiBzD,MAAa,uBACX,YACmB;CACnB,MAAM,6DAAkC;CACxC,MAAM,sDAAyB,cAAc;CAE7C,0DAEI,eAAe,OAAO,SACtB,aACA,SACA,iCACF,SACM;EACJ,UAAU,uCAEN,+CACAA,wBAAW,IACb,yCAEE,iDACAA,wBAAW,UACb,CACF,CAAC;CACH,GACA,EACE,gBAAgB,MAAO,KAAK,GAC9B,CACF;CAEA,MAAM,0CAAuB;EAC3B,GAAG;EACH,eAAe,CACb,GAAI,SAAS,iBAAiB,CAAC,GAC/B,GAAG,yBACL;CACF,CAAC;CAED,MAAM,eAA6B;EACjC,MAAM;EACN,eAAe,EACb,SAAS,EACP,OAAO,EACL,cAAc,uBAChB,EACF,EACF;CACF;CAEA,OAAO,CACL,GAAI,MAAM,QAAQ,WAAW,IAAI,cAAc,CAAC,WAAW,GAC3D,YACF;AACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_context = require('./context.cjs');
|
|
5
|
+
const require_createIntlObject = require('./createIntlObject.cjs');
|
|
6
|
+
let react = require("react");
|
|
7
|
+
let react_intlayer = require("react-intlayer");
|
|
8
|
+
|
|
9
|
+
//#region src/useIntl.ts
|
|
10
|
+
/**
|
|
11
|
+
* Drop-in for react-intl's `useIntl`.
|
|
12
|
+
*
|
|
13
|
+
* Returns the active `IntlShape` instance. When used inside an
|
|
14
|
+
* {@link IntlProvider} the instance comes from context; otherwise it is
|
|
15
|
+
* derived from `react-intlayer`'s locale context on the fly.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* const intl = useIntl();
|
|
20
|
+
* intl.formatMessage({ id: 'home.title' });
|
|
21
|
+
* intl.formatNumber(42, { style: 'currency', currency: 'USD' });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
const useIntl = () => {
|
|
25
|
+
const contextIntl = (0, react.useContext)(require_context.IntlContext);
|
|
26
|
+
const { locale } = (0, react_intlayer.useLocale)();
|
|
27
|
+
const derivedIntl = (0, react.useMemo)(() => require_createIntlObject.createIntlObject(locale), [locale]);
|
|
28
|
+
return contextIntl ?? derivedIntl;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.useIntl = useIntl;
|
|
33
|
+
//# sourceMappingURL=useIntl.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntl.cjs","names":["IntlContext","createIntlObject"],"sources":["../../src/useIntl.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport type { useIntl as _useIntl } from 'react-intl';\nimport { useLocale } from 'react-intlayer';\nimport { IntlContext } from './context';\nimport { createIntlObject } from './createIntlObject';\n\n/**\n * Drop-in for react-intl's `useIntl`.\n *\n * Returns the active `IntlShape` instance. When used inside an\n * {@link IntlProvider} the instance comes from context; otherwise it is\n * derived from `react-intlayer`'s locale context on the fly.\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n * intl.formatMessage({ id: 'home.title' });\n * intl.formatNumber(42, { style: 'currency', currency: 'USD' });\n * ```\n */\nexport const useIntl: typeof _useIntl = () => {\n const contextIntl = useContext(IntlContext);\n const { locale } = useLocale();\n\n const derivedIntl = useMemo(\n () => createIntlObject(locale as LocalesValues),\n [locale]\n );\n\n return contextIntl ?? derivedIntl;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,gBAAiC;CAC5C,MAAM,oCAAyBA,2BAAW;CAC1C,MAAM,EAAE,yCAAqB;CAE7B,MAAM,uCACEC,0CAAiB,MAAuB,GAC9C,CAAC,MAAM,CACT;CAEA,OAAO,eAAe;AACxB"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useIntl } from "./useIntl.mjs";
|
|
4
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/FormattedComponents.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Drop-in for react-intl's `<FormattedDate>`.
|
|
9
|
+
* Renders a locale-aware date string using `Intl.DateTimeFormat`.
|
|
10
|
+
*/
|
|
11
|
+
const FormattedDate = ({ value, children, format: _format, ...options }) => {
|
|
12
|
+
const formatted = useIntl().formatDate(value, options);
|
|
13
|
+
if (typeof children === "function") return children(formatted) ?? null;
|
|
14
|
+
return /* @__PURE__ */ jsx(Fragment, { children: formatted });
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Drop-in for react-intl's `<FormattedTime>`.
|
|
18
|
+
* Renders a locale-aware time string using `Intl.DateTimeFormat`.
|
|
19
|
+
*/
|
|
20
|
+
const FormattedTime = ({ value, children, format: _format, ...options }) => {
|
|
21
|
+
const formatted = useIntl().formatTime(value, options);
|
|
22
|
+
if (typeof children === "function") return children(formatted) ?? null;
|
|
23
|
+
return /* @__PURE__ */ jsx(Fragment, { children: formatted });
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Drop-in for react-intl's `<FormattedNumber>`.
|
|
27
|
+
* Renders a locale-aware number string using `Intl.NumberFormat`.
|
|
28
|
+
*/
|
|
29
|
+
const FormattedNumber = ({ value, children, format: _format, ...options }) => {
|
|
30
|
+
const formatted = useIntl().formatNumber(value, options);
|
|
31
|
+
if (typeof children === "function") return children(formatted) ?? null;
|
|
32
|
+
return /* @__PURE__ */ jsx(Fragment, { children: formatted });
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Drop-in for react-intl's `<FormattedList>`.
|
|
36
|
+
* Renders a locale-aware list string using `Intl.ListFormat`.
|
|
37
|
+
*/
|
|
38
|
+
const FormattedList = ({ value, ...options }) => {
|
|
39
|
+
const intl = useIntl();
|
|
40
|
+
const strings = value.filter((item) => typeof item === "string");
|
|
41
|
+
return /* @__PURE__ */ jsx(Fragment, { children: intl.formatList(strings, options) });
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Drop-in for react-intl's `<FormattedDisplayName>`.
|
|
45
|
+
* Renders a locale-aware display name using `Intl.DisplayNames`.
|
|
46
|
+
*/
|
|
47
|
+
const FormattedDisplayName = ({ value, ...options }) => {
|
|
48
|
+
return /* @__PURE__ */ jsx(Fragment, { children: useIntl().formatDisplayName(value, options) ?? value });
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Drop-in for react-intl's `<FormattedRelativeTime>`.
|
|
52
|
+
* Renders a locale-aware relative time string using `Intl.RelativeTimeFormat`.
|
|
53
|
+
* Auto-update (`updateIntervalInSeconds`) is not implemented.
|
|
54
|
+
*/
|
|
55
|
+
const FormattedRelativeTime = ({ value = 0, unit = "second", children, updateIntervalInSeconds: _updateIntervalInSeconds, ...options }) => {
|
|
56
|
+
const formatted = useIntl().formatRelativeTime(value, unit, options);
|
|
57
|
+
if (typeof children === "function") return children(formatted) ?? null;
|
|
58
|
+
return /* @__PURE__ */ jsx(Fragment, { children: formatted });
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Drop-in for react-intl's `<FormattedPlural>`.
|
|
62
|
+
* Selects the matching plural slot using `Intl.PluralRules`.
|
|
63
|
+
*/
|
|
64
|
+
const FormattedPlural = ({ value, other, zero, one, two, few, many, children, ...options }) => {
|
|
65
|
+
const rule = useIntl().formatPlural(value, options);
|
|
66
|
+
const selected = {
|
|
67
|
+
zero,
|
|
68
|
+
one,
|
|
69
|
+
two,
|
|
70
|
+
few,
|
|
71
|
+
many,
|
|
72
|
+
other
|
|
73
|
+
}[rule] ?? other;
|
|
74
|
+
if (typeof children === "function") return children(selected) ?? null;
|
|
75
|
+
return /* @__PURE__ */ jsx(Fragment, { children: selected });
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Drop-in for react-intl's `<FormattedDateTimeRange>`.
|
|
79
|
+
* Renders a locale-aware date range string using `Intl.DateTimeFormat#formatRange`.
|
|
80
|
+
*/
|
|
81
|
+
const FormattedDateTimeRange = ({ from, to, children, ...options }) => {
|
|
82
|
+
const formatted = useIntl().formatDateTimeRange(from, to, options);
|
|
83
|
+
if (typeof children === "function") return children(formatted) ?? null;
|
|
84
|
+
return /* @__PURE__ */ jsx(Fragment, { children: formatted });
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Drop-in for react-intl's `<FormattedDateParts>`.
|
|
88
|
+
* Renders format parts via a `children` render-prop.
|
|
89
|
+
*/
|
|
90
|
+
const FormattedDateParts = ({ value, children, format: _format, ...options }) => {
|
|
91
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children(useIntl().formatDateToParts(value, options)) });
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Drop-in for react-intl's `<FormattedTimeParts>`.
|
|
95
|
+
* Renders format parts via a `children` render-prop.
|
|
96
|
+
*/
|
|
97
|
+
const FormattedTimeParts = ({ value, children, format: _format, ...options }) => {
|
|
98
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children(useIntl().formatTimeToParts(value, options)) });
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Drop-in for react-intl's `<FormattedNumberParts>`.
|
|
102
|
+
* Renders format parts via a `children` render-prop.
|
|
103
|
+
*/
|
|
104
|
+
const FormattedNumberParts = ({ value, children, format: _format, ...options }) => {
|
|
105
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children(useIntl().formatNumberToParts(value, options)) });
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Drop-in for react-intl's `<FormattedListParts>`.
|
|
109
|
+
* Renders list format parts via a `children` render-prop.
|
|
110
|
+
*/
|
|
111
|
+
const FormattedListParts = ({ value, children, ...options }) => {
|
|
112
|
+
const intl = useIntl();
|
|
113
|
+
const strings = Array.from(value).filter((item) => typeof item === "string");
|
|
114
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children(intl.formatListToParts(strings, options)) });
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
export { FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedList, FormattedListParts, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts };
|
|
119
|
+
//# sourceMappingURL=FormattedComponents.mjs.map
|