@webiny/i18n-react 6.0.0-alpha.0 → 6.0.0-alpha.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.d.ts +1 -1
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.d.ts
CHANGED
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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\";\nimport { I18NDataValues, Modifier, Processor } from \"@webiny/i18n/types\";\n\ndeclare global {\n // eslint-disable-next-line\n namespace JSX {\n interface IntrinsicElements {\n \"i18n-text\": {\n children?: React.ReactNode;\n };\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 );\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,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":[]}
|
|
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\";\nimport type { I18NDataValues, Modifier, Processor } from \"@webiny/i18n/types\";\n\ndeclare global {\n // eslint-disable-next-line\n namespace JSX {\n interface IntrinsicElements {\n \"i18n-text\": {\n children?: React.ReactNode;\n };\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,aAAa;AAmBpC,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,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/i18n-react",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
],
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@webiny/i18n": "6.0.0-alpha.
|
|
17
|
+
"@webiny/i18n": "6.0.0-alpha.1",
|
|
18
18
|
"lodash": "4.17.21"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@webiny/project-utils": "6.0.0-alpha.
|
|
21
|
+
"@webiny/project-utils": "6.0.0-alpha.1",
|
|
22
22
|
"rimraf": "6.0.1",
|
|
23
23
|
"typescript": "5.3.3"
|
|
24
24
|
},
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"build": "node ../cli/bin.js run build",
|
|
34
34
|
"watch": "node ../cli/bin.js run watch"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "9bd236cf5e689f209a11bec089207dcc2d41a53c"
|
|
37
37
|
}
|