@webiny/i18n-react 0.0.0-mt-3 → 0.0.0-unstable.40876133bb
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 +3 -3
- package/index.js +31 -17
- package/index.js.map +1 -0
- package/package.json +13 -13
package/index.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ declare global {
|
|
|
7
7
|
children?: React.ReactNode;
|
|
8
8
|
};
|
|
9
9
|
"i18n-text-part": {
|
|
10
|
-
key?:
|
|
10
|
+
key?: string;
|
|
11
11
|
children?: React.ReactNode;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
declare const
|
|
17
|
-
export default
|
|
16
|
+
declare const processor: Processor;
|
|
17
|
+
export default processor;
|
package/index.js
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
|
|
14
|
+
var _trim = _interopRequireDefault(require("lodash/trim"));
|
|
6
15
|
|
|
7
16
|
var processTextPart = function processTextPart(part, values, modifiers) {
|
|
8
|
-
if (
|
|
17
|
+
if (part.startsWith("{") === false) {
|
|
9
18
|
return part;
|
|
10
19
|
}
|
|
11
20
|
|
|
12
|
-
part = _trim(part, "{}");
|
|
21
|
+
part = (0, _trim.default)(part, "{}");
|
|
13
22
|
var parts = part.split("|");
|
|
14
23
|
|
|
15
|
-
var _parts =
|
|
24
|
+
var _parts = (0, _slicedToArray2.default)(parts, 2),
|
|
16
25
|
variable = _parts[0],
|
|
17
26
|
modifier = _parts[1];
|
|
18
27
|
|
|
19
|
-
if (!
|
|
28
|
+
if (!values[variable]) {
|
|
20
29
|
return variable;
|
|
21
30
|
}
|
|
22
31
|
|
|
@@ -26,6 +35,10 @@ var processTextPart = function processTextPart(part, values, modifiers) {
|
|
|
26
35
|
var parameters = modifier.split(":");
|
|
27
36
|
var name = parameters.shift();
|
|
28
37
|
|
|
38
|
+
if (!name) {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
if (modifiers[name]) {
|
|
30
43
|
var _modifier = modifiers[name];
|
|
31
44
|
value = _modifier.execute(value, parameters);
|
|
@@ -35,13 +48,13 @@ var processTextPart = function processTextPart(part, values, modifiers) {
|
|
|
35
48
|
return value;
|
|
36
49
|
};
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
var processor = {
|
|
39
52
|
name: "react",
|
|
40
53
|
canExecute: function canExecute(data) {
|
|
41
54
|
for (var key in data.values) {
|
|
42
55
|
var value = data.values[key];
|
|
43
56
|
|
|
44
|
-
if ( /*#__PURE__*/
|
|
57
|
+
if ( /*#__PURE__*/_react.default.isValidElement(value)) {
|
|
45
58
|
return true;
|
|
46
59
|
}
|
|
47
60
|
}
|
|
@@ -49,12 +62,13 @@ export default {
|
|
|
49
62
|
return false;
|
|
50
63
|
},
|
|
51
64
|
execute: function execute(data) {
|
|
52
|
-
var parts = data.translation.split(/({.*?})/);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
key: index
|
|
65
|
+
var parts = data.translation.split(/({.*?})/);
|
|
66
|
+
return /*#__PURE__*/_react.default.createElement("i18n-text", null, parts.map(function (part, index) {
|
|
67
|
+
return /*#__PURE__*/_react.default.createElement("i18n-text-part", {
|
|
68
|
+
key: String(index)
|
|
57
69
|
}, processTextPart(part, data.values, data.i18n.modifiers));
|
|
58
70
|
}));
|
|
59
71
|
}
|
|
60
|
-
};
|
|
72
|
+
};
|
|
73
|
+
var _default = processor;
|
|
74
|
+
exports.default = _default;
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["processTextPart","part","values","modifiers","startsWith","lodashTrim","parts","split","variable","modifier","value","parameters","name","shift","execute","processor","canExecute","data","key","React","isValidElement","translation","map","index","String","i18n"],"sources":["index.tsx"],"sourcesContent":["import React from \"react\";\nimport lodashTrim from \"lodash/trim\";\nimport { 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;;AACA;;AAmBA,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAC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G,IAZiB,EAYX;IACV,IAAMX,KAAK,GAAGW,IAAI,CAACI,WAAL,CAAiBd,KAAjB,CAAuB,SAAvB,CAAd;IACA,oBACI,gDACKD,KAAK,CAACgB,GAAN,CAAU,UAACrB,IAAD,EAAOsB,KAAP;MAAA,oBACP;QAAgB,GAAG,EAAEC,MAAM,CAACD,KAAD;MAA3B,GACKvB,eAAe,CAACC,IAAD,EAAOgB,IAAI,CAACf,MAAZ,EAAoBe,IAAI,CAACQ,IAAL,CAAUtB,SAA9B,CADpB,CADO;IAAA,CAAV,CADL,CADJ;EASH;AAvBwB,CAA7B;eAyBeY,S"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/i18n-react",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.40876133bb",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,24 +14,24 @@
|
|
|
14
14
|
],
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@babel/runtime": "7.
|
|
18
|
-
"@webiny/i18n": "0.0.0-
|
|
17
|
+
"@babel/runtime": "7.19.0",
|
|
18
|
+
"@webiny/i18n": "0.0.0-unstable.40876133bb",
|
|
19
19
|
"lodash": "4.17.21"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@babel/cli": "^7.
|
|
23
|
-
"@babel/core": "^7.
|
|
24
|
-
"@babel/preset-env": "^7.
|
|
25
|
-
"@babel/preset-react": "^7.
|
|
26
|
-
"@babel/preset-typescript": "^7.
|
|
27
|
-
"@webiny/cli": "^0.0.0-
|
|
28
|
-
"@webiny/project-utils": "^0.0.0-
|
|
22
|
+
"@babel/cli": "^7.19.3",
|
|
23
|
+
"@babel/core": "^7.19.3",
|
|
24
|
+
"@babel/preset-env": "^7.19.4",
|
|
25
|
+
"@babel/preset-react": "^7.16.0",
|
|
26
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
27
|
+
"@webiny/cli": "^0.0.0-unstable.40876133bb",
|
|
28
|
+
"@webiny/project-utils": "^0.0.0-unstable.40876133bb",
|
|
29
29
|
"babel-plugin-lodash": "^3.3.4",
|
|
30
30
|
"rimraf": "^3.0.2",
|
|
31
|
-
"typescript": "
|
|
31
|
+
"typescript": "4.7.4"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"react": "
|
|
34
|
+
"react": "^17.0.2"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"build": "yarn webiny run build",
|
|
42
42
|
"watch": "yarn webiny run watch"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "f33811072795d25c5787ae39808e75e3312fb247"
|
|
45
45
|
}
|