@webiny/i18n-react 0.0.0-mt-2 β 0.0.0-unstable.0156a4c312
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 +6 -5
- package/index.js +36 -56
- package/index.js.map +1 -0
- 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,17 +1,18 @@
|
|
|
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": {
|
|
10
|
-
key?:
|
|
11
|
+
key?: string;
|
|
11
12
|
children?: React.ReactNode;
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
|
-
declare const
|
|
17
|
-
export default
|
|
17
|
+
declare const processor: Processor;
|
|
18
|
+
export default processor;
|
package/index.js
CHANGED
|
@@ -1,60 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!_has(values, variable)) {
|
|
20
|
-
return variable;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var value = values[variable];
|
|
24
|
-
|
|
25
|
-
if (modifier) {
|
|
26
|
-
var parameters = modifier.split(":");
|
|
27
|
-
var name = parameters.shift();
|
|
28
|
-
|
|
29
|
-
if (modifiers[name]) {
|
|
30
|
-
var _modifier = modifiers[name];
|
|
31
|
-
value = _modifier.execute(value, parameters);
|
|
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
|
+
}
|
|
32
18
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return value;
|
|
19
|
+
return value;
|
|
36
20
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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))));
|
|
47
35
|
}
|
|
36
|
+
};
|
|
37
|
+
const src = processor;
|
|
38
|
+
export default src;
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
execute: function execute(data) {
|
|
52
|
-
var parts = data.translation.split(/({.*?})/); // @ts-ignore
|
|
53
|
-
|
|
54
|
-
return /*#__PURE__*/React.createElement("i18n-text", null, parts.map(function (part, index) {
|
|
55
|
-
return /*#__PURE__*/React.createElement("i18n-text-part", {
|
|
56
|
-
key: index
|
|
57
|
-
}, processTextPart(part, data.values, data.i18n.modifiers));
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
};
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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-
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.0-unstable.0156a4c312",
|
|
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.0156a4c312",
|
|
22
|
+
"lodash": "4.18.1"
|
|
20
23
|
},
|
|
21
24
|
"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"
|
|
25
|
+
"@webiny/build-tools": "0.0.0-unstable.0156a4c312",
|
|
26
|
+
"rimraf": "6.1.3",
|
|
27
|
+
"typescript": "7.0.2"
|
|
32
28
|
},
|
|
33
29
|
"peerDependencies": {
|
|
34
|
-
"react": "
|
|
30
|
+
"react": "19.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
|
}
|