@webiny/i18n-react 6.3.0 → 6.4.0-beta.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.js +33 -40
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -1,47 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
const processTextPart = (part, values, modifiers)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return value;
|
|
1
|
+
import react from "react";
|
|
2
|
+
import trim from "lodash/trim.js";
|
|
3
|
+
const processTextPart = (part, values, modifiers)=>{
|
|
4
|
+
if (false === part.startsWith("{")) return part;
|
|
5
|
+
part = trim(part, "{}");
|
|
6
|
+
const parts = part.split("|");
|
|
7
|
+
const [variable, modifier] = parts;
|
|
8
|
+
if (!values[variable]) return variable;
|
|
9
|
+
let value = values[variable];
|
|
10
|
+
if (modifier) {
|
|
11
|
+
const parameters = modifier.split(":");
|
|
12
|
+
const name = parameters.shift();
|
|
13
|
+
if (!name) return value;
|
|
14
|
+
if (modifiers[name]) {
|
|
15
|
+
const modifier = modifiers[name];
|
|
16
|
+
value = modifier.execute(value, parameters);
|
|
17
|
+
}
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
const modifier = modifiers[name];
|
|
22
|
-
value = modifier.execute(value, parameters);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return value;
|
|
19
|
+
return value;
|
|
26
20
|
};
|
|
27
21
|
const processor = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
name: "react",
|
|
23
|
+
canExecute (data) {
|
|
24
|
+
for(const key in data.values){
|
|
25
|
+
const value = data.values[key];
|
|
26
|
+
if (/*#__PURE__*/ react.isValidElement(value)) return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
},
|
|
30
|
+
execute (data) {
|
|
31
|
+
const parts = data.translation.split(/({.*?})/);
|
|
32
|
+
return /*#__PURE__*/ react.createElement("i18n-text", null, parts.map((part, index)=>/*#__PURE__*/ react.createElement("i18n-text-part", {
|
|
33
|
+
key: String(index)
|
|
34
|
+
}, processTextPart(part, data.values, data.i18n.modifiers))));
|
|
35
35
|
}
|
|
36
|
-
return false;
|
|
37
|
-
},
|
|
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))));
|
|
43
|
-
}
|
|
44
36
|
};
|
|
45
|
-
|
|
37
|
+
const src = processor;
|
|
38
|
+
export default src;
|
|
46
39
|
|
|
47
40
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.tsx"],"sourcesContent":["import React from \"react\";\nimport lodashTrim from \"lodash/trim.js\";\nimport type { I18NDataValues, Modifier, Processor } from \"@webiny/i18n/types.js\";\n\ndeclare module \"react\" {\n namespace JSX {\n interface IntrinsicElements {\n \"i18n-text\": {\n default?: string;\n children?: React.ReactNode;\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"],"names":["processTextPart","part","values","modifiers","lodashTrim","parts","variable","modifier","value","parameters","name","processor","data","key","React","index","String"],"mappings":";;AAmBA,MAAMA,kBAAkB,CACpBC,MACAC,QACAC;IAEA,IAAIF,AAAyB,UAAzBA,KAAK,UAAU,CAAC,MAChB,OAAOA;IAGXA,OAAOG,KAAWH,MAAM;IAExB,MAAMI,QAAkBJ,KAAK,KAAK,CAAC;IAEnC,MAAM,CAACK,UAAUC,SAAS,GAAGF;IAE7B,IAAI,CAACH,MAAM,CAACI,SAAS,EACjB,OAAOA;IAGX,IAAIE,QAAQN,MAAM,CAACI,SAAS;IAC5B,IAAIC,UAAU;QACV,MAAME,aAAaF,SAAS,KAAK,CAAC;QAClC,MAAMG,OAAOD,WAAW,KAAK;QAC7B,IAAI,CAACC,MACD,OAAOF;QAEX,IAAIL,SAAS,CAACO,KAAK,EAAE;YACjB,MAAMH,WAAWJ,SAAS,CAACO,KAAK;YAChCF,QAAQD,SAAS,OAAO,CAACC,OAAOC;QACpC;IACJ;IAEA,OAAOD;AACX;AAEA,MAAMG,YAAuB;IACzB,MAAM;IACN,YAAWC,IAAI;QACX,IAAK,MAAMC,OAAOD,KAAK,MAAM,CAAE;YAC3B,MAAMJ,QAAQI,KAAK,MAAM,CAACC,IAAI;YAC9B,IAAI,WAAJ,GAAIC,MAAAA,cAAoB,CAACN,QACrB,OAAO;QAEf;QAEA,OAAO;IACX;IACA,SAAQI,IAAI;QACR,MAAMP,QAAQO,KAAK,WAAW,CAAC,KAAK,CAAC;QACrC,OAAO,WAAP,GACI,oBAAC,mBACIP,MAAM,GAAG,CAAC,CAACJ,MAAMc,QAAAA,WAAAA,GACd,oBAAC;gBAAe,KAAKC,OAAOD;eACvBf,gBAAgBC,MAAMW,KAAK,MAAM,EAAEA,KAAK,IAAI,CAAC,SAAS;IAK3E;AACJ;AACA,YAAeD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/i18n-react",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@webiny/i18n": "6.
|
|
21
|
+
"@webiny/i18n": "6.4.0-beta.1",
|
|
22
22
|
"lodash": "4.18.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@webiny/build-tools": "6.
|
|
25
|
+
"@webiny/build-tools": "6.4.0-beta.1",
|
|
26
26
|
"rimraf": "6.1.3",
|
|
27
27
|
"typescript": "6.0.3"
|
|
28
28
|
},
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"access": "public",
|
|
34
34
|
"directory": "dist"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "73237b8243693038c072bae1c0b783387448cbbe"
|
|
37
37
|
}
|