@webiny/i18n-react 5.43.3 → 6.0.0-alpha.1
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/index.d.ts +1 -1
- package/index.js +22 -34
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,59 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
var _trim = _interopRequireDefault(require("lodash/trim"));
|
|
11
|
-
var processTextPart = function processTextPart(part, values, modifiers) {
|
|
1
|
+
import React from "react";
|
|
2
|
+
import lodashTrim from "lodash/trim";
|
|
3
|
+
const processTextPart = (part, values, modifiers) => {
|
|
12
4
|
if (part.startsWith("{") === false) {
|
|
13
5
|
return part;
|
|
14
6
|
}
|
|
15
|
-
part = (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
variable = _parts[0],
|
|
19
|
-
modifier = _parts[1];
|
|
7
|
+
part = lodashTrim(part, "{}");
|
|
8
|
+
const parts = part.split("|");
|
|
9
|
+
const [variable, modifier] = parts;
|
|
20
10
|
if (!values[variable]) {
|
|
21
11
|
return variable;
|
|
22
12
|
}
|
|
23
|
-
|
|
13
|
+
let value = values[variable];
|
|
24
14
|
if (modifier) {
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const parameters = modifier.split(":");
|
|
16
|
+
const name = parameters.shift();
|
|
27
17
|
if (!name) {
|
|
28
18
|
return value;
|
|
29
19
|
}
|
|
30
20
|
if (modifiers[name]) {
|
|
31
|
-
|
|
32
|
-
value =
|
|
21
|
+
const modifier = modifiers[name];
|
|
22
|
+
value = modifier.execute(value, parameters);
|
|
33
23
|
}
|
|
34
24
|
}
|
|
35
25
|
return value;
|
|
36
26
|
};
|
|
37
|
-
|
|
27
|
+
const processor = {
|
|
38
28
|
name: "react",
|
|
39
|
-
canExecute
|
|
40
|
-
for (
|
|
41
|
-
|
|
42
|
-
if (/*#__PURE__*/
|
|
29
|
+
canExecute(data) {
|
|
30
|
+
for (const key in data.values) {
|
|
31
|
+
const value = data.values[key];
|
|
32
|
+
if (/*#__PURE__*/React.isValidElement(value)) {
|
|
43
33
|
return true;
|
|
44
34
|
}
|
|
45
35
|
}
|
|
46
36
|
return false;
|
|
47
37
|
},
|
|
48
|
-
execute
|
|
49
|
-
|
|
50
|
-
return /*#__PURE__*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, processTextPart(part, data.values, data.i18n.modifiers));
|
|
54
|
-
}));
|
|
38
|
+
execute(data) {
|
|
39
|
+
const parts = data.translation.split(/({.*?})/);
|
|
40
|
+
return /*#__PURE__*/React.createElement("i18n-text", null, parts.map((part, index) => /*#__PURE__*/React.createElement("i18n-text-part", {
|
|
41
|
+
key: String(index)
|
|
42
|
+
}, processTextPart(part, data.values, data.i18n.modifiers))));
|
|
55
43
|
}
|
|
56
44
|
};
|
|
57
|
-
|
|
45
|
+
export default processor;
|
|
58
46
|
|
|
59
47
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","lodashTrim","processTextPart","part","values","modifiers","startsWith","parts","split","variable","modifier","value","parameters","name","shift","execute","processor","canExecute","data","key","isValidElement","translation","createElement","map","index","String","i18n"],"sources":["index.tsx"],"sourcesContent":["import React from \"react\";\nimport lodashTrim from \"lodash/trim\";\nimport type { I18NDataValues, Modifier, Processor } from \"@webiny/i18n/types\";\n\ndeclare global {\n // eslint-disable-next-line\n namespace JSX {\n interface IntrinsicElements {\n \"i18n-text\": {\n children?: React.ReactNode;\n };\n\n \"i18n-text-part\": {\n key?: string;\n children?: React.ReactNode;\n };\n }\n }\n}\n\nconst processTextPart = (\n part: string,\n values: I18NDataValues,\n modifiers: Record<string, Modifier>\n): string => {\n if (part.startsWith(\"{\") === false) {\n return part;\n }\n\n part = lodashTrim(part, \"{}\");\n\n const parts: string[] = part.split(\"|\");\n\n const [variable, modifier] = parts;\n\n if (!values[variable]) {\n return variable;\n }\n\n let value = values[variable];\n if (modifier) {\n const parameters = modifier.split(\":\");\n const name = parameters.shift();\n if (!name) {\n return value;\n }\n if (modifiers[name]) {\n const modifier = modifiers[name];\n value = modifier.execute(value, parameters);\n }\n }\n\n return value;\n};\n\nconst processor: Processor = {\n name: \"react\",\n canExecute(data) {\n for (const key in data.values) {\n const value = data.values[key];\n if (React.isValidElement(value)) {\n return true;\n }\n }\n\n return false;\n },\n execute(data) {\n const parts = data.translation.split(/({.*?})/);\n return (\n <i18n-text>\n {parts.map((part, index) => (\n <i18n-text-part key={String(index)}>\n {processTextPart(part, data.values, data.i18n.modifiers)}\n </i18n-text-part>\n ))}\n </i18n-text>\n );\n }\n};\nexport default processor;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,UAAU,MAAM,aAAa;AAmBpC,MAAMC,eAAe,GAAGA,CACpBC,IAAY,EACZC,MAAsB,EACtBC,SAAmC,KAC1B;EACT,IAAIF,IAAI,CAACG,UAAU,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE;IAChC,OAAOH,IAAI;EACf;EAEAA,IAAI,GAAGF,UAAU,CAACE,IAAI,EAAE,IAAI,CAAC;EAE7B,MAAMI,KAAe,GAAGJ,IAAI,CAACK,KAAK,CAAC,GAAG,CAAC;EAEvC,MAAM,CAACC,QAAQ,EAAEC,QAAQ,CAAC,GAAGH,KAAK;EAElC,IAAI,CAACH,MAAM,CAACK,QAAQ,CAAC,EAAE;IACnB,OAAOA,QAAQ;EACnB;EAEA,IAAIE,KAAK,GAAGP,MAAM,CAACK,QAAQ,CAAC;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|
2
2
|
"name": "@webiny/i18n-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-alpha.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
],
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@webiny/i18n": "
|
|
17
|
+
"@webiny/i18n": "6.0.0-alpha.1",
|
|
18
18
|
"lodash": "4.17.21"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@webiny/project-utils": "
|
|
21
|
+
"@webiny/project-utils": "6.0.0-alpha.1",
|
|
22
22
|
"rimraf": "6.0.1",
|
|
23
23
|
"typescript": "5.3.3"
|
|
24
24
|
},
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"build": "node ../cli/bin.js run build",
|
|
34
34
|
"watch": "node ../cli/bin.js run watch"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "9bd236cf5e689f209a11bec089207dcc2d41a53c"
|
|
37
37
|
}
|