@lingui/react 5.9.0 → 6.0.0-next.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/dist/index-rsc.d.mts +2 -2
- package/dist/index-rsc.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.mjs +1 -1
- package/dist/shared/{react.05772d3b.d.ts → react.B7EjXn_h.d.mts} +2 -1
- package/dist/shared/{react.8970326b.mjs → react.DZONiYSA.mjs} +4 -8
- package/macro/browser.cjs +10 -0
- package/macro/index.cjs +6 -0
- package/macro/{index.d.ts → index.d.cts} +4 -7
- package/package.json +21 -40
- package/dist/index-rsc.cjs +0 -29
- package/dist/index-rsc.d.cts +0 -11
- package/dist/index-rsc.d.ts +0 -11
- package/dist/index.cjs +0 -71
- package/dist/index.d.cts +0 -9
- package/dist/index.d.ts +0 -9
- package/dist/server.cjs +0 -35
- package/dist/server.d.cts +0 -46
- package/dist/server.d.ts +0 -46
- package/dist/shared/react.05772d3b.d.cts +0 -53
- package/dist/shared/react.05772d3b.d.mts +0 -53
- package/dist/shared/react.90cde280.cjs +0 -140
- package/macro/index.js +0 -1
package/dist/index-rsc.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TransProps,
|
|
2
|
-
export {
|
|
1
|
+
import { T as TransProps, I as I18nContext } from './shared/react.B7EjXn_h.mjs';
|
|
2
|
+
export { c as TransRenderCallbackOrComponent, d as TransRenderProps } from './shared/react.B7EjXn_h.mjs';
|
|
3
3
|
import 'react/jsx-runtime';
|
|
4
4
|
import 'react';
|
|
5
5
|
import '@lingui/core';
|
package/dist/index-rsc.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getI18n } from './server.mjs';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { T as TransNoContext } from './shared/react.
|
|
3
|
+
import { T as TransNoContext } from './shared/react.DZONiYSA.mjs';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
|
6
6
|
function TransRsc(props) {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TransProps } from './shared/react.
|
|
2
|
-
export {
|
|
1
|
+
import { T as TransProps } from './shared/react.B7EjXn_h.mjs';
|
|
2
|
+
export { I as I18nContext, a as I18nProvider, b as I18nProviderProps, L as LinguiContext, c as TransRenderCallbackOrComponent, d as TransRenderProps, u as useLingui } from './shared/react.B7EjXn_h.mjs';
|
|
3
3
|
import 'react/jsx-runtime';
|
|
4
4
|
import 'react';
|
|
5
5
|
import '@lingui/core';
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { createContext, useRef, useCallback, useState, useEffect, useContext } from 'react';
|
|
4
|
-
import { T as TransNoContext } from './shared/react.
|
|
4
|
+
import { T as TransNoContext } from './shared/react.DZONiYSA.mjs';
|
|
5
5
|
|
|
6
6
|
const LinguiContext = createContext(null);
|
|
7
7
|
const useLinguiInternal = (devErrorMessage) => {
|
package/dist/server.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { e as TransNoContext, T as TransProps,
|
|
1
|
+
import { I as I18nContext } from './shared/react.B7EjXn_h.mjs';
|
|
2
|
+
export { e as TransNoContext, T as TransProps, c as TransRenderCallbackOrComponent, d as TransRenderProps } from './shared/react.B7EjXn_h.mjs';
|
|
3
3
|
import { I18n } from '@lingui/core';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
package/dist/server.mjs
CHANGED
|
@@ -50,4 +50,5 @@ declare const LinguiContext: react.Context<I18nContext | null>;
|
|
|
50
50
|
declare function useLingui(): I18nContext;
|
|
51
51
|
declare const I18nProvider: ({ i18n, defaultComponent, children, }: I18nProviderProps) => react_jsx_runtime.JSX.Element | null;
|
|
52
52
|
|
|
53
|
-
export {
|
|
53
|
+
export { LinguiContext as L, I18nProvider as a, TransNoContext as e, useLingui as u };
|
|
54
|
+
export type { I18nContext as I, TransProps as T, I18nProviderProps as b, TransRenderCallbackOrComponent as c, TransRenderProps as d };
|
|
@@ -22,13 +22,11 @@ const voidElementTags = {
|
|
|
22
22
|
};
|
|
23
23
|
function formatElements(value, elements = {}) {
|
|
24
24
|
const parts = value.split(tagRe);
|
|
25
|
-
if (parts.length === 1)
|
|
26
|
-
return value;
|
|
25
|
+
if (parts.length === 1) return value;
|
|
27
26
|
const uniqueId = makeCounter(0, "$lingui$");
|
|
28
27
|
const tree = [];
|
|
29
28
|
const before = parts.shift();
|
|
30
|
-
if (before)
|
|
31
|
-
tree.push(before);
|
|
29
|
+
if (before) tree.push(before);
|
|
32
30
|
for (const [index, children, after] of getElements(parts)) {
|
|
33
31
|
let element = typeof index !== "undefined" ? elements[index] : void 0;
|
|
34
32
|
if (!element || voidElementTags[element.type] && children) {
|
|
@@ -55,14 +53,12 @@ function formatElements(value, elements = {}) {
|
|
|
55
53
|
children ? formatElements(children, elements) : element.props.children
|
|
56
54
|
)
|
|
57
55
|
);
|
|
58
|
-
if (after)
|
|
59
|
-
tree.push(after);
|
|
56
|
+
if (after) tree.push(after);
|
|
60
57
|
}
|
|
61
58
|
return tree.length === 1 ? tree[0] : tree;
|
|
62
59
|
}
|
|
63
60
|
function getElements(parts) {
|
|
64
|
-
if (!parts.length)
|
|
65
|
-
return [];
|
|
61
|
+
if (!parts.length) return [];
|
|
66
62
|
const [paired, children, unpaired, after] = parts.slice(0, 4);
|
|
67
63
|
const triple = [paired || unpaired, children || "", after];
|
|
68
64
|
return [triple].concat(getElements(parts.slice(4, parts.length)));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const Trans = function () {}
|
|
2
|
+
export const Plural = function () {}
|
|
3
|
+
export const Select = function () {}
|
|
4
|
+
export const SelectOrdinal = function () {}
|
|
5
|
+
export const useLingui = function () {}
|
|
6
|
+
|
|
7
|
+
throw new Error(
|
|
8
|
+
`The macro you imported from "@lingui/react/macro" is being executed outside the context of compilation. \n` +
|
|
9
|
+
`This indicates that you don't configured correctly one of the "babel-plugin-macros" / "@lingui/swc-plugin" / "babel-plugin-lingui-macro"`,
|
|
10
|
+
)
|
package/macro/index.cjs
ADDED
|
@@ -107,12 +107,6 @@ export const SelectOrdinal: (props: PluralChoiceProps) => ReactNode
|
|
|
107
107
|
*/
|
|
108
108
|
export const Select: (props: SelectChoiceProps) => ReactNode
|
|
109
109
|
|
|
110
|
-
declare function _t(descriptor: MacroMessageDescriptor): string
|
|
111
|
-
declare function _t(
|
|
112
|
-
literals: TemplateStringsArray,
|
|
113
|
-
...placeholders: any[]
|
|
114
|
-
): string
|
|
115
|
-
|
|
116
110
|
/**
|
|
117
111
|
*
|
|
118
112
|
* Macro version of useLingui replaces _ function with `t` macro function which is bound to i18n passed from React.Context
|
|
@@ -137,5 +131,8 @@ declare function _t(
|
|
|
137
131
|
* ```
|
|
138
132
|
*/
|
|
139
133
|
export function useLingui(): Omit<I18nContext, "_"> & {
|
|
140
|
-
t:
|
|
134
|
+
t: {
|
|
135
|
+
(descriptor: MacroMessageDescriptor): string
|
|
136
|
+
(literals: TemplateStringsArray, ...placeholders: any[]): string
|
|
137
|
+
}
|
|
141
138
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-next.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "React components for translations",
|
|
6
|
-
"
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
6
|
+
"type": "module",
|
|
9
7
|
"author": {
|
|
10
8
|
"name": "Tomáš Ehrlich",
|
|
11
9
|
"email": "tomas.ehrlich@gmail.com"
|
|
@@ -27,8 +25,8 @@
|
|
|
27
25
|
"l10n"
|
|
28
26
|
],
|
|
29
27
|
"scripts": {
|
|
30
|
-
"build": "
|
|
31
|
-
"
|
|
28
|
+
"build": "unbuild",
|
|
29
|
+
"check-types": "tsc --noEmit"
|
|
32
30
|
},
|
|
33
31
|
"homepage": "https://lingui.dev",
|
|
34
32
|
"repository": {
|
|
@@ -40,34 +38,18 @@
|
|
|
40
38
|
"url": "https://github.com/lingui/js-lingui/issues"
|
|
41
39
|
},
|
|
42
40
|
"engines": {
|
|
43
|
-
"node": ">=
|
|
41
|
+
"node": ">=22.19.0"
|
|
44
42
|
},
|
|
45
43
|
"exports": {
|
|
46
44
|
".": {
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
"react-server": "./dist/index-rsc.cjs",
|
|
50
|
-
"default": "./dist/index.cjs"
|
|
51
|
-
},
|
|
52
|
-
"import": {
|
|
53
|
-
"types": "./dist/index.d.mts",
|
|
54
|
-
"react-server": "./dist/index-rsc.mjs",
|
|
55
|
-
"default": "./dist/index.mjs"
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
"./server": {
|
|
59
|
-
"require": {
|
|
60
|
-
"types": "./dist/server.d.ts",
|
|
61
|
-
"default": "./dist/server.cjs"
|
|
62
|
-
},
|
|
63
|
-
"import": {
|
|
64
|
-
"types": "./dist/server.d.ts",
|
|
65
|
-
"default": "./dist/server.mjs"
|
|
66
|
-
}
|
|
45
|
+
"react-server": "./dist/index-rsc.mjs",
|
|
46
|
+
"default": "./dist/index.mjs"
|
|
67
47
|
},
|
|
48
|
+
"./server": "./dist/server.mjs",
|
|
68
49
|
"./macro": {
|
|
69
|
-
"
|
|
70
|
-
"
|
|
50
|
+
"browser": "./macro/browser.cjs",
|
|
51
|
+
"types": "./macro/index.d.cts",
|
|
52
|
+
"default": "./macro/index.cjs"
|
|
71
53
|
},
|
|
72
54
|
"./package.json": "./package.json"
|
|
73
55
|
},
|
|
@@ -75,35 +57,34 @@
|
|
|
75
57
|
"LICENSE",
|
|
76
58
|
"README.md",
|
|
77
59
|
"dist/",
|
|
78
|
-
"macro/
|
|
79
|
-
"macro/index.
|
|
60
|
+
"macro/browser.cjs",
|
|
61
|
+
"macro/index.d.cts",
|
|
62
|
+
"macro/index.cjs"
|
|
80
63
|
],
|
|
81
64
|
"peerDependencies": {
|
|
82
|
-
"@lingui/babel-plugin-lingui-macro": "5.9.0",
|
|
83
65
|
"babel-plugin-macros": "2 || 3",
|
|
84
66
|
"react": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
85
67
|
},
|
|
86
68
|
"peerDependenciesMeta": {
|
|
87
|
-
"@lingui/babel-plugin-lingui-macro": {
|
|
88
|
-
"optional": true
|
|
89
|
-
},
|
|
90
69
|
"babel-plugin-macros": {
|
|
91
70
|
"optional": true
|
|
92
71
|
}
|
|
93
72
|
},
|
|
94
73
|
"dependencies": {
|
|
95
|
-
"@babel
|
|
96
|
-
"@lingui/core": "
|
|
74
|
+
"@lingui/babel-plugin-lingui-macro": "6.0.0-next.0",
|
|
75
|
+
"@lingui/core": "6.0.0-next.0"
|
|
97
76
|
},
|
|
98
77
|
"devDependencies": {
|
|
99
|
-
"@lingui/
|
|
78
|
+
"@lingui/test-utils": "3.0.3",
|
|
100
79
|
"@testing-library/react": "^14.0.0",
|
|
101
80
|
"@types/react": "^18.2.13",
|
|
102
81
|
"eslint-plugin-react": "^7.32.2",
|
|
103
82
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
83
|
+
"happy-dom": "^20.0.10",
|
|
104
84
|
"react": "^18.2.0",
|
|
105
85
|
"react-dom": "^18.2.0",
|
|
106
|
-
"unbuild": "
|
|
86
|
+
"unbuild": "3.6.1",
|
|
87
|
+
"vitest": "4.0.18"
|
|
107
88
|
},
|
|
108
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "a9576050487a4f7dfbc88db20814d5a1bb861c8c"
|
|
109
90
|
}
|
package/dist/index-rsc.cjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const server = require('./server.cjs');
|
|
4
|
-
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
const TransNoContext = require('./shared/react.90cde280.cjs');
|
|
6
|
-
require('react');
|
|
7
|
-
|
|
8
|
-
function TransRsc(props) {
|
|
9
|
-
const ctx = server.getI18n();
|
|
10
|
-
if (!ctx) {
|
|
11
|
-
throw new Error(
|
|
12
|
-
"You tried to use `Trans` in Server Component, but i18n instance for RSC hasn't been setup.\nMake sure to call `setI18n` in the root of your page."
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
return /* @__PURE__ */ jsxRuntime.jsx(TransNoContext.TransNoContext, { ...props, lingui: ctx });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function useLingui() {
|
|
19
|
-
const ctx = server.getI18n();
|
|
20
|
-
if (!ctx) {
|
|
21
|
-
throw new Error(
|
|
22
|
-
"You tried to use `useLingui` in a Server Component, but i18n instance for RSC hasn't been setup.\nMake sure to call `setI18n` in the root of your page."
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
return ctx;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
exports.Trans = TransRsc;
|
|
29
|
-
exports.useLingui = useLingui;
|
package/dist/index-rsc.d.cts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { T as TransProps, b as I18nContext } from './shared/react.05772d3b.cjs';
|
|
2
|
-
export { d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.05772d3b.cjs';
|
|
3
|
-
import 'react/jsx-runtime';
|
|
4
|
-
import 'react';
|
|
5
|
-
import '@lingui/core';
|
|
6
|
-
|
|
7
|
-
declare function TransRsc(props: TransProps): React.ReactElement<any, any> | null;
|
|
8
|
-
|
|
9
|
-
declare function useLingui(): I18nContext;
|
|
10
|
-
|
|
11
|
-
export { TransRsc as Trans, TransProps, useLingui };
|
package/dist/index-rsc.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { T as TransProps, b as I18nContext } from './shared/react.05772d3b.js';
|
|
2
|
-
export { d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.05772d3b.js';
|
|
3
|
-
import 'react/jsx-runtime';
|
|
4
|
-
import 'react';
|
|
5
|
-
import '@lingui/core';
|
|
6
|
-
|
|
7
|
-
declare function TransRsc(props: TransProps): React.ReactElement<any, any> | null;
|
|
8
|
-
|
|
9
|
-
declare function useLingui(): I18nContext;
|
|
10
|
-
|
|
11
|
-
export { TransRsc as Trans, TransProps, useLingui };
|
package/dist/index.cjs
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
const React = require('react');
|
|
6
|
-
const TransNoContext = require('./shared/react.90cde280.cjs');
|
|
7
|
-
|
|
8
|
-
const LinguiContext = React.createContext(null);
|
|
9
|
-
const useLinguiInternal = (devErrorMessage) => {
|
|
10
|
-
const context = React.useContext(LinguiContext);
|
|
11
|
-
if (process.env.NODE_ENV !== "production") {
|
|
12
|
-
if (context == null) {
|
|
13
|
-
throw new Error(
|
|
14
|
-
devErrorMessage ?? "useLingui hook was used without I18nProvider."
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return context;
|
|
19
|
-
};
|
|
20
|
-
function useLingui() {
|
|
21
|
-
return useLinguiInternal();
|
|
22
|
-
}
|
|
23
|
-
const I18nProvider = ({
|
|
24
|
-
i18n,
|
|
25
|
-
defaultComponent,
|
|
26
|
-
children
|
|
27
|
-
}) => {
|
|
28
|
-
const latestKnownLocale = React.useRef(i18n.locale);
|
|
29
|
-
const makeContext = React.useCallback(
|
|
30
|
-
() => ({
|
|
31
|
-
i18n,
|
|
32
|
-
defaultComponent,
|
|
33
|
-
_: i18n.t.bind(i18n)
|
|
34
|
-
}),
|
|
35
|
-
[i18n, defaultComponent]
|
|
36
|
-
);
|
|
37
|
-
const [context, setContext] = React.useState(makeContext());
|
|
38
|
-
React.useEffect(() => {
|
|
39
|
-
const updateContext = () => {
|
|
40
|
-
latestKnownLocale.current = i18n.locale;
|
|
41
|
-
setContext(makeContext());
|
|
42
|
-
};
|
|
43
|
-
const unsubscribe = i18n.on("change", updateContext);
|
|
44
|
-
if (latestKnownLocale.current !== i18n.locale) {
|
|
45
|
-
updateContext();
|
|
46
|
-
}
|
|
47
|
-
return unsubscribe;
|
|
48
|
-
}, [i18n, makeContext]);
|
|
49
|
-
if (!latestKnownLocale.current) {
|
|
50
|
-
process.env.NODE_ENV === "development" && console.log(
|
|
51
|
-
"I18nProvider rendered `null`. A call to `i18n.activate` needs to happen in order for translations to be activated and for the I18nProvider to render.This is not an error but an informational message logged only in development."
|
|
52
|
-
);
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
return /* @__PURE__ */ jsxRuntime.jsx(LinguiContext.Provider, { value: context, children });
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
function Trans(props) {
|
|
59
|
-
let errMessage = void 0;
|
|
60
|
-
if (process.env.NODE_ENV !== "production") {
|
|
61
|
-
errMessage = `Trans component was rendered without I18nProvider.
|
|
62
|
-
Attempted to render message: ${props.message} id: ${props.id}. Make sure this component is rendered inside a I18nProvider.`;
|
|
63
|
-
}
|
|
64
|
-
const lingui = useLinguiInternal(errMessage);
|
|
65
|
-
return /* @__PURE__ */ jsxRuntime.jsx(TransNoContext.TransNoContext, { ...props, lingui });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
exports.I18nProvider = I18nProvider;
|
|
69
|
-
exports.LinguiContext = LinguiContext;
|
|
70
|
-
exports.Trans = Trans;
|
|
71
|
-
exports.useLingui = useLingui;
|
package/dist/index.d.cts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { T as TransProps } from './shared/react.05772d3b.cjs';
|
|
2
|
-
export { b as I18nContext, I as I18nProvider, a as I18nProviderProps, L as LinguiContext, d as TransRenderCallbackOrComponent, c as TransRenderProps, u as useLingui } from './shared/react.05772d3b.cjs';
|
|
3
|
-
import 'react/jsx-runtime';
|
|
4
|
-
import 'react';
|
|
5
|
-
import '@lingui/core';
|
|
6
|
-
|
|
7
|
-
declare function Trans(props: TransProps): React.ReactElement<any, any> | null;
|
|
8
|
-
|
|
9
|
-
export { Trans, TransProps };
|
package/dist/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { T as TransProps } from './shared/react.05772d3b.js';
|
|
2
|
-
export { b as I18nContext, I as I18nProvider, a as I18nProviderProps, L as LinguiContext, d as TransRenderCallbackOrComponent, c as TransRenderProps, u as useLingui } from './shared/react.05772d3b.js';
|
|
3
|
-
import 'react/jsx-runtime';
|
|
4
|
-
import 'react';
|
|
5
|
-
import '@lingui/core';
|
|
6
|
-
|
|
7
|
-
declare function Trans(props: TransProps): React.ReactElement<any, any> | null;
|
|
8
|
-
|
|
9
|
-
export { Trans, TransProps };
|
package/dist/server.cjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const TransNoContext = require('./shared/react.90cde280.cjs');
|
|
4
|
-
const React = require('react');
|
|
5
|
-
require('react/jsx-runtime');
|
|
6
|
-
|
|
7
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
8
|
-
|
|
9
|
-
const React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
10
|
-
|
|
11
|
-
let cache = null;
|
|
12
|
-
const getLinguiCache = () => {
|
|
13
|
-
if (!cache) {
|
|
14
|
-
cache = React__default.cache(
|
|
15
|
-
() => ({
|
|
16
|
-
current: null
|
|
17
|
-
})
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
return cache();
|
|
21
|
-
};
|
|
22
|
-
function setI18n(i18n, defaultComponent) {
|
|
23
|
-
getLinguiCache().current = {
|
|
24
|
-
i18n,
|
|
25
|
-
_: i18n._.bind(i18n),
|
|
26
|
-
defaultComponent
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function getI18n() {
|
|
30
|
-
return getLinguiCache()?.current;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
exports.TransNoContext = TransNoContext.TransNoContext;
|
|
34
|
-
exports.getI18n = getI18n;
|
|
35
|
-
exports.setI18n = setI18n;
|
package/dist/server.d.cts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { b as I18nContext } from './shared/react.05772d3b.cjs';
|
|
2
|
-
export { e as TransNoContext, T as TransProps, d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.05772d3b.cjs';
|
|
3
|
-
import { I18n } from '@lingui/core';
|
|
4
|
-
import 'react/jsx-runtime';
|
|
5
|
-
import 'react';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This is an entry point for React Server Components (RSC)
|
|
9
|
-
*
|
|
10
|
-
* RSC uses static analysis to find any non-valid function calls in the import graph.
|
|
11
|
-
* That means this entry point and its children must not have any Provider/Context calls.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Set Lingui's i18n instance for later use in RSC Components
|
|
16
|
-
*
|
|
17
|
-
* Example:
|
|
18
|
-
*
|
|
19
|
-
* ```js
|
|
20
|
-
* import { setupI18n } from "@lingui/core";
|
|
21
|
-
*
|
|
22
|
-
* const i18n = setupI18n({
|
|
23
|
-
* locale,
|
|
24
|
-
* messages: { [locale]: messages },
|
|
25
|
-
* })
|
|
26
|
-
*
|
|
27
|
-
* setI18n(i18n);
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
declare function setI18n(i18n: I18n, defaultComponent?: I18nContext["defaultComponent"]): void;
|
|
31
|
-
/**
|
|
32
|
-
* Get Lingui's i18n instance saved for RSC
|
|
33
|
-
*
|
|
34
|
-
* ```js
|
|
35
|
-
* export function generateMetadata() {
|
|
36
|
-
* const i18n = getI18n()
|
|
37
|
-
*
|
|
38
|
-
* return {
|
|
39
|
-
* title: t(i18n)`Translation Demo`,
|
|
40
|
-
* }
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
declare function getI18n(): I18nContext | null;
|
|
45
|
-
|
|
46
|
-
export { getI18n, setI18n };
|
package/dist/server.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { b as I18nContext } from './shared/react.05772d3b.js';
|
|
2
|
-
export { e as TransNoContext, T as TransProps, d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.05772d3b.js';
|
|
3
|
-
import { I18n } from '@lingui/core';
|
|
4
|
-
import 'react/jsx-runtime';
|
|
5
|
-
import 'react';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This is an entry point for React Server Components (RSC)
|
|
9
|
-
*
|
|
10
|
-
* RSC uses static analysis to find any non-valid function calls in the import graph.
|
|
11
|
-
* That means this entry point and its children must not have any Provider/Context calls.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Set Lingui's i18n instance for later use in RSC Components
|
|
16
|
-
*
|
|
17
|
-
* Example:
|
|
18
|
-
*
|
|
19
|
-
* ```js
|
|
20
|
-
* import { setupI18n } from "@lingui/core";
|
|
21
|
-
*
|
|
22
|
-
* const i18n = setupI18n({
|
|
23
|
-
* locale,
|
|
24
|
-
* messages: { [locale]: messages },
|
|
25
|
-
* })
|
|
26
|
-
*
|
|
27
|
-
* setI18n(i18n);
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
declare function setI18n(i18n: I18n, defaultComponent?: I18nContext["defaultComponent"]): void;
|
|
31
|
-
/**
|
|
32
|
-
* Get Lingui's i18n instance saved for RSC
|
|
33
|
-
*
|
|
34
|
-
* ```js
|
|
35
|
-
* export function generateMetadata() {
|
|
36
|
-
* const i18n = getI18n()
|
|
37
|
-
*
|
|
38
|
-
* return {
|
|
39
|
-
* title: t(i18n)`Translation Demo`,
|
|
40
|
-
* }
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
declare function getI18n(): I18nContext | null;
|
|
45
|
-
|
|
46
|
-
export { getI18n, setI18n };
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as react from 'react';
|
|
3
|
-
import { MessageOptions, I18n } from '@lingui/core';
|
|
4
|
-
|
|
5
|
-
type TransRenderProps = {
|
|
6
|
-
id: string;
|
|
7
|
-
translation: React.ReactNode;
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
message?: string | null;
|
|
10
|
-
};
|
|
11
|
-
type TransRenderCallbackOrComponent = {
|
|
12
|
-
component?: never;
|
|
13
|
-
render?: ((props: TransRenderProps) => React.ReactElement<any, any>) | null;
|
|
14
|
-
} | {
|
|
15
|
-
component?: React.ComponentType<TransRenderProps> | null;
|
|
16
|
-
render?: never;
|
|
17
|
-
};
|
|
18
|
-
type TransProps = {
|
|
19
|
-
id: string;
|
|
20
|
-
message?: string;
|
|
21
|
-
values?: Record<string, unknown>;
|
|
22
|
-
components?: {
|
|
23
|
-
[key: string]: React.ElementType | any;
|
|
24
|
-
};
|
|
25
|
-
formats?: MessageOptions["formats"];
|
|
26
|
-
comment?: string;
|
|
27
|
-
} & TransRenderCallbackOrComponent;
|
|
28
|
-
/**
|
|
29
|
-
* Version of `<Trans>` component without using a Provider/Context React feature.
|
|
30
|
-
* Primarily made for support React Server Components (RSC)
|
|
31
|
-
*
|
|
32
|
-
* @experimental the api of this component is not stabilized yet.
|
|
33
|
-
*/
|
|
34
|
-
declare function TransNoContext(props: TransProps & {
|
|
35
|
-
lingui: {
|
|
36
|
-
i18n: I18n;
|
|
37
|
-
defaultComponent?: React.ComponentType<TransRenderProps>;
|
|
38
|
-
};
|
|
39
|
-
}): React.ReactElement<any, any> | null;
|
|
40
|
-
|
|
41
|
-
type I18nContext = {
|
|
42
|
-
i18n: I18n;
|
|
43
|
-
_: I18n["_"];
|
|
44
|
-
defaultComponent?: React.ComponentType<TransRenderProps>;
|
|
45
|
-
};
|
|
46
|
-
type I18nProviderProps = Omit<I18nContext, "_"> & {
|
|
47
|
-
children?: React.ReactNode;
|
|
48
|
-
};
|
|
49
|
-
declare const LinguiContext: react.Context<I18nContext | null>;
|
|
50
|
-
declare function useLingui(): I18nContext;
|
|
51
|
-
declare const I18nProvider: ({ i18n, defaultComponent, children, }: I18nProviderProps) => react_jsx_runtime.JSX.Element | null;
|
|
52
|
-
|
|
53
|
-
export { I18nProvider as I, LinguiContext as L, type TransProps as T, type I18nProviderProps as a, type I18nContext as b, type TransRenderProps as c, type TransRenderCallbackOrComponent as d, TransNoContext as e, useLingui as u };
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as react from 'react';
|
|
3
|
-
import { MessageOptions, I18n } from '@lingui/core';
|
|
4
|
-
|
|
5
|
-
type TransRenderProps = {
|
|
6
|
-
id: string;
|
|
7
|
-
translation: React.ReactNode;
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
message?: string | null;
|
|
10
|
-
};
|
|
11
|
-
type TransRenderCallbackOrComponent = {
|
|
12
|
-
component?: never;
|
|
13
|
-
render?: ((props: TransRenderProps) => React.ReactElement<any, any>) | null;
|
|
14
|
-
} | {
|
|
15
|
-
component?: React.ComponentType<TransRenderProps> | null;
|
|
16
|
-
render?: never;
|
|
17
|
-
};
|
|
18
|
-
type TransProps = {
|
|
19
|
-
id: string;
|
|
20
|
-
message?: string;
|
|
21
|
-
values?: Record<string, unknown>;
|
|
22
|
-
components?: {
|
|
23
|
-
[key: string]: React.ElementType | any;
|
|
24
|
-
};
|
|
25
|
-
formats?: MessageOptions["formats"];
|
|
26
|
-
comment?: string;
|
|
27
|
-
} & TransRenderCallbackOrComponent;
|
|
28
|
-
/**
|
|
29
|
-
* Version of `<Trans>` component without using a Provider/Context React feature.
|
|
30
|
-
* Primarily made for support React Server Components (RSC)
|
|
31
|
-
*
|
|
32
|
-
* @experimental the api of this component is not stabilized yet.
|
|
33
|
-
*/
|
|
34
|
-
declare function TransNoContext(props: TransProps & {
|
|
35
|
-
lingui: {
|
|
36
|
-
i18n: I18n;
|
|
37
|
-
defaultComponent?: React.ComponentType<TransRenderProps>;
|
|
38
|
-
};
|
|
39
|
-
}): React.ReactElement<any, any> | null;
|
|
40
|
-
|
|
41
|
-
type I18nContext = {
|
|
42
|
-
i18n: I18n;
|
|
43
|
-
_: I18n["_"];
|
|
44
|
-
defaultComponent?: React.ComponentType<TransRenderProps>;
|
|
45
|
-
};
|
|
46
|
-
type I18nProviderProps = Omit<I18nContext, "_"> & {
|
|
47
|
-
children?: React.ReactNode;
|
|
48
|
-
};
|
|
49
|
-
declare const LinguiContext: react.Context<I18nContext | null>;
|
|
50
|
-
declare function useLingui(): I18nContext;
|
|
51
|
-
declare const I18nProvider: ({ i18n, defaultComponent, children, }: I18nProviderProps) => react_jsx_runtime.JSX.Element | null;
|
|
52
|
-
|
|
53
|
-
export { I18nProvider as I, LinguiContext as L, type TransProps as T, type I18nProviderProps as a, type I18nContext as b, type TransRenderProps as c, type TransRenderCallbackOrComponent as d, TransNoContext as e, useLingui as u };
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
const React = require('react');
|
|
5
|
-
|
|
6
|
-
const tagRe = /<([a-zA-Z0-9]+)>([\s\S]*?)<\/\1>|<([a-zA-Z0-9]+)\/>/;
|
|
7
|
-
const voidElementTags = {
|
|
8
|
-
area: true,
|
|
9
|
-
base: true,
|
|
10
|
-
br: true,
|
|
11
|
-
col: true,
|
|
12
|
-
embed: true,
|
|
13
|
-
hr: true,
|
|
14
|
-
img: true,
|
|
15
|
-
input: true,
|
|
16
|
-
keygen: true,
|
|
17
|
-
link: true,
|
|
18
|
-
meta: true,
|
|
19
|
-
param: true,
|
|
20
|
-
source: true,
|
|
21
|
-
track: true,
|
|
22
|
-
wbr: true,
|
|
23
|
-
menuitem: true
|
|
24
|
-
};
|
|
25
|
-
function formatElements(value, elements = {}) {
|
|
26
|
-
const parts = value.split(tagRe);
|
|
27
|
-
if (parts.length === 1)
|
|
28
|
-
return value;
|
|
29
|
-
const uniqueId = makeCounter(0, "$lingui$");
|
|
30
|
-
const tree = [];
|
|
31
|
-
const before = parts.shift();
|
|
32
|
-
if (before)
|
|
33
|
-
tree.push(before);
|
|
34
|
-
for (const [index, children, after] of getElements(parts)) {
|
|
35
|
-
let element = typeof index !== "undefined" ? elements[index] : void 0;
|
|
36
|
-
if (!element || voidElementTags[element.type] && children) {
|
|
37
|
-
if (!element) {
|
|
38
|
-
console.error(
|
|
39
|
-
`Can't use element at index '${index}' as it is not declared in the original translation`
|
|
40
|
-
);
|
|
41
|
-
} else {
|
|
42
|
-
console.error(
|
|
43
|
-
`${element.type} is a void element tag therefore it must have no children`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
element = /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
47
|
-
}
|
|
48
|
-
if (Array.isArray(element)) {
|
|
49
|
-
element = /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: element });
|
|
50
|
-
}
|
|
51
|
-
tree.push(
|
|
52
|
-
React.cloneElement(
|
|
53
|
-
element,
|
|
54
|
-
{ key: uniqueId() },
|
|
55
|
-
// format children for pair tags
|
|
56
|
-
// unpaired tags might have children if it's a component passed as a variable
|
|
57
|
-
children ? formatElements(children, elements) : element.props.children
|
|
58
|
-
)
|
|
59
|
-
);
|
|
60
|
-
if (after)
|
|
61
|
-
tree.push(after);
|
|
62
|
-
}
|
|
63
|
-
return tree.length === 1 ? tree[0] : tree;
|
|
64
|
-
}
|
|
65
|
-
function getElements(parts) {
|
|
66
|
-
if (!parts.length)
|
|
67
|
-
return [];
|
|
68
|
-
const [paired, children, unpaired, after] = parts.slice(0, 4);
|
|
69
|
-
const triple = [paired || unpaired, children || "", after];
|
|
70
|
-
return [triple].concat(getElements(parts.slice(4, parts.length)));
|
|
71
|
-
}
|
|
72
|
-
const makeCounter = (count = 0, prefix = "") => () => `${prefix}_${count++}`;
|
|
73
|
-
|
|
74
|
-
function TransNoContext(props) {
|
|
75
|
-
const {
|
|
76
|
-
render,
|
|
77
|
-
component,
|
|
78
|
-
id,
|
|
79
|
-
message,
|
|
80
|
-
formats,
|
|
81
|
-
lingui: { i18n, defaultComponent }
|
|
82
|
-
} = props;
|
|
83
|
-
const { values, components } = getInterpolationValuesAndComponents(props);
|
|
84
|
-
const _translation = i18n && typeof i18n._ === "function" ? i18n._(id, values, { message, formats }) : id;
|
|
85
|
-
const translation = _translation ? formatElements(_translation, components) : null;
|
|
86
|
-
if (render === null || component === null) {
|
|
87
|
-
return translation;
|
|
88
|
-
}
|
|
89
|
-
const FallbackComponent = defaultComponent || RenderChildren;
|
|
90
|
-
const i18nProps = {
|
|
91
|
-
id,
|
|
92
|
-
message,
|
|
93
|
-
translation,
|
|
94
|
-
children: translation
|
|
95
|
-
// for type-compatibility with `component` prop
|
|
96
|
-
};
|
|
97
|
-
if (render && component) {
|
|
98
|
-
console.error(
|
|
99
|
-
"You can't use both `component` and `render` prop at the same time. `component` is ignored."
|
|
100
|
-
);
|
|
101
|
-
} else if (render && typeof render !== "function") {
|
|
102
|
-
console.error(
|
|
103
|
-
`Invalid value supplied to prop \`render\`. It must be a function, provided ${render}`
|
|
104
|
-
);
|
|
105
|
-
} else if (component && typeof component !== "function") {
|
|
106
|
-
console.error(
|
|
107
|
-
`Invalid value supplied to prop \`component\`. It must be a React component, provided ${component}`
|
|
108
|
-
);
|
|
109
|
-
return /* @__PURE__ */ jsxRuntime.jsx(FallbackComponent, { ...i18nProps, children: translation });
|
|
110
|
-
}
|
|
111
|
-
if (typeof render === "function") {
|
|
112
|
-
return render(i18nProps);
|
|
113
|
-
}
|
|
114
|
-
const Component = component || FallbackComponent;
|
|
115
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...i18nProps, children: translation });
|
|
116
|
-
}
|
|
117
|
-
const RenderChildren = ({ children }) => {
|
|
118
|
-
return children;
|
|
119
|
-
};
|
|
120
|
-
const getInterpolationValuesAndComponents = (props) => {
|
|
121
|
-
if (!props.values) {
|
|
122
|
-
return {
|
|
123
|
-
values: void 0,
|
|
124
|
-
components: props.components
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
const values = { ...props.values };
|
|
128
|
-
const components = { ...props.components };
|
|
129
|
-
Object.entries(props.values).forEach(([key, valueForKey]) => {
|
|
130
|
-
if (typeof valueForKey === "string" || typeof valueForKey === "number") {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const index = Object.keys(components).length;
|
|
134
|
-
components[index] = /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: valueForKey });
|
|
135
|
-
values[key] = `<${index}/>`;
|
|
136
|
-
});
|
|
137
|
-
return { values, components };
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
exports.TransNoContext = TransNoContext;
|
package/macro/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("@lingui/babel-plugin-lingui-macro/macro")
|