@webiny/i18n-react 6.0.0-beta.0 β 6.0.0-rc.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/README.md +6 -14
- package/index.d.ts +3 -2
- package/index.js +22 -34
- package/index.js.map +1 -1
- package/package.json +8 -18
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,59 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
var _trim = _interopRequireDefault(require("lodash/trim"));
|
|
11
|
-
var processTextPart = function processTextPart(part, values, modifiers) {
|
|
1
|
+
import React from "react";
|
|
2
|
+
import lodashTrim from "lodash/trim.js";
|
|
3
|
+
const processTextPart = (part, values, modifiers) => {
|
|
12
4
|
if (part.startsWith("{") === false) {
|
|
13
5
|
return part;
|
|
14
6
|
}
|
|
15
|
-
part = (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
variable = _parts[0],
|
|
19
|
-
modifier = _parts[1];
|
|
7
|
+
part = lodashTrim(part, "{}");
|
|
8
|
+
const parts = part.split("|");
|
|
9
|
+
const [variable, modifier] = parts;
|
|
20
10
|
if (!values[variable]) {
|
|
21
11
|
return variable;
|
|
22
12
|
}
|
|
23
|
-
|
|
13
|
+
let value = values[variable];
|
|
24
14
|
if (modifier) {
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const parameters = modifier.split(":");
|
|
16
|
+
const name = parameters.shift();
|
|
27
17
|
if (!name) {
|
|
28
18
|
return value;
|
|
29
19
|
}
|
|
30
20
|
if (modifiers[name]) {
|
|
31
|
-
|
|
32
|
-
value =
|
|
21
|
+
const modifier = modifiers[name];
|
|
22
|
+
value = modifier.execute(value, parameters);
|
|
33
23
|
}
|
|
34
24
|
}
|
|
35
25
|
return value;
|
|
36
26
|
};
|
|
37
|
-
|
|
27
|
+
const processor = {
|
|
38
28
|
name: "react",
|
|
39
|
-
canExecute
|
|
40
|
-
for (
|
|
41
|
-
|
|
42
|
-
if (
|
|
29
|
+
canExecute(data) {
|
|
30
|
+
for (const key in data.values) {
|
|
31
|
+
const value = data.values[key];
|
|
32
|
+
if (/*#__PURE__*/React.isValidElement(value)) {
|
|
43
33
|
return true;
|
|
44
34
|
}
|
|
45
35
|
}
|
|
46
36
|
return false;
|
|
47
37
|
},
|
|
48
|
-
execute
|
|
49
|
-
|
|
50
|
-
return /*#__PURE__*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, processTextPart(part, data.values, data.i18n.modifiers));
|
|
54
|
-
}));
|
|
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))));
|
|
55
43
|
}
|
|
56
44
|
};
|
|
57
|
-
|
|
45
|
+
export default processor;
|
|
58
46
|
|
|
59
47
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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.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"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,UAAU,MAAM,gBAAgB;AAkBvC,MAAMC,eAAe,GAAGA,CACpBC,IAAY,EACZC,MAAsB,EACtBC,SAAmC,KAC1B;EACT,IAAIF,IAAI,CAACG,UAAU,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE;IAChC,OAAOH,IAAI;EACf;EAEAA,IAAI,GAAGF,UAAU,CAACE,IAAI,EAAE,IAAI,CAAC;EAE7B,MAAMI,KAAe,GAAGJ,IAAI,CAACK,KAAK,CAAC,GAAG,CAAC;EAEvC,MAAM,CAACC,QAAQ,EAAEC,QAAQ,CAAC,GAAGH,KAAK;EAElC,IAAI,CAACH,MAAM,CAACK,QAAQ,CAAC,EAAE;IACnB,OAAOA,QAAQ;EACnB;EAEA,IAAIE,KAAK,GAAGP,MAAM,CAACK,QAAQ,CAAC;EAC5B,IAAIC,QAAQ,EAAE;IACV,MAAME,UAAU,GAAGF,QAAQ,CAACF,KAAK,CAAC,GAAG,CAAC;IACtC,MAAMK,IAAI,GAAGD,UAAU,CAACE,KAAK,CAAC,CAAC;IAC/B,IAAI,CAACD,IAAI,EAAE;MACP,OAAOF,KAAK;IAChB;IACA,IAAIN,SAAS,CAACQ,IAAI,CAAC,EAAE;MACjB,MAAMH,QAAQ,GAAGL,SAAS,CAACQ,IAAI,CAAC;MAChCF,KAAK,GAAGD,QAAQ,CAACK,OAAO,CAACJ,KAAK,EAAEC,UAAU,CAAC;IAC/C;EACJ;EAEA,OAAOD,KAAK;AAChB,CAAC;AAED,MAAMK,SAAoB,GAAG;EACzBH,IAAI,EAAE,OAAO;EACbI,UAAUA,CAACC,IAAI,EAAE;IACb,KAAK,MAAMC,GAAG,IAAID,IAAI,CAACd,MAAM,EAAE;MAC3B,MAAMO,KAAK,GAAGO,IAAI,CAACd,MAAM,CAACe,GAAG,CAAC;MAC9B,iBAAInB,KAAK,CAACoB,cAAc,CAACT,KAAK,CAAC,EAAE;QAC7B,OAAO,IAAI;MACf;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,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/i18n-react",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-rc.1",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "index.js",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
@@ -14,20 +15,13 @@
|
|
|
14
15
|
],
|
|
15
16
|
"license": "MIT",
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"
|
|
19
|
-
"lodash": "4.17.21"
|
|
18
|
+
"@webiny/i18n": "6.0.0-rc.1",
|
|
19
|
+
"lodash": "4.17.23"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"@babel/preset-react": "7.24.1",
|
|
26
|
-
"@babel/preset-typescript": "7.24.1",
|
|
27
|
-
"@webiny/cli": "6.0.0-beta.0",
|
|
28
|
-
"@webiny/project-utils": "6.0.0-beta.0",
|
|
29
|
-
"rimraf": "5.0.5",
|
|
30
|
-
"typescript": "4.7.4"
|
|
22
|
+
"@webiny/build-tools": "6.0.0-rc.1",
|
|
23
|
+
"rimraf": "6.1.3",
|
|
24
|
+
"typescript": "5.9.3"
|
|
31
25
|
},
|
|
32
26
|
"peerDependencies": {
|
|
33
27
|
"react": "18.2.0"
|
|
@@ -36,9 +30,5 @@
|
|
|
36
30
|
"access": "public",
|
|
37
31
|
"directory": "dist"
|
|
38
32
|
},
|
|
39
|
-
"
|
|
40
|
-
"build": "yarn webiny run build",
|
|
41
|
-
"watch": "yarn webiny run watch"
|
|
42
|
-
},
|
|
43
|
-
"gitHead": "aa8dbfbbd5ad13ec271adba6f2431e02991a300f"
|
|
33
|
+
"gitHead": "36d702721ff9ed39fb21d6f5fe7922a2a8716e63"
|
|
44
34
|
}
|