@lingui/react 4.0.0-next.3 → 4.0.0-next.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/index.cjs +168 -0
- package/dist/index.mjs +163 -0
- package/package.json +17 -12
- package/build/LICENSE +0 -21
- package/build/cjs/index.js +0 -245
- package/build/cjs/index.js.map +0 -1
- package/build/esm/index.js +0 -240
- package/build/esm/index.js.map +0 -1
- package/build/esm/package.json +0 -3
- package/build/index.js +0 -1
- /package/{build → dist}/index.d.ts +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const React = require('react');
|
|
4
|
+
|
|
5
|
+
const LinguiContext = React.createContext(null);
|
|
6
|
+
function useLingui() {
|
|
7
|
+
const context = React.useContext(LinguiContext);
|
|
8
|
+
if (process.env.NODE_ENV !== "production") {
|
|
9
|
+
if (context == null) {
|
|
10
|
+
throw new Error("useLingui hook was used without I18nProvider.");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return context;
|
|
14
|
+
}
|
|
15
|
+
const I18nProvider = ({
|
|
16
|
+
i18n,
|
|
17
|
+
defaultComponent,
|
|
18
|
+
children
|
|
19
|
+
}) => {
|
|
20
|
+
const latestKnownLocale = React.useRef(i18n.locale);
|
|
21
|
+
const makeContext = React.useCallback(
|
|
22
|
+
() => ({
|
|
23
|
+
i18n,
|
|
24
|
+
defaultComponent
|
|
25
|
+
}),
|
|
26
|
+
[i18n, defaultComponent]
|
|
27
|
+
);
|
|
28
|
+
const [context, setContext] = React.useState(makeContext());
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
const updateContext = () => {
|
|
31
|
+
latestKnownLocale.current = i18n.locale;
|
|
32
|
+
setContext(makeContext());
|
|
33
|
+
};
|
|
34
|
+
const unsubscribe = i18n.on("change", updateContext);
|
|
35
|
+
if (latestKnownLocale.current !== i18n.locale) {
|
|
36
|
+
updateContext();
|
|
37
|
+
}
|
|
38
|
+
return unsubscribe;
|
|
39
|
+
}, [makeContext]);
|
|
40
|
+
if (!latestKnownLocale.current) {
|
|
41
|
+
process.env.NODE_ENV === "development" && console.log(
|
|
42
|
+
"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."
|
|
43
|
+
);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return /* @__PURE__ */ React.createElement(LinguiContext.Provider, { value: context }, children);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const tagRe = /<([a-zA-Z0-9]+)>(.*?)<\/\1>|<([a-zA-Z0-9]+)\/>/;
|
|
50
|
+
const nlRe = /(?:\r\n|\r|\n)/g;
|
|
51
|
+
const voidElementTags = {
|
|
52
|
+
area: true,
|
|
53
|
+
base: true,
|
|
54
|
+
br: true,
|
|
55
|
+
col: true,
|
|
56
|
+
embed: true,
|
|
57
|
+
hr: true,
|
|
58
|
+
img: true,
|
|
59
|
+
input: true,
|
|
60
|
+
keygen: true,
|
|
61
|
+
link: true,
|
|
62
|
+
meta: true,
|
|
63
|
+
param: true,
|
|
64
|
+
source: true,
|
|
65
|
+
track: true,
|
|
66
|
+
wbr: true,
|
|
67
|
+
menuitem: true
|
|
68
|
+
};
|
|
69
|
+
function formatElements(value, elements = {}) {
|
|
70
|
+
const uniqueId = makeCounter(0, "$lingui$");
|
|
71
|
+
const parts = value.replace(nlRe, "").split(tagRe);
|
|
72
|
+
if (parts.length === 1)
|
|
73
|
+
return value;
|
|
74
|
+
const tree = [];
|
|
75
|
+
const before = parts.shift();
|
|
76
|
+
if (before)
|
|
77
|
+
tree.push(before);
|
|
78
|
+
for (const [index, children, after] of getElements(parts)) {
|
|
79
|
+
let element = elements[index];
|
|
80
|
+
if (!element || voidElementTags[element.type] && children) {
|
|
81
|
+
if (!element) {
|
|
82
|
+
console.error(
|
|
83
|
+
`Can't use element at index '${index}' as it is not declared in the original translation`
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
console.error(
|
|
87
|
+
`${element.type} is a void element tag therefore it must have no children`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
element = React.createElement(React.Fragment);
|
|
91
|
+
}
|
|
92
|
+
tree.push(
|
|
93
|
+
React.cloneElement(
|
|
94
|
+
element,
|
|
95
|
+
{ key: uniqueId() },
|
|
96
|
+
// format children for pair tags
|
|
97
|
+
// unpaired tags might have children if it's a component passed as a variable
|
|
98
|
+
children ? formatElements(children, elements) : element.props.children
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
if (after)
|
|
102
|
+
tree.push(after);
|
|
103
|
+
}
|
|
104
|
+
return tree;
|
|
105
|
+
}
|
|
106
|
+
function getElements(parts) {
|
|
107
|
+
if (!parts.length)
|
|
108
|
+
return [];
|
|
109
|
+
const [paired, children, unpaired, after] = parts.slice(0, 4);
|
|
110
|
+
return [[paired || unpaired, children || "", after]].concat(
|
|
111
|
+
getElements(parts.slice(4, parts.length))
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
const makeCounter = (count = 0, prefix = "") => () => `${prefix}_${count++}`;
|
|
115
|
+
|
|
116
|
+
function Trans(props) {
|
|
117
|
+
const { i18n, defaultComponent } = useLingui();
|
|
118
|
+
const { render, component, id, message, formats } = props;
|
|
119
|
+
const values = { ...props.values || {} };
|
|
120
|
+
const components = { ...props.components || {} };
|
|
121
|
+
if (values) {
|
|
122
|
+
Object.keys(values).forEach((key) => {
|
|
123
|
+
const value = values[key];
|
|
124
|
+
if (!React.isValidElement(value))
|
|
125
|
+
return;
|
|
126
|
+
const index = Object.keys(components).length;
|
|
127
|
+
components[index] = value;
|
|
128
|
+
values[key] = `<${index}/>`;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
const _translation = i18n && typeof i18n._ === "function" ? i18n._(id, values, { message, formats }) : id;
|
|
132
|
+
const translation = _translation ? formatElements(_translation, components) : null;
|
|
133
|
+
if (render === null || component === null) {
|
|
134
|
+
return translation;
|
|
135
|
+
}
|
|
136
|
+
const FallbackComponent = defaultComponent || React.Fragment;
|
|
137
|
+
const i18nProps = {
|
|
138
|
+
id,
|
|
139
|
+
message,
|
|
140
|
+
translation,
|
|
141
|
+
isTranslated: id !== translation && message !== translation
|
|
142
|
+
};
|
|
143
|
+
if (render && component) {
|
|
144
|
+
console.error(
|
|
145
|
+
"You can't use both `component` and `render` prop at the same time. `component` is ignored."
|
|
146
|
+
);
|
|
147
|
+
} else if (render && typeof render !== "function") {
|
|
148
|
+
console.error(
|
|
149
|
+
`Invalid value supplied to prop \`render\`. It must be a function, provided ${render}`
|
|
150
|
+
);
|
|
151
|
+
} else if (component && typeof component !== "function") {
|
|
152
|
+
console.error(
|
|
153
|
+
`Invalid value supplied to prop \`component\`. It must be a React component, provided ${component}`
|
|
154
|
+
);
|
|
155
|
+
return /* @__PURE__ */ React.createElement(FallbackComponent, { ...i18nProps }, translation);
|
|
156
|
+
}
|
|
157
|
+
if (typeof render === "function") {
|
|
158
|
+
return render(i18nProps);
|
|
159
|
+
}
|
|
160
|
+
const Component = component || FallbackComponent;
|
|
161
|
+
const DefaultComponent = defaultComponent;
|
|
162
|
+
return DefaultComponent && !component ? /* @__PURE__ */ React.createElement(DefaultComponent, { ...i18nProps }, translation) : /* @__PURE__ */ React.createElement(Component, null, translation);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
exports.I18nProvider = I18nProvider;
|
|
166
|
+
exports.LinguiContext = LinguiContext;
|
|
167
|
+
exports.Trans = Trans;
|
|
168
|
+
exports.useLingui = useLingui;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const LinguiContext = React.createContext(null);
|
|
4
|
+
function useLingui() {
|
|
5
|
+
const context = React.useContext(LinguiContext);
|
|
6
|
+
if (process.env.NODE_ENV !== "production") {
|
|
7
|
+
if (context == null) {
|
|
8
|
+
throw new Error("useLingui hook was used without I18nProvider.");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
13
|
+
const I18nProvider = ({
|
|
14
|
+
i18n,
|
|
15
|
+
defaultComponent,
|
|
16
|
+
children
|
|
17
|
+
}) => {
|
|
18
|
+
const latestKnownLocale = React.useRef(i18n.locale);
|
|
19
|
+
const makeContext = React.useCallback(
|
|
20
|
+
() => ({
|
|
21
|
+
i18n,
|
|
22
|
+
defaultComponent
|
|
23
|
+
}),
|
|
24
|
+
[i18n, defaultComponent]
|
|
25
|
+
);
|
|
26
|
+
const [context, setContext] = React.useState(makeContext());
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
const updateContext = () => {
|
|
29
|
+
latestKnownLocale.current = i18n.locale;
|
|
30
|
+
setContext(makeContext());
|
|
31
|
+
};
|
|
32
|
+
const unsubscribe = i18n.on("change", updateContext);
|
|
33
|
+
if (latestKnownLocale.current !== i18n.locale) {
|
|
34
|
+
updateContext();
|
|
35
|
+
}
|
|
36
|
+
return unsubscribe;
|
|
37
|
+
}, [makeContext]);
|
|
38
|
+
if (!latestKnownLocale.current) {
|
|
39
|
+
process.env.NODE_ENV === "development" && console.log(
|
|
40
|
+
"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."
|
|
41
|
+
);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return /* @__PURE__ */ React.createElement(LinguiContext.Provider, { value: context }, children);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const tagRe = /<([a-zA-Z0-9]+)>(.*?)<\/\1>|<([a-zA-Z0-9]+)\/>/;
|
|
48
|
+
const nlRe = /(?:\r\n|\r|\n)/g;
|
|
49
|
+
const voidElementTags = {
|
|
50
|
+
area: true,
|
|
51
|
+
base: true,
|
|
52
|
+
br: true,
|
|
53
|
+
col: true,
|
|
54
|
+
embed: true,
|
|
55
|
+
hr: true,
|
|
56
|
+
img: true,
|
|
57
|
+
input: true,
|
|
58
|
+
keygen: true,
|
|
59
|
+
link: true,
|
|
60
|
+
meta: true,
|
|
61
|
+
param: true,
|
|
62
|
+
source: true,
|
|
63
|
+
track: true,
|
|
64
|
+
wbr: true,
|
|
65
|
+
menuitem: true
|
|
66
|
+
};
|
|
67
|
+
function formatElements(value, elements = {}) {
|
|
68
|
+
const uniqueId = makeCounter(0, "$lingui$");
|
|
69
|
+
const parts = value.replace(nlRe, "").split(tagRe);
|
|
70
|
+
if (parts.length === 1)
|
|
71
|
+
return value;
|
|
72
|
+
const tree = [];
|
|
73
|
+
const before = parts.shift();
|
|
74
|
+
if (before)
|
|
75
|
+
tree.push(before);
|
|
76
|
+
for (const [index, children, after] of getElements(parts)) {
|
|
77
|
+
let element = elements[index];
|
|
78
|
+
if (!element || voidElementTags[element.type] && children) {
|
|
79
|
+
if (!element) {
|
|
80
|
+
console.error(
|
|
81
|
+
`Can't use element at index '${index}' as it is not declared in the original translation`
|
|
82
|
+
);
|
|
83
|
+
} else {
|
|
84
|
+
console.error(
|
|
85
|
+
`${element.type} is a void element tag therefore it must have no children`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
element = React.createElement(React.Fragment);
|
|
89
|
+
}
|
|
90
|
+
tree.push(
|
|
91
|
+
React.cloneElement(
|
|
92
|
+
element,
|
|
93
|
+
{ key: uniqueId() },
|
|
94
|
+
// format children for pair tags
|
|
95
|
+
// unpaired tags might have children if it's a component passed as a variable
|
|
96
|
+
children ? formatElements(children, elements) : element.props.children
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
if (after)
|
|
100
|
+
tree.push(after);
|
|
101
|
+
}
|
|
102
|
+
return tree;
|
|
103
|
+
}
|
|
104
|
+
function getElements(parts) {
|
|
105
|
+
if (!parts.length)
|
|
106
|
+
return [];
|
|
107
|
+
const [paired, children, unpaired, after] = parts.slice(0, 4);
|
|
108
|
+
return [[paired || unpaired, children || "", after]].concat(
|
|
109
|
+
getElements(parts.slice(4, parts.length))
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const makeCounter = (count = 0, prefix = "") => () => `${prefix}_${count++}`;
|
|
113
|
+
|
|
114
|
+
function Trans(props) {
|
|
115
|
+
const { i18n, defaultComponent } = useLingui();
|
|
116
|
+
const { render, component, id, message, formats } = props;
|
|
117
|
+
const values = { ...props.values || {} };
|
|
118
|
+
const components = { ...props.components || {} };
|
|
119
|
+
if (values) {
|
|
120
|
+
Object.keys(values).forEach((key) => {
|
|
121
|
+
const value = values[key];
|
|
122
|
+
if (!React.isValidElement(value))
|
|
123
|
+
return;
|
|
124
|
+
const index = Object.keys(components).length;
|
|
125
|
+
components[index] = value;
|
|
126
|
+
values[key] = `<${index}/>`;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const _translation = i18n && typeof i18n._ === "function" ? i18n._(id, values, { message, formats }) : id;
|
|
130
|
+
const translation = _translation ? formatElements(_translation, components) : null;
|
|
131
|
+
if (render === null || component === null) {
|
|
132
|
+
return translation;
|
|
133
|
+
}
|
|
134
|
+
const FallbackComponent = defaultComponent || React.Fragment;
|
|
135
|
+
const i18nProps = {
|
|
136
|
+
id,
|
|
137
|
+
message,
|
|
138
|
+
translation,
|
|
139
|
+
isTranslated: id !== translation && message !== translation
|
|
140
|
+
};
|
|
141
|
+
if (render && component) {
|
|
142
|
+
console.error(
|
|
143
|
+
"You can't use both `component` and `render` prop at the same time. `component` is ignored."
|
|
144
|
+
);
|
|
145
|
+
} else if (render && typeof render !== "function") {
|
|
146
|
+
console.error(
|
|
147
|
+
`Invalid value supplied to prop \`render\`. It must be a function, provided ${render}`
|
|
148
|
+
);
|
|
149
|
+
} else if (component && typeof component !== "function") {
|
|
150
|
+
console.error(
|
|
151
|
+
`Invalid value supplied to prop \`component\`. It must be a React component, provided ${component}`
|
|
152
|
+
);
|
|
153
|
+
return /* @__PURE__ */ React.createElement(FallbackComponent, { ...i18nProps }, translation);
|
|
154
|
+
}
|
|
155
|
+
if (typeof render === "function") {
|
|
156
|
+
return render(i18nProps);
|
|
157
|
+
}
|
|
158
|
+
const Component = component || FallbackComponent;
|
|
159
|
+
const DefaultComponent = defaultComponent;
|
|
160
|
+
return DefaultComponent && !component ? /* @__PURE__ */ React.createElement(DefaultComponent, { ...i18nProps }, translation) : /* @__PURE__ */ React.createElement(Component, null, translation);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { I18nProvider, LinguiContext, Trans, useLingui };
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/react",
|
|
3
|
-
"version": "4.0.0-next.
|
|
3
|
+
"version": "4.0.0-next.4",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "React components for translations",
|
|
6
|
-
"main": "./
|
|
7
|
-
"module": "./
|
|
8
|
-
"types": "./
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
9
|
"author": {
|
|
10
10
|
"name": "Tomáš Ehrlich",
|
|
11
11
|
"email": "tomas.ehrlich@gmail.com"
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"icu",
|
|
22
22
|
"messageformat"
|
|
23
23
|
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "rimraf ./dist && unbuild",
|
|
26
|
+
"stub": "unbuild --stub"
|
|
27
|
+
},
|
|
24
28
|
"repository": {
|
|
25
29
|
"type": "git",
|
|
26
30
|
"url": "https://github.com/lingui/js-lingui.git"
|
|
@@ -34,12 +38,12 @@
|
|
|
34
38
|
"exports": {
|
|
35
39
|
".": {
|
|
36
40
|
"require": {
|
|
37
|
-
"types": "./
|
|
38
|
-
"default": "./
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"default": "./dist/index.cjs"
|
|
39
43
|
},
|
|
40
44
|
"import": {
|
|
41
|
-
"types": "./
|
|
42
|
-
"default": "./
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"default": "./dist/index.mjs"
|
|
43
47
|
}
|
|
44
48
|
},
|
|
45
49
|
"./package.json": "./package.json"
|
|
@@ -47,17 +51,18 @@
|
|
|
47
51
|
"files": [
|
|
48
52
|
"LICENSE",
|
|
49
53
|
"README.md",
|
|
50
|
-
"
|
|
54
|
+
"dist/"
|
|
51
55
|
],
|
|
52
56
|
"peerDependencies": {
|
|
53
57
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
54
58
|
},
|
|
55
59
|
"dependencies": {
|
|
56
60
|
"@babel/runtime": "^7.20.13",
|
|
57
|
-
"@lingui/core": "^4.0.0-next.
|
|
61
|
+
"@lingui/core": "^4.0.0-next.4"
|
|
58
62
|
},
|
|
59
63
|
"devDependencies": {
|
|
60
|
-
"@testing-library/react": "^11.0.4"
|
|
64
|
+
"@testing-library/react": "^11.0.4",
|
|
65
|
+
"unbuild": "^1.1.2"
|
|
61
66
|
},
|
|
62
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "3b999e35d26e67dec7cf0591f794be782e11022c"
|
|
63
68
|
}
|
package/build/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017-2022 Tomáš Ehrlich, (c) 2022-2023 Crowdin.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
package/build/cjs/index.js
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
|
|
5
|
-
const LinguiContext = /*#__PURE__*/React.createContext(null);
|
|
6
|
-
function useLingui() {
|
|
7
|
-
const context = React.useContext(LinguiContext);
|
|
8
|
-
if (process.env.NODE_ENV !== "production") {
|
|
9
|
-
if (context == null) {
|
|
10
|
-
throw new Error("useLingui hook was used without I18nProvider.");
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return context;
|
|
14
|
-
}
|
|
15
|
-
const I18nProvider = _ref => {
|
|
16
|
-
let {
|
|
17
|
-
i18n,
|
|
18
|
-
defaultComponent,
|
|
19
|
-
children
|
|
20
|
-
} = _ref;
|
|
21
|
-
const latestKnownLocale = React.useRef(i18n.locale);
|
|
22
|
-
/**
|
|
23
|
-
* We can't pass `i18n` object directly through context, because even when locale
|
|
24
|
-
* or messages are changed, i18n object is still the same. Context provider compares
|
|
25
|
-
* reference identity and suggested workaround is to create a wrapper object every time
|
|
26
|
-
* we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.
|
|
27
|
-
*
|
|
28
|
-
* Due to this effect we also pass `defaultComponent` in the same context, instead
|
|
29
|
-
* of creating a separate Provider/Consumer pair.
|
|
30
|
-
*
|
|
31
|
-
* We can't use useMemo hook either, because we want to recalculate value manually.
|
|
32
|
-
*/
|
|
33
|
-
const makeContext = React.useCallback(() => ({
|
|
34
|
-
i18n,
|
|
35
|
-
defaultComponent
|
|
36
|
-
}), [i18n, defaultComponent]);
|
|
37
|
-
const [context, setContext] = React.useState(makeContext());
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Subscribe for locale/message changes
|
|
41
|
-
*
|
|
42
|
-
* I18n object from `@lingui/core` is the single source of truth for all i18n related
|
|
43
|
-
* data (active locale, catalogs). When new messages are loaded or locale is changed
|
|
44
|
-
* we need to trigger re-rendering of LinguiContext.Consumers.
|
|
45
|
-
*/
|
|
46
|
-
React.useEffect(() => {
|
|
47
|
-
const updateContext = () => {
|
|
48
|
-
latestKnownLocale.current = i18n.locale;
|
|
49
|
-
setContext(makeContext());
|
|
50
|
-
};
|
|
51
|
-
const unsubscribe = i18n.on("change", updateContext);
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* unlikely, but if the locale changes before the onChange listener
|
|
55
|
-
* was added, we need to trigger a rerender
|
|
56
|
-
* */
|
|
57
|
-
if (latestKnownLocale.current !== i18n.locale) {
|
|
58
|
-
updateContext();
|
|
59
|
-
}
|
|
60
|
-
return unsubscribe;
|
|
61
|
-
}, [makeContext]);
|
|
62
|
-
if (!latestKnownLocale.current) {
|
|
63
|
-
process.env.NODE_ENV === "development" && console.log("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.");
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
return /*#__PURE__*/React.createElement(LinguiContext.Provider, {
|
|
67
|
-
value: context
|
|
68
|
-
}, children);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
// match <tag>paired</tag> and <tag/> unpaired tags
|
|
72
|
-
const tagRe = /<([a-zA-Z0-9]+)>(.*?)<\/\1>|<([a-zA-Z0-9]+)\/>/;
|
|
73
|
-
const nlRe = /(?:\r\n|\r|\n)/g;
|
|
74
|
-
|
|
75
|
-
// For HTML, certain tags should omit their close tag. We keep a whitelist for
|
|
76
|
-
// those special-case tags.
|
|
77
|
-
const voidElementTags = {
|
|
78
|
-
area: true,
|
|
79
|
-
base: true,
|
|
80
|
-
br: true,
|
|
81
|
-
col: true,
|
|
82
|
-
embed: true,
|
|
83
|
-
hr: true,
|
|
84
|
-
img: true,
|
|
85
|
-
input: true,
|
|
86
|
-
keygen: true,
|
|
87
|
-
link: true,
|
|
88
|
-
meta: true,
|
|
89
|
-
param: true,
|
|
90
|
-
source: true,
|
|
91
|
-
track: true,
|
|
92
|
-
wbr: true,
|
|
93
|
-
menuitem: true
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* `formatElements` - parse string and return tree of react elements
|
|
98
|
-
*
|
|
99
|
-
* `value` is string to be formatted with <tag>Paired<tag/> or <tag/> (unpaired)
|
|
100
|
-
* placeholders. `elements` is a array of react elements which indexes
|
|
101
|
-
* correspond to element indexes in formatted string
|
|
102
|
-
*/
|
|
103
|
-
function formatElements(value) {
|
|
104
|
-
let elements = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
105
|
-
const uniqueId = makeCounter(0, "$lingui$");
|
|
106
|
-
const parts = value.replace(nlRe, "").split(tagRe);
|
|
107
|
-
|
|
108
|
-
// no inline elements, return
|
|
109
|
-
if (parts.length === 1) return value;
|
|
110
|
-
const tree = [];
|
|
111
|
-
const before = parts.shift();
|
|
112
|
-
if (before) tree.push(before);
|
|
113
|
-
for (const [index, children, after] of getElements(parts)) {
|
|
114
|
-
let element = elements[index];
|
|
115
|
-
if (!element || voidElementTags[element.type] && children) {
|
|
116
|
-
if (!element) {
|
|
117
|
-
console.error(`Can't use element at index '${index}' as it is not declared in the original translation`);
|
|
118
|
-
} else {
|
|
119
|
-
console.error(`${element.type} is a void element tag therefore it must have no children`);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// ignore problematic element but push its children and elements after it
|
|
123
|
-
element = /*#__PURE__*/React.createElement(React.Fragment);
|
|
124
|
-
}
|
|
125
|
-
tree.push( /*#__PURE__*/React.cloneElement(element, {
|
|
126
|
-
key: uniqueId()
|
|
127
|
-
},
|
|
128
|
-
// format children for pair tags
|
|
129
|
-
// unpaired tags might have children if it's a component passed as a variable
|
|
130
|
-
children ? formatElements(children, elements) : element.props.children));
|
|
131
|
-
if (after) tree.push(after);
|
|
132
|
-
}
|
|
133
|
-
return tree;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/*
|
|
137
|
-
* `getElements` - return array of element indexes and element childrens
|
|
138
|
-
*
|
|
139
|
-
* `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]
|
|
140
|
-
* where:
|
|
141
|
-
* - `pairedIndex` is index of paired element (undef for unpaired)
|
|
142
|
-
* - `children` are children of paired element (undef for unpaired)
|
|
143
|
-
* - `unpairedIndex` is index of unpaired element (undef for paired)
|
|
144
|
-
* - `textAfter` is string after all elements (empty string, if there's nothing)
|
|
145
|
-
*
|
|
146
|
-
* `parts` length is always multiply of 4
|
|
147
|
-
*
|
|
148
|
-
* Returns: Array<[elementIndex, children, after]>
|
|
149
|
-
*/
|
|
150
|
-
function getElements(parts) {
|
|
151
|
-
if (!parts.length) return [];
|
|
152
|
-
const [paired, children, unpaired, after] = parts.slice(0, 4);
|
|
153
|
-
return [[paired || unpaired, children || "", after]].concat(getElements(parts.slice(4, parts.length)));
|
|
154
|
-
}
|
|
155
|
-
const makeCounter = function () {
|
|
156
|
-
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
157
|
-
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
158
|
-
return () => `${prefix}_${count++}`;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
function Trans(props) {
|
|
162
|
-
const {
|
|
163
|
-
i18n,
|
|
164
|
-
defaultComponent
|
|
165
|
-
} = useLingui();
|
|
166
|
-
const {
|
|
167
|
-
render,
|
|
168
|
-
component,
|
|
169
|
-
id,
|
|
170
|
-
message,
|
|
171
|
-
formats
|
|
172
|
-
} = props;
|
|
173
|
-
const values = {
|
|
174
|
-
...(props.values || {})
|
|
175
|
-
};
|
|
176
|
-
const components = {
|
|
177
|
-
...(props.components || {})
|
|
178
|
-
};
|
|
179
|
-
if (values) {
|
|
180
|
-
/*
|
|
181
|
-
Related discussion: https://github.com/lingui/js-lingui/issues/183
|
|
182
|
-
Values *might* contain React elements with static content.
|
|
183
|
-
They're replaced with <INDEX /> placeholders and added to `components`.
|
|
184
|
-
Example:
|
|
185
|
-
Translation: Hello {name}
|
|
186
|
-
Values: { name: <strong>Jane</strong> }
|
|
187
|
-
It'll become "Hello <0 />" with components=[<strong>Jane</strong>]
|
|
188
|
-
*/
|
|
189
|
-
|
|
190
|
-
Object.keys(values).forEach(key => {
|
|
191
|
-
const value = values[key];
|
|
192
|
-
if (! /*#__PURE__*/React.isValidElement(value)) return;
|
|
193
|
-
const index = Object.keys(components).length;
|
|
194
|
-
components[index] = value;
|
|
195
|
-
values[key] = `<${index}/>`;
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
const _translation = i18n && typeof i18n._ === "function" ? i18n._(id, values, {
|
|
199
|
-
message,
|
|
200
|
-
formats
|
|
201
|
-
}) : id; // i18n provider isn't loaded at all
|
|
202
|
-
|
|
203
|
-
const translation = _translation ? formatElements(_translation, components) : null;
|
|
204
|
-
if (render === null || component === null) {
|
|
205
|
-
// Although `string` is a valid react element, types only allow `Element`
|
|
206
|
-
// Upstream issue: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544
|
|
207
|
-
return translation;
|
|
208
|
-
}
|
|
209
|
-
const FallbackComponent = defaultComponent || React.Fragment;
|
|
210
|
-
const i18nProps = {
|
|
211
|
-
id,
|
|
212
|
-
message,
|
|
213
|
-
translation,
|
|
214
|
-
isTranslated: id !== translation && message !== translation
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
// Validation of `render` and `component` props
|
|
218
|
-
if (render && component) {
|
|
219
|
-
console.error("You can't use both `component` and `render` prop at the same time. `component` is ignored.");
|
|
220
|
-
} else if (render && typeof render !== "function") {
|
|
221
|
-
console.error(`Invalid value supplied to prop \`render\`. It must be a function, provided ${render}`);
|
|
222
|
-
} else if (component && typeof component !== "function") {
|
|
223
|
-
// Apparently, both function components and class components are functions
|
|
224
|
-
// See https://stackoverflow.com/a/41658173/1535540
|
|
225
|
-
console.error(`Invalid value supplied to prop \`component\`. It must be a React component, provided ${component}`);
|
|
226
|
-
return /*#__PURE__*/React.createElement(FallbackComponent, i18nProps, translation);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Rendering using a render prop
|
|
230
|
-
if (typeof render === "function") {
|
|
231
|
-
// Component: render={(props) => <a title={props.translation}>x</a>}
|
|
232
|
-
return render(i18nProps);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// `component` prop has a higher precedence over `defaultComponent`
|
|
236
|
-
const Component = component || FallbackComponent;
|
|
237
|
-
const DefaultComponent = defaultComponent;
|
|
238
|
-
return DefaultComponent && !component ? /*#__PURE__*/React.createElement(DefaultComponent, i18nProps, translation) : /*#__PURE__*/React.createElement(Component, null, translation);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
exports.I18nProvider = I18nProvider;
|
|
242
|
-
exports.LinguiContext = LinguiContext;
|
|
243
|
-
exports.Trans = Trans;
|
|
244
|
-
exports.useLingui = useLingui;
|
|
245
|
-
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/I18nProvider.tsx","../../src/format.ts","../../src/Trans.tsx"],"sourcesContent":["import React, { ComponentType, FunctionComponent } from \"react\"\nimport { I18n } from \"@lingui/core\"\nimport { TransRenderProps } from \"./Trans\"\n\nexport type I18nContext = {\n i18n: I18n\n defaultComponent?: ComponentType<TransRenderProps>\n}\n\nexport type I18nProviderProps = I18nContext & {\n children?: React.ReactNode\n}\n\nexport const LinguiContext = React.createContext<I18nContext>(null)\n\nexport function useLingui(): I18nContext {\n const context = React.useContext<I18nContext>(LinguiContext)\n\n if (process.env.NODE_ENV !== \"production\") {\n if (context == null) {\n throw new Error(\"useLingui hook was used without I18nProvider.\")\n }\n }\n\n return context\n}\n\nexport const I18nProvider: FunctionComponent<I18nProviderProps> = ({\n i18n,\n defaultComponent,\n children,\n}) => {\n const latestKnownLocale = React.useRef<string | undefined>(i18n.locale)\n /**\n * We can't pass `i18n` object directly through context, because even when locale\n * or messages are changed, i18n object is still the same. Context provider compares\n * reference identity and suggested workaround is to create a wrapper object every time\n * we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.\n *\n * Due to this effect we also pass `defaultComponent` in the same context, instead\n * of creating a separate Provider/Consumer pair.\n *\n * We can't use useMemo hook either, because we want to recalculate value manually.\n */\n const makeContext = React.useCallback(\n () => ({\n i18n,\n defaultComponent,\n }),\n [i18n, defaultComponent]\n )\n\n const [context, setContext] = React.useState<I18nContext>(makeContext())\n\n /**\n * Subscribe for locale/message changes\n *\n * I18n object from `@lingui/core` is the single source of truth for all i18n related\n * data (active locale, catalogs). When new messages are loaded or locale is changed\n * we need to trigger re-rendering of LinguiContext.Consumers.\n */\n React.useEffect(() => {\n const updateContext = () => {\n latestKnownLocale.current = i18n.locale\n setContext(makeContext())\n }\n const unsubscribe = i18n.on(\"change\", updateContext)\n\n /**\n * unlikely, but if the locale changes before the onChange listener\n * was added, we need to trigger a rerender\n * */\n if (latestKnownLocale.current !== i18n.locale) {\n updateContext()\n }\n return unsubscribe\n }, [makeContext])\n\n if (!latestKnownLocale.current) {\n process.env.NODE_ENV === \"development\" &&\n console.log(\n \"I18nProvider rendered `null`. A call to `i18n.activate` needs to happen in order for translations to be activated and for the I18nProvider to render.\" +\n \"This is not an error but an informational message logged only in development.\"\n )\n return null\n }\n\n return (\n <LinguiContext.Provider value={context}>{children}</LinguiContext.Provider>\n )\n}\n","import React from \"react\"\n\n// match <tag>paired</tag> and <tag/> unpaired tags\nconst tagRe = /<([a-zA-Z0-9]+)>(.*?)<\\/\\1>|<([a-zA-Z0-9]+)\\/>/\nconst nlRe = /(?:\\r\\n|\\r|\\n)/g\n\n// For HTML, certain tags should omit their close tag. We keep a whitelist for\n// those special-case tags.\nconst voidElementTags = {\n area: true,\n base: true,\n br: true,\n col: true,\n embed: true,\n hr: true,\n img: true,\n input: true,\n keygen: true,\n link: true,\n meta: true,\n param: true,\n source: true,\n track: true,\n wbr: true,\n menuitem: true,\n}\n\n/**\n * `formatElements` - parse string and return tree of react elements\n *\n * `value` is string to be formatted with <tag>Paired<tag/> or <tag/> (unpaired)\n * placeholders. `elements` is a array of react elements which indexes\n * correspond to element indexes in formatted string\n */\nfunction formatElements(\n value: string,\n elements: { [key: string]: React.ReactElement<any> } = {}\n): string | Array<any> {\n const uniqueId = makeCounter(0, \"$lingui$\")\n const parts = value.replace(nlRe, \"\").split(tagRe)\n\n // no inline elements, return\n if (parts.length === 1) return value\n\n const tree = []\n\n const before = parts.shift()\n if (before) tree.push(before)\n\n for (const [index, children, after] of getElements(parts)) {\n let element = elements[index]\n\n if (!element || (voidElementTags[element.type as string] && children)) {\n if (!element) {\n console.error(\n `Can't use element at index '${index}' as it is not declared in the original translation`\n )\n } else {\n console.error(\n `${element.type} is a void element tag therefore it must have no children`\n )\n }\n\n // ignore problematic element but push its children and elements after it\n element = React.createElement(React.Fragment)\n }\n\n tree.push(\n React.cloneElement(\n element,\n { key: uniqueId() },\n\n // format children for pair tags\n // unpaired tags might have children if it's a component passed as a variable\n children ? formatElements(children, elements) : element.props.children\n )\n )\n\n if (after) tree.push(after)\n }\n\n return tree\n}\n\n/*\n * `getElements` - return array of element indexes and element childrens\n *\n * `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]\n * where:\n * - `pairedIndex` is index of paired element (undef for unpaired)\n * - `children` are children of paired element (undef for unpaired)\n * - `unpairedIndex` is index of unpaired element (undef for paired)\n * - `textAfter` is string after all elements (empty string, if there's nothing)\n *\n * `parts` length is always multiply of 4\n *\n * Returns: Array<[elementIndex, children, after]>\n */\nfunction getElements(parts) {\n if (!parts.length) return []\n\n const [paired, children, unpaired, after] = parts.slice(0, 4)\n\n return [[paired || unpaired, children || \"\", after]].concat(\n getElements(parts.slice(4, parts.length))\n )\n}\n\nconst makeCounter =\n (count = 0, prefix = \"\") =>\n () =>\n `${prefix}_${count++}`\n\nexport { formatElements }\n","import React from \"react\"\n\nimport { useLingui } from \"./I18nProvider\"\nimport { formatElements } from \"./format\"\n\nexport type TransRenderProps = {\n id?: string\n translation?: React.ReactNode\n children?: React.ReactNode\n message?: string | null\n isTranslated?: boolean\n}\n\nexport type TransProps = {\n id: string\n message?: string\n values?: Record<string, unknown>\n components?: { [key: string]: React.ElementType | any }\n formats?: Record<string, unknown>\n children?: React.ReactNode\n component?: React.ComponentType<TransRenderProps>\n render?: (props: TransRenderProps) => React.ReactElement<any, any> | null\n}\n\nexport function Trans(props: TransProps): React.ReactElement<any, any> | null {\n const { i18n, defaultComponent } = useLingui()\n const { render, component, id, message, formats } = props\n\n const values = { ...(props.values || {}) }\n const components = { ...(props.components || {}) }\n\n if (values) {\n /*\n Related discussion: https://github.com/lingui/js-lingui/issues/183\n\n Values *might* contain React elements with static content.\n They're replaced with <INDEX /> placeholders and added to `components`.\n\n Example:\n Translation: Hello {name}\n Values: { name: <strong>Jane</strong> }\n\n It'll become \"Hello <0 />\" with components=[<strong>Jane</strong>]\n */\n\n Object.keys(values).forEach((key) => {\n const value = values[key]\n if (!React.isValidElement(value)) return\n\n const index = Object.keys(components).length\n\n components[index] = value\n values[key] = `<${index}/>`\n })\n }\n\n const _translation: string =\n i18n && typeof i18n._ === \"function\"\n ? i18n._(id, values, { message, formats })\n : id // i18n provider isn't loaded at all\n\n const translation = _translation\n ? formatElements(_translation, components)\n : null\n\n if (render === null || component === null) {\n // Although `string` is a valid react element, types only allow `Element`\n // Upstream issue: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544\n return translation as unknown as React.ReactElement<any, any>\n }\n\n const FallbackComponent = (defaultComponent ||\n React.Fragment) as React.ComponentType<any>\n\n const i18nProps = {\n id,\n message,\n translation,\n isTranslated: id !== translation && message !== translation,\n }\n\n // Validation of `render` and `component` props\n if (render && component) {\n console.error(\n \"You can't use both `component` and `render` prop at the same time. `component` is ignored.\"\n )\n } else if (render && typeof render !== \"function\") {\n console.error(\n `Invalid value supplied to prop \\`render\\`. It must be a function, provided ${render}`\n )\n } else if (component && typeof component !== \"function\") {\n // Apparently, both function components and class components are functions\n // See https://stackoverflow.com/a/41658173/1535540\n console.error(\n `Invalid value supplied to prop \\`component\\`. It must be a React component, provided ${component}`\n )\n return <FallbackComponent {...i18nProps}>{translation}</FallbackComponent>\n }\n\n // Rendering using a render prop\n if (typeof render === \"function\") {\n // Component: render={(props) => <a title={props.translation}>x</a>}\n return render(i18nProps)\n }\n\n // `component` prop has a higher precedence over `defaultComponent`\n const Component = (component || FallbackComponent) as React.ComponentType<any>\n const DefaultComponent = defaultComponent\n\n return DefaultComponent && !component ? (\n <DefaultComponent {...i18nProps}>{translation}</DefaultComponent>\n ) : (\n <Component>{translation}</Component>\n )\n}\n"],"names":["LinguiContext","React","createContext","useLingui","context","useContext","process","env","NODE_ENV","Error","I18nProvider","i18n","defaultComponent","children","latestKnownLocale","useRef","locale","makeContext","useCallback","setContext","useState","useEffect","updateContext","current","unsubscribe","on","console","log","tagRe","nlRe","voidElementTags","area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr","menuitem","formatElements","value","elements","uniqueId","makeCounter","parts","replace","split","length","tree","before","shift","push","index","after","getElements","element","type","error","createElement","Fragment","cloneElement","key","props","paired","unpaired","slice","concat","count","prefix","Trans","render","component","id","message","formats","values","components","Object","keys","forEach","isValidElement","_translation","_","translation","FallbackComponent","i18nProps","isTranslated","Component","Default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oBAAC,gBAAgB,EAAKc,SAAS,EAAGF,WAAW,CAAoB,gBAEjE,oBAAC,SAAS,EAAA,IAAA,EAAEA,WAAW,CACxB,CAAA;AACH;;;;;;;"}
|
package/build/esm/index.js
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
const LinguiContext = /*#__PURE__*/React.createContext(null);
|
|
4
|
-
function useLingui() {
|
|
5
|
-
const context = React.useContext(LinguiContext);
|
|
6
|
-
if (process.env.NODE_ENV !== "production") {
|
|
7
|
-
if (context == null) {
|
|
8
|
-
throw new Error("useLingui hook was used without I18nProvider.");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return context;
|
|
12
|
-
}
|
|
13
|
-
const I18nProvider = _ref => {
|
|
14
|
-
let {
|
|
15
|
-
i18n,
|
|
16
|
-
defaultComponent,
|
|
17
|
-
children
|
|
18
|
-
} = _ref;
|
|
19
|
-
const latestKnownLocale = React.useRef(i18n.locale);
|
|
20
|
-
/**
|
|
21
|
-
* We can't pass `i18n` object directly through context, because even when locale
|
|
22
|
-
* or messages are changed, i18n object is still the same. Context provider compares
|
|
23
|
-
* reference identity and suggested workaround is to create a wrapper object every time
|
|
24
|
-
* we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.
|
|
25
|
-
*
|
|
26
|
-
* Due to this effect we also pass `defaultComponent` in the same context, instead
|
|
27
|
-
* of creating a separate Provider/Consumer pair.
|
|
28
|
-
*
|
|
29
|
-
* We can't use useMemo hook either, because we want to recalculate value manually.
|
|
30
|
-
*/
|
|
31
|
-
const makeContext = React.useCallback(() => ({
|
|
32
|
-
i18n,
|
|
33
|
-
defaultComponent
|
|
34
|
-
}), [i18n, defaultComponent]);
|
|
35
|
-
const [context, setContext] = React.useState(makeContext());
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Subscribe for locale/message changes
|
|
39
|
-
*
|
|
40
|
-
* I18n object from `@lingui/core` is the single source of truth for all i18n related
|
|
41
|
-
* data (active locale, catalogs). When new messages are loaded or locale is changed
|
|
42
|
-
* we need to trigger re-rendering of LinguiContext.Consumers.
|
|
43
|
-
*/
|
|
44
|
-
React.useEffect(() => {
|
|
45
|
-
const updateContext = () => {
|
|
46
|
-
latestKnownLocale.current = i18n.locale;
|
|
47
|
-
setContext(makeContext());
|
|
48
|
-
};
|
|
49
|
-
const unsubscribe = i18n.on("change", updateContext);
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* unlikely, but if the locale changes before the onChange listener
|
|
53
|
-
* was added, we need to trigger a rerender
|
|
54
|
-
* */
|
|
55
|
-
if (latestKnownLocale.current !== i18n.locale) {
|
|
56
|
-
updateContext();
|
|
57
|
-
}
|
|
58
|
-
return unsubscribe;
|
|
59
|
-
}, [makeContext]);
|
|
60
|
-
if (!latestKnownLocale.current) {
|
|
61
|
-
process.env.NODE_ENV === "development" && console.log("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.");
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
return /*#__PURE__*/React.createElement(LinguiContext.Provider, {
|
|
65
|
-
value: context
|
|
66
|
-
}, children);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// match <tag>paired</tag> and <tag/> unpaired tags
|
|
70
|
-
const tagRe = /<([a-zA-Z0-9]+)>(.*?)<\/\1>|<([a-zA-Z0-9]+)\/>/;
|
|
71
|
-
const nlRe = /(?:\r\n|\r|\n)/g;
|
|
72
|
-
|
|
73
|
-
// For HTML, certain tags should omit their close tag. We keep a whitelist for
|
|
74
|
-
// those special-case tags.
|
|
75
|
-
const voidElementTags = {
|
|
76
|
-
area: true,
|
|
77
|
-
base: true,
|
|
78
|
-
br: true,
|
|
79
|
-
col: true,
|
|
80
|
-
embed: true,
|
|
81
|
-
hr: true,
|
|
82
|
-
img: true,
|
|
83
|
-
input: true,
|
|
84
|
-
keygen: true,
|
|
85
|
-
link: true,
|
|
86
|
-
meta: true,
|
|
87
|
-
param: true,
|
|
88
|
-
source: true,
|
|
89
|
-
track: true,
|
|
90
|
-
wbr: true,
|
|
91
|
-
menuitem: true
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* `formatElements` - parse string and return tree of react elements
|
|
96
|
-
*
|
|
97
|
-
* `value` is string to be formatted with <tag>Paired<tag/> or <tag/> (unpaired)
|
|
98
|
-
* placeholders. `elements` is a array of react elements which indexes
|
|
99
|
-
* correspond to element indexes in formatted string
|
|
100
|
-
*/
|
|
101
|
-
function formatElements(value) {
|
|
102
|
-
let elements = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
103
|
-
const uniqueId = makeCounter(0, "$lingui$");
|
|
104
|
-
const parts = value.replace(nlRe, "").split(tagRe);
|
|
105
|
-
|
|
106
|
-
// no inline elements, return
|
|
107
|
-
if (parts.length === 1) return value;
|
|
108
|
-
const tree = [];
|
|
109
|
-
const before = parts.shift();
|
|
110
|
-
if (before) tree.push(before);
|
|
111
|
-
for (const [index, children, after] of getElements(parts)) {
|
|
112
|
-
let element = elements[index];
|
|
113
|
-
if (!element || voidElementTags[element.type] && children) {
|
|
114
|
-
if (!element) {
|
|
115
|
-
console.error(`Can't use element at index '${index}' as it is not declared in the original translation`);
|
|
116
|
-
} else {
|
|
117
|
-
console.error(`${element.type} is a void element tag therefore it must have no children`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// ignore problematic element but push its children and elements after it
|
|
121
|
-
element = /*#__PURE__*/React.createElement(React.Fragment);
|
|
122
|
-
}
|
|
123
|
-
tree.push( /*#__PURE__*/React.cloneElement(element, {
|
|
124
|
-
key: uniqueId()
|
|
125
|
-
},
|
|
126
|
-
// format children for pair tags
|
|
127
|
-
// unpaired tags might have children if it's a component passed as a variable
|
|
128
|
-
children ? formatElements(children, elements) : element.props.children));
|
|
129
|
-
if (after) tree.push(after);
|
|
130
|
-
}
|
|
131
|
-
return tree;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/*
|
|
135
|
-
* `getElements` - return array of element indexes and element childrens
|
|
136
|
-
*
|
|
137
|
-
* `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]
|
|
138
|
-
* where:
|
|
139
|
-
* - `pairedIndex` is index of paired element (undef for unpaired)
|
|
140
|
-
* - `children` are children of paired element (undef for unpaired)
|
|
141
|
-
* - `unpairedIndex` is index of unpaired element (undef for paired)
|
|
142
|
-
* - `textAfter` is string after all elements (empty string, if there's nothing)
|
|
143
|
-
*
|
|
144
|
-
* `parts` length is always multiply of 4
|
|
145
|
-
*
|
|
146
|
-
* Returns: Array<[elementIndex, children, after]>
|
|
147
|
-
*/
|
|
148
|
-
function getElements(parts) {
|
|
149
|
-
if (!parts.length) return [];
|
|
150
|
-
const [paired, children, unpaired, after] = parts.slice(0, 4);
|
|
151
|
-
return [[paired || unpaired, children || "", after]].concat(getElements(parts.slice(4, parts.length)));
|
|
152
|
-
}
|
|
153
|
-
const makeCounter = function () {
|
|
154
|
-
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
155
|
-
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
156
|
-
return () => `${prefix}_${count++}`;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
function Trans(props) {
|
|
160
|
-
const {
|
|
161
|
-
i18n,
|
|
162
|
-
defaultComponent
|
|
163
|
-
} = useLingui();
|
|
164
|
-
const {
|
|
165
|
-
render,
|
|
166
|
-
component,
|
|
167
|
-
id,
|
|
168
|
-
message,
|
|
169
|
-
formats
|
|
170
|
-
} = props;
|
|
171
|
-
const values = {
|
|
172
|
-
...(props.values || {})
|
|
173
|
-
};
|
|
174
|
-
const components = {
|
|
175
|
-
...(props.components || {})
|
|
176
|
-
};
|
|
177
|
-
if (values) {
|
|
178
|
-
/*
|
|
179
|
-
Related discussion: https://github.com/lingui/js-lingui/issues/183
|
|
180
|
-
Values *might* contain React elements with static content.
|
|
181
|
-
They're replaced with <INDEX /> placeholders and added to `components`.
|
|
182
|
-
Example:
|
|
183
|
-
Translation: Hello {name}
|
|
184
|
-
Values: { name: <strong>Jane</strong> }
|
|
185
|
-
It'll become "Hello <0 />" with components=[<strong>Jane</strong>]
|
|
186
|
-
*/
|
|
187
|
-
|
|
188
|
-
Object.keys(values).forEach(key => {
|
|
189
|
-
const value = values[key];
|
|
190
|
-
if (! /*#__PURE__*/React.isValidElement(value)) return;
|
|
191
|
-
const index = Object.keys(components).length;
|
|
192
|
-
components[index] = value;
|
|
193
|
-
values[key] = `<${index}/>`;
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
const _translation = i18n && typeof i18n._ === "function" ? i18n._(id, values, {
|
|
197
|
-
message,
|
|
198
|
-
formats
|
|
199
|
-
}) : id; // i18n provider isn't loaded at all
|
|
200
|
-
|
|
201
|
-
const translation = _translation ? formatElements(_translation, components) : null;
|
|
202
|
-
if (render === null || component === null) {
|
|
203
|
-
// Although `string` is a valid react element, types only allow `Element`
|
|
204
|
-
// Upstream issue: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544
|
|
205
|
-
return translation;
|
|
206
|
-
}
|
|
207
|
-
const FallbackComponent = defaultComponent || React.Fragment;
|
|
208
|
-
const i18nProps = {
|
|
209
|
-
id,
|
|
210
|
-
message,
|
|
211
|
-
translation,
|
|
212
|
-
isTranslated: id !== translation && message !== translation
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
// Validation of `render` and `component` props
|
|
216
|
-
if (render && component) {
|
|
217
|
-
console.error("You can't use both `component` and `render` prop at the same time. `component` is ignored.");
|
|
218
|
-
} else if (render && typeof render !== "function") {
|
|
219
|
-
console.error(`Invalid value supplied to prop \`render\`. It must be a function, provided ${render}`);
|
|
220
|
-
} else if (component && typeof component !== "function") {
|
|
221
|
-
// Apparently, both function components and class components are functions
|
|
222
|
-
// See https://stackoverflow.com/a/41658173/1535540
|
|
223
|
-
console.error(`Invalid value supplied to prop \`component\`. It must be a React component, provided ${component}`);
|
|
224
|
-
return /*#__PURE__*/React.createElement(FallbackComponent, i18nProps, translation);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Rendering using a render prop
|
|
228
|
-
if (typeof render === "function") {
|
|
229
|
-
// Component: render={(props) => <a title={props.translation}>x</a>}
|
|
230
|
-
return render(i18nProps);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// `component` prop has a higher precedence over `defaultComponent`
|
|
234
|
-
const Component = component || FallbackComponent;
|
|
235
|
-
const DefaultComponent = defaultComponent;
|
|
236
|
-
return DefaultComponent && !component ? /*#__PURE__*/React.createElement(DefaultComponent, i18nProps, translation) : /*#__PURE__*/React.createElement(Component, null, translation);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export { I18nProvider, LinguiContext, Trans, useLingui };
|
|
240
|
-
//# sourceMappingURL=index.js.map
|
package/build/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/I18nProvider.tsx","../../src/format.ts","../../src/Trans.tsx"],"sourcesContent":["import React, { ComponentType, FunctionComponent } from \"react\"\nimport { I18n } from \"@lingui/core\"\nimport { TransRenderProps } from \"./Trans\"\n\nexport type I18nContext = {\n i18n: I18n\n defaultComponent?: ComponentType<TransRenderProps>\n}\n\nexport type I18nProviderProps = I18nContext & {\n children?: React.ReactNode\n}\n\nexport const LinguiContext = React.createContext<I18nContext>(null)\n\nexport function useLingui(): I18nContext {\n const context = React.useContext<I18nContext>(LinguiContext)\n\n if (process.env.NODE_ENV !== \"production\") {\n if (context == null) {\n throw new Error(\"useLingui hook was used without I18nProvider.\")\n }\n }\n\n return context\n}\n\nexport const I18nProvider: FunctionComponent<I18nProviderProps> = ({\n i18n,\n defaultComponent,\n children,\n}) => {\n const latestKnownLocale = React.useRef<string | undefined>(i18n.locale)\n /**\n * We can't pass `i18n` object directly through context, because even when locale\n * or messages are changed, i18n object is still the same. Context provider compares\n * reference identity and suggested workaround is to create a wrapper object every time\n * we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.\n *\n * Due to this effect we also pass `defaultComponent` in the same context, instead\n * of creating a separate Provider/Consumer pair.\n *\n * We can't use useMemo hook either, because we want to recalculate value manually.\n */\n const makeContext = React.useCallback(\n () => ({\n i18n,\n defaultComponent,\n }),\n [i18n, defaultComponent]\n )\n\n const [context, setContext] = React.useState<I18nContext>(makeContext())\n\n /**\n * Subscribe for locale/message changes\n *\n * I18n object from `@lingui/core` is the single source of truth for all i18n related\n * data (active locale, catalogs). When new messages are loaded or locale is changed\n * we need to trigger re-rendering of LinguiContext.Consumers.\n */\n React.useEffect(() => {\n const updateContext = () => {\n latestKnownLocale.current = i18n.locale\n setContext(makeContext())\n }\n const unsubscribe = i18n.on(\"change\", updateContext)\n\n /**\n * unlikely, but if the locale changes before the onChange listener\n * was added, we need to trigger a rerender\n * */\n if (latestKnownLocale.current !== i18n.locale) {\n updateContext()\n }\n return unsubscribe\n }, [makeContext])\n\n if (!latestKnownLocale.current) {\n process.env.NODE_ENV === \"development\" &&\n console.log(\n \"I18nProvider rendered `null`. A call to `i18n.activate` needs to happen in order for translations to be activated and for the I18nProvider to render.\" +\n \"This is not an error but an informational message logged only in development.\"\n )\n return null\n }\n\n return (\n <LinguiContext.Provider value={context}>{children}</LinguiContext.Provider>\n )\n}\n","import React from \"react\"\n\n// match <tag>paired</tag> and <tag/> unpaired tags\nconst tagRe = /<([a-zA-Z0-9]+)>(.*?)<\\/\\1>|<([a-zA-Z0-9]+)\\/>/\nconst nlRe = /(?:\\r\\n|\\r|\\n)/g\n\n// For HTML, certain tags should omit their close tag. We keep a whitelist for\n// those special-case tags.\nconst voidElementTags = {\n area: true,\n base: true,\n br: true,\n col: true,\n embed: true,\n hr: true,\n img: true,\n input: true,\n keygen: true,\n link: true,\n meta: true,\n param: true,\n source: true,\n track: true,\n wbr: true,\n menuitem: true,\n}\n\n/**\n * `formatElements` - parse string and return tree of react elements\n *\n * `value` is string to be formatted with <tag>Paired<tag/> or <tag/> (unpaired)\n * placeholders. `elements` is a array of react elements which indexes\n * correspond to element indexes in formatted string\n */\nfunction formatElements(\n value: string,\n elements: { [key: string]: React.ReactElement<any> } = {}\n): string | Array<any> {\n const uniqueId = makeCounter(0, \"$lingui$\")\n const parts = value.replace(nlRe, \"\").split(tagRe)\n\n // no inline elements, return\n if (parts.length === 1) return value\n\n const tree = []\n\n const before = parts.shift()\n if (before) tree.push(before)\n\n for (const [index, children, after] of getElements(parts)) {\n let element = elements[index]\n\n if (!element || (voidElementTags[element.type as string] && children)) {\n if (!element) {\n console.error(\n `Can't use element at index '${index}' as it is not declared in the original translation`\n )\n } else {\n console.error(\n `${element.type} is a void element tag therefore it must have no children`\n )\n }\n\n // ignore problematic element but push its children and elements after it\n element = React.createElement(React.Fragment)\n }\n\n tree.push(\n React.cloneElement(\n element,\n { key: uniqueId() },\n\n // format children for pair tags\n // unpaired tags might have children if it's a component passed as a variable\n children ? formatElements(children, elements) : element.props.children\n )\n )\n\n if (after) tree.push(after)\n }\n\n return tree\n}\n\n/*\n * `getElements` - return array of element indexes and element childrens\n *\n * `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]\n * where:\n * - `pairedIndex` is index of paired element (undef for unpaired)\n * - `children` are children of paired element (undef for unpaired)\n * - `unpairedIndex` is index of unpaired element (undef for paired)\n * - `textAfter` is string after all elements (empty string, if there's nothing)\n *\n * `parts` length is always multiply of 4\n *\n * Returns: Array<[elementIndex, children, after]>\n */\nfunction getElements(parts) {\n if (!parts.length) return []\n\n const [paired, children, unpaired, after] = parts.slice(0, 4)\n\n return [[paired || unpaired, children || \"\", after]].concat(\n getElements(parts.slice(4, parts.length))\n )\n}\n\nconst makeCounter =\n (count = 0, prefix = \"\") =>\n () =>\n `${prefix}_${count++}`\n\nexport { formatElements }\n","import React from \"react\"\n\nimport { useLingui } from \"./I18nProvider\"\nimport { formatElements } from \"./format\"\n\nexport type TransRenderProps = {\n id?: string\n translation?: React.ReactNode\n children?: React.ReactNode\n message?: string | null\n isTranslated?: boolean\n}\n\nexport type TransProps = {\n id: string\n message?: string\n values?: Record<string, unknown>\n components?: { [key: string]: React.ElementType | any }\n formats?: Record<string, unknown>\n children?: React.ReactNode\n component?: React.ComponentType<TransRenderProps>\n render?: (props: TransRenderProps) => React.ReactElement<any, any> | null\n}\n\nexport function Trans(props: TransProps): React.ReactElement<any, any> | null {\n const { i18n, defaultComponent } = useLingui()\n const { render, component, id, message, formats } = props\n\n const values = { ...(props.values || {}) }\n const components = { ...(props.components || {}) }\n\n if (values) {\n /*\n Related discussion: https://github.com/lingui/js-lingui/issues/183\n\n Values *might* contain React elements with static content.\n They're replaced with <INDEX /> placeholders and added to `components`.\n\n Example:\n Translation: Hello {name}\n Values: { name: <strong>Jane</strong> }\n\n It'll become \"Hello <0 />\" with components=[<strong>Jane</strong>]\n */\n\n Object.keys(values).forEach((key) => {\n const value = values[key]\n if (!React.isValidElement(value)) return\n\n const index = Object.keys(components).length\n\n components[index] = value\n values[key] = `<${index}/>`\n })\n }\n\n const _translation: string =\n i18n && typeof i18n._ === \"function\"\n ? i18n._(id, values, { message, formats })\n : id // i18n provider isn't loaded at all\n\n const translation = _translation\n ? formatElements(_translation, components)\n : null\n\n if (render === null || component === null) {\n // Although `string` is a valid react element, types only allow `Element`\n // Upstream issue: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544\n return translation as unknown as React.ReactElement<any, any>\n }\n\n const FallbackComponent = (defaultComponent ||\n React.Fragment) as React.ComponentType<any>\n\n const i18nProps = {\n id,\n message,\n translation,\n isTranslated: id !== translation && message !== translation,\n }\n\n // Validation of `render` and `component` props\n if (render && component) {\n console.error(\n \"You can't use both `component` and `render` prop at the same time. `component` is ignored.\"\n )\n } else if (render && typeof render !== \"function\") {\n console.error(\n `Invalid value supplied to prop \\`render\\`. It must be a function, provided ${render}`\n )\n } else if (component && typeof component !== \"function\") {\n // Apparently, both function components and class components are functions\n // See https://stackoverflow.com/a/41658173/1535540\n console.error(\n `Invalid value supplied to prop \\`component\\`. It must be a React component, provided ${component}`\n )\n return <FallbackComponent {...i18nProps}>{translation}</FallbackComponent>\n }\n\n // Rendering using a render prop\n if (typeof render === \"function\") {\n // Component: render={(props) => <a title={props.translation}>x</a>}\n return render(i18nProps)\n }\n\n // `component` prop has a higher precedence over `defaultComponent`\n const Component = (component || FallbackComponent) as React.ComponentType<any>\n const DefaultComponent = defaultComponent\n\n return DefaultComponent && !component ? (\n <DefaultComponent {...i18nProps}>{translation}</DefaultComponent>\n ) : (\n <Component>{translation}</Component>\n )\n}\n"],"names":["LinguiContext","React","createContext","useLingui","context","useContext","process","env","NODE_ENV","Error","I18nProvider","i18n","defaultComponent","children","latestKnownLocale","useRef","locale","makeContext","useCallback","setContext","useState","useEffect","updateContext","current","unsubscribe","on","console","log","tagRe","nlRe","voidElementTags","area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr","menuitem","formatElements","value","elements","uniqueId","makeCounter","parts","replace","split","length","tree","before","shift","push","index","after","getElements","element","type","error","createElement","Fragment","cloneElement","key","props","paired","unpaired","slice","concat","count","prefix","Trans","render","component","id","message","formats","values","components","Object","keys","forEach","isValidElement","_translation","_","translation","FallbackComponent","i18nProps","isTranslated","Component","DefaultComponent"],"mappings":";;AAaO,MAAMA,aAAa,gBAAGC,KAAK,CAACC,aAAa,CAAc,IAAI,EAAC;AAE5D,SAASC,SAAS,GAAgB;AACvC,EAAA,MAAMC,OAAO,GAAGH,KAAK,CAACI,UAAU,CAAcL,aAAa,CAAC,CAAA;AAE5D,EAAA,IAAIM,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC,IAAIJ,OAAO,IAAI,IAAI,EAAE;AACnB,MAAA,MAAM,IAAIK,KAAK,CAAC,+CAA+C,CAAC,CAAA;AAClE,KAAA;AACF,GAAA;AAEA,EAAA,OAAOL,OAAO,CAAA;AAChB,CAAA;AAEO,M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AAKU,WAAAA;GACjD,CAAA;;AAED;EACA,IAAIb,MAAM,IAAIC,SAAS,EAAE;AACvBrD,IAAAA,OAAO,CAACuC,KAAK,CACX,4FAA4F,CAC7F,CAAA;GACF,MAAM,IAAIa,MAAM,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;AACjDpD,IAAAA,OAAO,CAACuC,KAAK,CACV,CAA6Ea,2EAAAA,EAAAA,MAAO,EAAC,CACvF,CAAA;GACF,MAAM,IAAIC,SAAS,IAAI,OAAOA,SAAS,KAAK,UAAU,EAAE;AACvD;AACA;AACArD,IAAAA,OAAO,CAACuC,KAAK,CACV,CAAuFc,qFAAAA,EAAAA,SAAU,EAAC,CACpG,CAAA;AACD,IAAA,oBAAO,oBAAC,iBAAiB,EAAKc,SAAS,EAAGF,WAAW,CAAqB,CAAA;AAC5E,GAAA;;AAEA;AACA,EAAA,IAAI,OAAOb,MAAM,KAAK,UAAU,EAAE;AAChC;IACA,OAAOA,MAAM,CAACe,SAAS,CAAC,CAAA;AAC1B,GAAA;;AAEA;AACA,EAAA,MAAME,SAAS,GAAIhB,SAAS,IAAIa,iBAA8C,CAAA;EAC9E,MAAMI,gBAAgB,GAAGpF,gBAAgB,CAAA;AAEzC,EAAA,OAAOoF,gBAAgB,IAAI,CAACjB,SAAS,gBACnC,oBAAC,gBAAgB,EAAKc,SAAS,EAAGF,WAAW,CAAoB,gBAEjE,oBAAC,SAAS,EAAA,IAAA,EAAEA,WAAW,CACxB,CAAA;AACH;;;;"}
|
package/build/esm/package.json
DELETED
package/build/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./cjs/index.js")
|
|
File without changes
|