@webiny/i18n-react 0.0.0-mt-2 → 0.0.0-unstable.06b2ede40f
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 +4 -4
- package/index.js +29 -42
- package/index.js.map +1 -0
- package/package.json +9 -17
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Processor } from "@webiny/i18n/types";
|
|
2
|
+
import type { Processor } from "@webiny/i18n/types";
|
|
3
3
|
declare global {
|
|
4
4
|
namespace JSX {
|
|
5
5
|
interface IntrinsicElements {
|
|
@@ -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,60 +1,47 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import _has from "lodash/has";
|
|
3
|
-
import _trim from "lodash/trim";
|
|
4
|
-
import _startsWith from "lodash/startsWith";
|
|
5
1
|
import React from "react";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (
|
|
2
|
+
import lodashTrim from "lodash/trim";
|
|
3
|
+
const processTextPart = (part, values, modifiers) => {
|
|
4
|
+
if (part.startsWith("{") === false) {
|
|
9
5
|
return part;
|
|
10
6
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _parts = _slicedToArray(parts, 2),
|
|
16
|
-
variable = _parts[0],
|
|
17
|
-
modifier = _parts[1];
|
|
18
|
-
|
|
19
|
-
if (!_has(values, variable)) {
|
|
7
|
+
part = lodashTrim(part, "{}");
|
|
8
|
+
const parts = part.split("|");
|
|
9
|
+
const [variable, modifier] = parts;
|
|
10
|
+
if (!values[variable]) {
|
|
20
11
|
return variable;
|
|
21
12
|
}
|
|
22
|
-
|
|
23
|
-
var value = values[variable];
|
|
24
|
-
|
|
13
|
+
let value = values[variable];
|
|
25
14
|
if (modifier) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
const parameters = modifier.split(":");
|
|
16
|
+
const name = parameters.shift();
|
|
17
|
+
if (!name) {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
29
20
|
if (modifiers[name]) {
|
|
30
|
-
|
|
31
|
-
value =
|
|
21
|
+
const modifier = modifiers[name];
|
|
22
|
+
value = modifier.execute(value, parameters);
|
|
32
23
|
}
|
|
33
24
|
}
|
|
34
|
-
|
|
35
25
|
return value;
|
|
36
26
|
};
|
|
37
|
-
|
|
38
|
-
export default {
|
|
27
|
+
const processor = {
|
|
39
28
|
name: "react",
|
|
40
|
-
canExecute
|
|
41
|
-
for (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if ( /*#__PURE__*/React.isValidElement(value)) {
|
|
29
|
+
canExecute(data) {
|
|
30
|
+
for (const key in data.values) {
|
|
31
|
+
const value = data.values[key];
|
|
32
|
+
if (/*#__PURE__*/React.isValidElement(value)) {
|
|
45
33
|
return true;
|
|
46
34
|
}
|
|
47
35
|
}
|
|
48
|
-
|
|
49
36
|
return false;
|
|
50
37
|
},
|
|
51
|
-
execute
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
key: index
|
|
57
|
-
}, processTextPart(part, data.values, data.i18n.modifiers));
|
|
58
|
-
}));
|
|
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))));
|
|
59
43
|
}
|
|
60
|
-
};
|
|
44
|
+
};
|
|
45
|
+
export default processor;
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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":"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ACf;IACJ;IAEA,OAAO,KAAK;EAChB,CAAC;EACDI,OAAOA,CAACG,IAAI,EAAE;IACV,MAAMX,KAAK,GAAGW,IAAI,CAACG,WAAW,CAACb,KAAK,CAAC,SAAS,CAAC;IAC/C,oBACIR,KAAA,CAAAsB,aAAA,oBACKf,KAAK,CAACgB,GAAG,CAAC,CAACpB,IAAI,EAAEqB,KAAK,kBACnBxB,KAAA,CAAAsB,aAAA;MAAgBH,GAAG,EAAEM,MAAM,CAACD,KAAK;IAAE,GAC9BtB,eAAe,CAACC,IAAI,EAAEe,IAAI,CAACd,MAAM,EAAEc,IAAI,CAACQ,IAAI,CAACrB,SAAS,CAC3C,CACnB,CACM,CAAC;EAEpB;AACJ,CAAC;AACD,eAAeW,SAAS","ignoreList":[]}
|
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.06b2ede40f",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,32 +14,24 @@
|
|
|
14
14
|
],
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"@webiny/i18n": "0.0.0-mt-2",
|
|
17
|
+
"@webiny/i18n": "0.0.0-unstable.06b2ede40f",
|
|
19
18
|
"lodash": "4.17.21"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"@babel/preset-react": "^7.0.0",
|
|
26
|
-
"@babel/preset-typescript": "^7.8.3",
|
|
27
|
-
"@webiny/cli": "^0.0.0-mt-2",
|
|
28
|
-
"@webiny/project-utils": "^0.0.0-mt-2",
|
|
29
|
-
"babel-plugin-lodash": "^3.3.4",
|
|
30
|
-
"rimraf": "^3.0.2",
|
|
31
|
-
"typescript": "^4.1.3"
|
|
21
|
+
"@webiny/project-utils": "0.0.0-unstable.06b2ede40f",
|
|
22
|
+
"rimraf": "6.0.1",
|
|
23
|
+
"typescript": "5.3.3"
|
|
32
24
|
},
|
|
33
25
|
"peerDependencies": {
|
|
34
|
-
"react": "
|
|
26
|
+
"react": "18.2.0"
|
|
35
27
|
},
|
|
36
28
|
"publishConfig": {
|
|
37
29
|
"access": "public",
|
|
38
30
|
"directory": "dist"
|
|
39
31
|
},
|
|
40
32
|
"scripts": {
|
|
41
|
-
"build": "
|
|
42
|
-
"watch": "
|
|
33
|
+
"build": "node ../cli/bin.js run build",
|
|
34
|
+
"watch": "node ../cli/bin.js run watch"
|
|
43
35
|
},
|
|
44
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "06b2ede40fc2212a70eeafd74afd50b56fb0ce82"
|
|
45
37
|
}
|