@webiny/i18n-react 0.0.0-unstable.78f581c1d2 β 0.0.0-unstable.7be00a75a9
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/README.md +6 -14
- package/index.d.ts +3 -2
- package/index.js +36 -70
- package/index.js.map +1 -1
- package/package.json +17 -23
package/README.md
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
# @webiny/i18n-react
|
|
2
|
-
[](https://www.npmjs.com/package/@webiny/i18n-react)
|
|
3
|
-
[](https://www.npmjs.com/package/@webiny/i18n-react)
|
|
4
|
-
[](https://github.com/prettier/prettier)
|
|
5
|
-
[](http://makeapullrequest.com)
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> Itβs **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
npm install --save @webiny/i18n-react
|
|
13
|
-
```
|
|
7
|
+
π **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
yarn add @webiny/i18n-react
|
|
18
|
-
```
|
|
9
|
+
---
|
|
19
10
|
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Processor } from "@webiny/i18n/types";
|
|
3
|
-
declare
|
|
2
|
+
import type { Processor } from "@webiny/i18n/types.js";
|
|
3
|
+
declare module "react" {
|
|
4
4
|
namespace JSX {
|
|
5
5
|
interface IntrinsicElements {
|
|
6
6
|
"i18n-text": {
|
|
7
|
+
default?: string;
|
|
7
8
|
children?: React.ReactNode;
|
|
8
9
|
};
|
|
9
10
|
"i18n-text-part": {
|
package/index.js
CHANGED
|
@@ -1,74 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return part;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
part = (0, _trim.default)(part, "{}");
|
|
22
|
-
var parts = part.split("|");
|
|
23
|
-
|
|
24
|
-
var _parts = (0, _slicedToArray2.default)(parts, 2),
|
|
25
|
-
variable = _parts[0],
|
|
26
|
-
modifier = _parts[1];
|
|
27
|
-
|
|
28
|
-
if (!values[variable]) {
|
|
29
|
-
return variable;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var value = values[variable];
|
|
33
|
-
|
|
34
|
-
if (modifier) {
|
|
35
|
-
var parameters = modifier.split(":");
|
|
36
|
-
var name = parameters.shift();
|
|
37
|
-
|
|
38
|
-
if (!name) {
|
|
39
|
-
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
|
+
}
|
|
40
18
|
}
|
|
41
|
-
|
|
42
|
-
if (modifiers[name]) {
|
|
43
|
-
var _modifier = modifiers[name];
|
|
44
|
-
value = _modifier.execute(value, parameters);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return value;
|
|
19
|
+
return value;
|
|
49
20
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
21
|
+
const processor = {
|
|
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))));
|
|
60
35
|
}
|
|
61
|
-
|
|
62
|
-
return false;
|
|
63
|
-
},
|
|
64
|
-
execute: function execute(data) {
|
|
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)
|
|
69
|
-
}, processTextPart(part, data.values, data.i18n.modifiers));
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
36
|
};
|
|
73
|
-
|
|
74
|
-
|
|
37
|
+
const src = processor;
|
|
38
|
+
export default src;
|
|
39
|
+
|
|
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,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/i18n-react",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.0-unstable.7be00a75a9",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
},
|
|
5
9
|
"repository": {
|
|
6
10
|
"type": "git",
|
|
7
11
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
@@ -14,32 +18,22 @@
|
|
|
14
18
|
],
|
|
15
19
|
"license": "MIT",
|
|
16
20
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"
|
|
19
|
-
"lodash": "4.17.21"
|
|
21
|
+
"@webiny/i18n": "0.0.0-unstable.7be00a75a9",
|
|
22
|
+
"lodash": "4.18.1"
|
|
20
23
|
},
|
|
21
24
|
"devDependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"@babel/preset-react": "^7.16.0",
|
|
26
|
-
"@babel/preset-typescript": "^7.18.6",
|
|
27
|
-
"@webiny/cli": "^0.0.0-unstable.78f581c1d2",
|
|
28
|
-
"@webiny/project-utils": "^0.0.0-unstable.78f581c1d2",
|
|
29
|
-
"babel-plugin-lodash": "^3.3.4",
|
|
30
|
-
"rimraf": "^3.0.2",
|
|
31
|
-
"typescript": "4.7.4"
|
|
25
|
+
"@webiny/build-tools": "0.0.0-unstable.7be00a75a9",
|
|
26
|
+
"rimraf": "6.1.3",
|
|
27
|
+
"typescript": "6.0.3"
|
|
32
28
|
},
|
|
33
29
|
"peerDependencies": {
|
|
34
|
-
"react": "
|
|
30
|
+
"react": "18.3.1"
|
|
35
31
|
},
|
|
36
32
|
"publishConfig": {
|
|
37
|
-
"access": "public"
|
|
38
|
-
"directory": "dist"
|
|
39
|
-
},
|
|
40
|
-
"scripts": {
|
|
41
|
-
"build": "yarn webiny run build",
|
|
42
|
-
"watch": "yarn webiny run watch"
|
|
33
|
+
"access": "public"
|
|
43
34
|
},
|
|
44
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
|
|
36
|
+
"webiny": {
|
|
37
|
+
"publishFrom": "dist"
|
|
38
|
+
}
|
|
45
39
|
}
|