@webiny/i18n-react 0.0.0-unstable.06b2ede40f β 0.0.0-unstable.0d717d18dd
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 +33 -40
- package/index.js.map +1 -1
- package/package.json +17 -15
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 type { 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,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,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/i18n-react",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.0-unstable.0d717d18dd",
|
|
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,24 +18,22 @@
|
|
|
14
18
|
],
|
|
15
19
|
"license": "MIT",
|
|
16
20
|
"dependencies": {
|
|
17
|
-
"@webiny/i18n": "0.0.0-unstable.
|
|
18
|
-
"lodash": "4.
|
|
21
|
+
"@webiny/i18n": "0.0.0-unstable.0d717d18dd",
|
|
22
|
+
"lodash": "4.18.1"
|
|
19
23
|
},
|
|
20
24
|
"devDependencies": {
|
|
21
|
-
"@webiny/
|
|
22
|
-
"rimraf": "6.
|
|
23
|
-
"typescript": "
|
|
25
|
+
"@webiny/build-tools": "0.0.0-unstable.0d717d18dd",
|
|
26
|
+
"rimraf": "6.1.3",
|
|
27
|
+
"typescript": "7.0.2"
|
|
24
28
|
},
|
|
25
29
|
"peerDependencies": {
|
|
26
|
-
"react": "18.
|
|
30
|
+
"react": "18.3.1"
|
|
27
31
|
},
|
|
28
32
|
"publishConfig": {
|
|
29
|
-
"access": "public"
|
|
30
|
-
"directory": "dist"
|
|
31
|
-
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"build": "node ../cli/bin.js run build",
|
|
34
|
-
"watch": "node ../cli/bin.js run watch"
|
|
33
|
+
"access": "public"
|
|
35
34
|
},
|
|
36
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
|
|
36
|
+
"webiny": {
|
|
37
|
+
"publishFrom": "dist"
|
|
38
|
+
}
|
|
37
39
|
}
|