@team-monolith/cds 1.129.2-alpha.2 → 1.129.3-alpha
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/dist/CdsProvider.js +180 -180
- package/dist/components/AlertDialog/AlertDialogTitle.js +15 -15
- package/dist/components/Banner.js +28 -28
- package/dist/components/FileTypeAlertDialog.js +16 -16
- package/dist/components/Pagination.js +22 -22
- package/dist/emotion.d.ts +185 -0
- package/dist/i18n/i18n.js +14 -14
- package/dist/index.d.ts +8 -1
- package/dist/node_modules/.pnpm/html-parse-stringify@3.0.1/node_modules/html-parse-stringify/dist/html-parse-stringify.module.js +78 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/I18nextProvider.js +12 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/Trans.js +26 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/TransWithoutContext.js +174 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/context.js +20 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/defaults.js +24 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/i18nInstance.js +6 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/initReactI18next.js +11 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/unescape.js +25 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/useTranslation.js +69 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/utils.js +35 -0
- package/dist/patterns/LexicalEditor/Plugins.js +64 -64
- package/dist/patterns/LexicalEditor/components/FileSelectInput.js +19 -19
- package/dist/patterns/LexicalEditor/components/InsertImageDialog/ImagePreview.js +6 -6
- package/dist/patterns/LexicalEditor/components/InsertImageDialog/InsertImageDialog.js +34 -34
- package/dist/patterns/LexicalEditor/components/UploadFileDialog/UploadFileDialog.js +14 -14
- package/dist/patterns/LexicalEditor/nodes/FileNode/FileDownloadButton.js +17 -17
- package/dist/patterns/LexicalEditor/nodes/ImageNode/ImageComponent.js +62 -62
- package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/InputComponent.js +25 -25
- package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/SettingForm/FormPlaceholder.js +7 -7
- package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/SettingForm/FormSolution.js +24 -23
- package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/SettingForm/SettingForm.js +48 -47
- package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/SettingForm/TextTypeDropdown.js +11 -11
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SelectBox/SelectBoxView.js +15 -15
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SelectComponent.js +28 -28
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SettingForm/FormSelection.js +30 -30
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SettingForm/SettingForm.js +35 -35
- package/dist/patterns/LexicalEditor/nodes/SelfEvaluationNode/EvaluationComponent/Evaluation/SettingForm/FormIconAndLabel/FormIconAndLabel.js +21 -21
- package/dist/patterns/LexicalEditor/nodes/SelfEvaluationNode/EvaluationComponent/Evaluation/SettingForm/FormIconAndLabel/FormLabel.js +15 -15
- package/dist/patterns/LexicalEditor/nodes/SelfEvaluationNode/EvaluationComponent/Evaluation/SettingForm/FormQuestion.js +17 -17
- package/dist/patterns/LexicalEditor/nodes/SelfEvaluationNode/EvaluationComponent/Evaluation/SettingForm/SettingForm.js +30 -30
- package/dist/patterns/LexicalEditor/nodes/SelfEvaluationNode/EvaluationComponent/EvaluationComponent.js +20 -20
- package/dist/patterns/LexicalEditor/nodes/SheetInputNode/InputComponent.js +24 -24
- package/dist/patterns/LexicalEditor/nodes/SheetInputNode/SettingForm.js +28 -28
- package/dist/patterns/LexicalEditor/nodes/SheetSelectNode/SelectComponent/SelectBox/SelectBoxView.js +11 -11
- package/dist/patterns/LexicalEditor/nodes/SheetSelectNode/SelectComponent/SelectComponent.js +26 -26
- package/dist/patterns/LexicalEditor/nodes/SheetSelectNode/SelectComponent/SettingForm/FormAllowMultipleAnswers.js +8 -8
- package/dist/patterns/LexicalEditor/nodes/SheetSelectNode/SelectComponent/SettingForm/FormSelection.js +27 -27
- package/dist/patterns/LexicalEditor/nodes/SheetSelectNode/SelectComponent/SettingForm/SettingForm.js +33 -33
- package/dist/patterns/LexicalEditor/nodes/VideoNode/VideoComponent.js +21 -21
- package/dist/patterns/LexicalEditor/plugins/ComponentAdderPlugin/ComponentAdderPlugin.js +99 -99
- package/dist/patterns/LexicalEditor/plugins/ComponentAdderPlugin/useContextMenuOptions.js +50 -50
- package/dist/patterns/LexicalEditor/plugins/ComponentPickerMenuPlugin/ComponentPickerMenuPlugin.js +85 -85
- package/dist/patterns/LexicalEditor/plugins/DragDropPastePlugin/index.js +13 -13
- package/dist/patterns/LexicalEditor/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +48 -48
- package/dist/patterns/LexicalEditor/plugins/ImagesPlugin/useImageNodeTransform.js +16 -16
- package/dist/patterns/ToggleButtonGroup/ToggleButton.js +17 -17
- package/package.json +15 -18
- package/@types/emotion.d.ts +0 -197
- package/node_modules/react-i18next/.eslintrc.json +0 -74
- package/node_modules/react-i18next/.husky/pre-commit +0 -1
- package/node_modules/react-i18next/.prettierignore +0 -4
- package/node_modules/react-i18next/CHANGELOG.md +0 -1433
- package/node_modules/react-i18next/LICENSE +0 -22
- package/node_modules/react-i18next/README.md +0 -181
- package/node_modules/react-i18next/TransWithoutContext.d.mts +0 -1
- package/node_modules/react-i18next/TransWithoutContext.d.ts +0 -129
- package/node_modules/react-i18next/dist/amd/react-i18next.js +0 -867
- package/node_modules/react-i18next/dist/amd/react-i18next.min.js +0 -1
- package/node_modules/react-i18next/dist/commonjs/I18nextProvider.js +0 -21
- package/node_modules/react-i18next/dist/commonjs/Trans.js +0 -54
- package/node_modules/react-i18next/dist/commonjs/TransWithoutContext.js +0 -330
- package/node_modules/react-i18next/dist/commonjs/Translation.js +0 -19
- package/node_modules/react-i18next/dist/commonjs/context.js +0 -81
- package/node_modules/react-i18next/dist/commonjs/defaults.js +0 -26
- package/node_modules/react-i18next/dist/commonjs/i18nInstance.js +0 -13
- package/node_modules/react-i18next/dist/commonjs/index.js +0 -128
- package/node_modules/react-i18next/dist/commonjs/initReactI18next.js +0 -15
- package/node_modules/react-i18next/dist/commonjs/unescape.js +0 -32
- package/node_modules/react-i18next/dist/commonjs/useSSR.js +0 -34
- package/node_modules/react-i18next/dist/commonjs/useTranslation.js +0 -114
- package/node_modules/react-i18next/dist/commonjs/utils.js +0 -76
- package/node_modules/react-i18next/dist/commonjs/withSSR.js +0 -27
- package/node_modules/react-i18next/dist/commonjs/withTranslation.js +0 -39
- package/node_modules/react-i18next/dist/es/I18nextProvider.js +0 -15
- package/node_modules/react-i18next/dist/es/Trans.js +0 -43
- package/node_modules/react-i18next/dist/es/TransWithoutContext.js +0 -321
- package/node_modules/react-i18next/dist/es/Translation.js +0 -12
- package/node_modules/react-i18next/dist/es/context.js +0 -42
- package/node_modules/react-i18next/dist/es/defaults.js +0 -18
- package/node_modules/react-i18next/dist/es/i18nInstance.js +0 -5
- package/node_modules/react-i18next/dist/es/index.js +0 -18
- package/node_modules/react-i18next/dist/es/initReactI18next.js +0 -9
- package/node_modules/react-i18next/dist/es/package.json +0 -1
- package/node_modules/react-i18next/dist/es/unescape.js +0 -25
- package/node_modules/react-i18next/dist/es/useSSR.js +0 -27
- package/node_modules/react-i18next/dist/es/useTranslation.js +0 -107
- package/node_modules/react-i18next/dist/es/utils.js +0 -62
- package/node_modules/react-i18next/dist/es/withSSR.js +0 -20
- package/node_modules/react-i18next/dist/es/withTranslation.js +0 -32
- package/node_modules/react-i18next/dist/umd/react-i18next.js +0 -871
- package/node_modules/react-i18next/dist/umd/react-i18next.min.js +0 -1
- package/node_modules/react-i18next/helpers.d.ts +0 -3
- package/node_modules/react-i18next/icu.macro.d.mts +0 -1
- package/node_modules/react-i18next/icu.macro.d.ts +0 -103
- package/node_modules/react-i18next/icu.macro.js +0 -729
- package/node_modules/react-i18next/index.d.mts +0 -1
- package/node_modules/react-i18next/index.d.ts +0 -209
- package/node_modules/react-i18next/initReactI18next.d.mts +0 -1
- package/node_modules/react-i18next/initReactI18next.d.ts +0 -3
- package/node_modules/react-i18next/lint-staged.config.mjs +0 -4
- package/node_modules/react-i18next/package.json +0 -167
- package/node_modules/react-i18next/react-i18next.js +0 -871
- package/node_modules/react-i18next/react-i18next.min.js +0 -1
- package/node_modules/react-i18next/src/I18nextProvider.js +0 -7
- package/node_modules/react-i18next/src/Trans.js +0 -45
- package/node_modules/react-i18next/src/TransWithoutContext.js +0 -479
- package/node_modules/react-i18next/src/Translation.js +0 -14
- package/node_modules/react-i18next/src/context.js +0 -54
- package/node_modules/react-i18next/src/defaults.js +0 -20
- package/node_modules/react-i18next/src/i18nInstance.js +0 -7
- package/node_modules/react-i18next/src/index.js +0 -22
- package/node_modules/react-i18next/src/initReactI18next.js +0 -11
- package/node_modules/react-i18next/src/unescape.js +0 -31
- package/node_modules/react-i18next/src/useSSR.js +0 -33
- package/node_modules/react-i18next/src/useTranslation.js +0 -171
- package/node_modules/react-i18next/src/utils.js +0 -93
- package/node_modules/react-i18next/src/withSSR.js +0 -21
- package/node_modules/react-i18next/src/withTranslation.js +0 -35
- package/node_modules/react-i18next/vitest.workspace.typescript.mts +0 -52
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function a(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var a=e.indexOf("--\x3e");return{type:"comment",comment:-1!==a?e.slice(4,a):""}}for(var i=new RegExp(r),o=null;null!==(o=i.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var i=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(i,(function(i,l){if(u){if(i!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=a(i);return c<0?(s.push(h),s):((p=r[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=a(i)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!g||"<"===g||t.children.push({type:"text",content:e.slice(m,e.indexOf("<",m))}),0===c&&s.push(t),(p=r[c-1])&&p.children.push(t),r[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===i.slice(2,-1))&&(c--,t=-1===c?s:r[c]),!u&&"<"!==g&&g)){p=-1===c?s:r[c].children;var y=e.indexOf("<",m),N=e.slice(m,-1===y?void 0:y);o.test(N)&&(N=" "),(y>-1&&c+p.length>=0||" "!==N)&&p.push({type:"text",content:N})}})),s};const u=(e,n,t,s)=>{const r=[t,{code:n,...s||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);y(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...r):console?.warn&&console.warn(...r)},p={},d=(e,n,t,s)=>{y(t)&&p[t]||(y(t)&&(p[t]=new Date),u(e,n,t,s))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,N=e=>"object"==typeof e&&null!==e,x=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},v=e=>b[e];let E={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(x,v)};const O=(e={})=>{E={...E,...e}},I=()=>E;let S;const w=e=>{S=e},$=()=>S,k=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},T=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?A(n):n},A=e=>Array.isArray(e)?e:[e],R=(e,t,s,r)=>{if(!e)return"";let a="";const i=A(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))a+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(!p&&u&&!c)return void(a+=`<${l}/>`);if(!p&&(!u||c)||n.i18nIsDynamicList)return void(a+=`<${i}></${i}>`);if(u&&1===c&&y(p))return void(a+=`<${l}>${p}</${l}>`);const d=R(p,t,s,r);a+=`<${i}>${d}</${i}>`}else if(null!==e)if(N(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];return void(a+=`{{${e}}}`)}u(s,"TRANS_INVALID_OBJ","Invalid child - Object should only have keys {{ value, format }} (format is optional).",{i18nKey:r,child:e})}else u(s,"TRANS_INVALID_VAR","Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.",{i18nKey:r,child:e});else u(s,"TRANS_NULL_VALUE","Passed in a null value as child",{i18nKey:r})})),a},j=(e,t,s,r,a,i,o)=>{if(""===s)return[];const l=a.transKeepBasicHtmlNodesFor||[],u=s&&new RegExp(l.map((e=>`<${e}`)).join("|")).test(s);if(!(e||t||u||o))return[s];const p=t??{},d=e=>{A(e).forEach((e=>{y(e)||(k(e)?d(T(e)):N(e)&&!n.isValidElement(e)&&Object.assign(p,e))}))};d(e);const f=c(`<0>${s}</0>`),m={...p,...i},g=(e,t,s)=>{const r=T(e),a=x(r,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(r)&&0===a.length||e.props?.i18nIsDynamicList?r:a},h=(e,t,s,r,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:r},a?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:r,ref:e.props.ref??e.ref},a?null:t)})))},x=(e,s,i)=>{const c=A(e);return A(s).reduce(((e,s,p)=>{const d=s.children?.[0]?.content&&r.services.interpolator.interpolate(s.children[0].content,m,r.language);if("tag"===s.type){let o=c[parseInt(s.name,10)];!o&&t&&(o=t[s.name]),1!==i.length||o||(o=i[0][s.name]),o||(o={});const f=0!==Object.keys(s.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:s.attrs},o):o,b=n.isValidElement(f),v=b&&k(s,!0)&&!s.voidElement,E=u&&N(f)&&f.dummy&&!b,O=N(t)&&Object.hasOwnProperty.call(t,s.name);if(y(f)){const n=r.services.interpolator.interpolate(f,m,r.language);e.push(n)}else if(k(f)||v){const n=g(f,s,i);h(f,n,e,p)}else if(E){const n=x(c,s.children,i);h(f,n,e,p)}else if(Number.isNaN(parseFloat(s.name)))if(O){const n=g(f,s,i);h(f,n,e,p,s.voidElement)}else if(a.transSupportBasicHtmlNodes&&l.indexOf(s.name)>-1)if(s.voidElement)e.push(n.createElement(s.name,{key:`${s.name}-${p}`}));else{const t=x(c,s.children,i);e.push(n.createElement(s.name,{key:`${s.name}-${p}`},t))}else if(s.voidElement)e.push(`<${s.name} />`);else{const n=x(c,s.children,i);e.push(`<${s.name}>${n}</${s.name}>`)}else if(N(f)&&!b){const n=s.children[0]?d:null;n&&e.push(n)}else h(f,d,e,p,1!==s.children.length||!d)}else if("text"===s.type){const t=a.transWrapTextNodes,i=o?a.unescape(r.services.interpolator.interpolate(s.content,m,r.language)):r.services.interpolator.interpolate(s.content,m,r.language);t?e.push(n.createElement(t,{key:`${s.name}-${p}`},i)):e.push(i)}return e}),[])},b=x([{dummy:!0,children:e||[]}],f,A(e||[]));return T(b[0])},C=(e,t,s)=>{const r=e.key||t,a=n.cloneElement(e,{key:r});if(!a.props||!a.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return a;return n.createElement((function(){return n.createElement(n.Fragment,null,a)}),{key:r})},L=(e,n,t,s)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>C(e,t,n))))(e,n):N(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:C(e[s],s,n)})})),t})(e,n):(d(t,"TRANS_INVALID_COMPONENTS",'<Trans /> "components" prop expects an object or array',{i18nKey:s}),null):null,P=e=>!!N(e)&&(!Array.isArray(e)&&Object.keys(e).reduce(((e,n)=>e&&Number.isNaN(Number.parseFloat(n))),!0));function V({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:f,shouldUnescape:m,...g}){const h=p||$();if(!h)return d(h,"NO_I18NEXT_INSTANCE","Trans: You need to pass in an i18next instance using i18nextReactModule",{i18nKey:r}),e;const N=f||h.t.bind(h)||(e=>e),x={...I(),...h.options?.react};let b=u||N.ns||h.options?.defaultNS;b=y(b)?[b]:b||["translation"];const v=R(e,x,h,r),E=l||v||x.transEmptyNodeValue||r,{hashTransKey:O}=x,S=r||(O?O(v||E):v||E);h.options?.interpolation?.defaultVariables&&(o=o&&Object.keys(o).length>0?{...o,...h.options.interpolation.defaultVariables}:{...h.options.interpolation.defaultVariables});const w=o||void 0!==t&&!h.options?.interpolation?.alwaysFormat||!e?i.interpolation:{interpolation:{...i.interpolation,prefix:"#$?",suffix:"?$#"}},k={...i,context:a||i.context,count:t,...o,...w,defaultValue:E,ns:b},T=S?N(S,k):E,A=L(c,T,h,r);let C=A||e,V=null;P(A)&&(V=A,C=e);const _=j(C,V,T,h,x,k,m),D=s??x.defaultTransParent;return D?n.createElement(D,g,_):_}const _={type:"3rdParty",init(e){O(e.options.react),w(e)}},D=n.createContext();class K{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const z=e=>async n=>({...await(e.getInitialProps?.(n))??{},...U()}),U=()=>{const e=$(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const F=(e,n,t,s)=>e.getFixedT(n,t,s),B=(e,t={})=>{const{i18n:s}=t,{i18n:r,defaultNS:a}=n.useContext(D)||{},i=s||r||$();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new K),!i){d(i,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:N(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}i.options.react?.wait&&d(i,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...I(),...i.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||a||i.options?.defaultNS;u=y(u)?[u]:u||["translation"],i.reportNamespaces.addUsedNamespaces?.(u);const p=(i.isInitialized||i.initializedStoreOnce)&&u.every((e=>((e,n,t={})=>n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d(n,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:n.languages}),!0))(e,i,o))),f=((e,t,s,r)=>n.useCallback(F(e,t,s,r),[e,t,s,r]))(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,x=()=>F(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[b,v]=n.useState(h);let E=u.join();t.lng&&(E=`${t.lng}${E}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(E),S=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;S.current=!0,p||l||(t.lng?g(i,t.lng,u,(()=>{S.current&&v(x)})):m(i,u,(()=>{S.current&&v(x)}))),p&&O&&O!==E&&S.current&&v(x);const s=()=>{S.current&&v(x)};return e&&i?.on(e,s),n&&i?.store.on(n,s),()=>{S.current=!1,i&&e&&e?.split(" ").forEach((e=>i.off(e,s))),n&&i&&n.split(" ").forEach((e=>i.store.off(e,s)))}}),[i,E]),n.useEffect((()=>{S.current&&p&&v(h)}),[i,c,p]);const w=[b,i,p];if(w.t=b,w.i18n=i,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?g(i,t.lng,u,(()=>e())):m(i,u,(()=>e()))}))};const W=(e,t,s={})=>{const{i18n:r}=s,{i18n:a}=n.useContext(D)||{},i=r||a||$();i.options?.isClone||(e&&!i.initializedStoreOnce&&(i.services.resourceStore.data=e,i.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),i.options.ns),i.initializedStoreOnce=!0,i.isInitialized=!0),t&&!i.initializedLanguageOnce&&(i.changeLanguage(t),i.initializedLanguageOnce=!0))};e.I18nContext=D,e.I18nextProvider=function({i18n:e,defaultNS:t,children:s}){const r=n.useMemo((()=>({i18n:e,defaultNS:t})),[e,t]);return n.createElement(D.Provider,{value:r},s)},e.Trans=function({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:d,shouldUnescape:f,...m}){const{i18n:g,defaultNS:h}=n.useContext(D)||{},y=p||g||$(),N=d||y?.t.bind(y);return V({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i,values:o,defaults:l,components:c,ns:u||N?.ns||h||y?.options?.defaultNS,i18n:y,t:d,shouldUnescape:f,...m})},e.TransWithoutContext=V,e.Translation=({ns:e,children:n,...t})=>{const[s,r,a]=B(e,t);return n(s,{i18n:r,lng:r.language},a)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=I,e.getI18n=$,e.getInitialProps=U,e.initReactI18next=_,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=W,e.useTranslation=B,e.withSSR=()=>function(e){function t({initialI18nStore:t,initialLanguage:s,...r}){return W(t,s),n.createElement(e,{...r})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${h(e)})`,t.WrappedComponent=e,t},e.withTranslation=(e,t={})=>function(s){function r({forwardedRef:r,...a}){const[i,o,l]=B(e,{...a,keyPrefix:t.keyPrefix}),c={...a,t:i,i18n:o,tReady:l};return t.withRef&&r?c.ref=r:!t.withRef&&r&&(c.forwardedRef=r),n.createElement(s,c)}r.displayName=`withI18nextTranslation(${h(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}));
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { createElement, useMemo } from 'react';
|
|
2
|
-
import { I18nContext } from './context.js';
|
|
3
|
-
|
|
4
|
-
export function I18nextProvider({ i18n, defaultNS, children }) {
|
|
5
|
-
const value = useMemo(() => ({ i18n, defaultNS }), [i18n, defaultNS]);
|
|
6
|
-
return createElement(I18nContext.Provider, { value }, children);
|
|
7
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
import { nodesToString, Trans as TransWithoutContext } from './TransWithoutContext.js';
|
|
3
|
-
import { getI18n, I18nContext } from './context.js';
|
|
4
|
-
|
|
5
|
-
export { nodesToString };
|
|
6
|
-
|
|
7
|
-
export function Trans({
|
|
8
|
-
children,
|
|
9
|
-
count,
|
|
10
|
-
parent,
|
|
11
|
-
i18nKey,
|
|
12
|
-
context,
|
|
13
|
-
tOptions = {},
|
|
14
|
-
values,
|
|
15
|
-
defaults,
|
|
16
|
-
components,
|
|
17
|
-
ns,
|
|
18
|
-
i18n: i18nFromProps,
|
|
19
|
-
t: tFromProps,
|
|
20
|
-
shouldUnescape,
|
|
21
|
-
...additionalProps
|
|
22
|
-
}) {
|
|
23
|
-
const { i18n: i18nFromContext, defaultNS: defaultNSFromContext } = useContext(I18nContext) || {};
|
|
24
|
-
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
25
|
-
|
|
26
|
-
const t = tFromProps || i18n?.t.bind(i18n);
|
|
27
|
-
|
|
28
|
-
return TransWithoutContext({
|
|
29
|
-
children,
|
|
30
|
-
count,
|
|
31
|
-
parent,
|
|
32
|
-
i18nKey,
|
|
33
|
-
context,
|
|
34
|
-
tOptions,
|
|
35
|
-
values,
|
|
36
|
-
defaults,
|
|
37
|
-
components,
|
|
38
|
-
// prepare having a namespace
|
|
39
|
-
ns: ns || t?.ns || defaultNSFromContext || i18n?.options?.defaultNS,
|
|
40
|
-
i18n,
|
|
41
|
-
t: tFromProps,
|
|
42
|
-
shouldUnescape,
|
|
43
|
-
...additionalProps,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
@@ -1,479 +0,0 @@
|
|
|
1
|
-
import { Fragment, isValidElement, cloneElement, createElement, Children } from 'react';
|
|
2
|
-
import HTML from 'html-parse-stringify';
|
|
3
|
-
import { isObject, isString, warn, warnOnce } from './utils.js';
|
|
4
|
-
import { getDefaults } from './defaults.js';
|
|
5
|
-
import { getI18n } from './i18nInstance.js';
|
|
6
|
-
|
|
7
|
-
const hasChildren = (node, checkLength) => {
|
|
8
|
-
if (!node) return false;
|
|
9
|
-
const base = node.props?.children ?? node.children;
|
|
10
|
-
if (checkLength) return base.length > 0;
|
|
11
|
-
return !!base;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const getChildren = (node) => {
|
|
15
|
-
if (!node) return [];
|
|
16
|
-
const children = node.props?.children ?? node.children;
|
|
17
|
-
return node.props?.i18nIsDynamicList ? getAsArray(children) : children;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const hasValidReactChildren = (children) =>
|
|
21
|
-
Array.isArray(children) && children.every(isValidElement);
|
|
22
|
-
|
|
23
|
-
const getAsArray = (data) => (Array.isArray(data) ? data : [data]);
|
|
24
|
-
|
|
25
|
-
const mergeProps = (source, target) => {
|
|
26
|
-
const newTarget = { ...target };
|
|
27
|
-
// overwrite source.props when target.props already set
|
|
28
|
-
newTarget.props = Object.assign(source.props, target.props);
|
|
29
|
-
return newTarget;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
|
|
33
|
-
if (!children) return '';
|
|
34
|
-
let stringNode = '';
|
|
35
|
-
|
|
36
|
-
// do not use `React.Children.toArray`, will fail at object children
|
|
37
|
-
const childrenArray = getAsArray(children);
|
|
38
|
-
const keepArray = i18nOptions?.transSupportBasicHtmlNodes
|
|
39
|
-
? (i18nOptions.transKeepBasicHtmlNodesFor ?? [])
|
|
40
|
-
: [];
|
|
41
|
-
|
|
42
|
-
// e.g. lorem <br/> ipsum {{ messageCount, format }} dolor <strong>bold</strong> amet
|
|
43
|
-
childrenArray.forEach((child, childIndex) => {
|
|
44
|
-
if (isString(child)) {
|
|
45
|
-
// actual e.g. lorem
|
|
46
|
-
// expected e.g. lorem
|
|
47
|
-
stringNode += `${child}`;
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (isValidElement(child)) {
|
|
51
|
-
const { props, type } = child;
|
|
52
|
-
const childPropsCount = Object.keys(props).length;
|
|
53
|
-
const shouldKeepChild = keepArray.indexOf(type) > -1;
|
|
54
|
-
const childChildren = props.children;
|
|
55
|
-
|
|
56
|
-
if (!childChildren && shouldKeepChild && !childPropsCount) {
|
|
57
|
-
// actual e.g. lorem <br/> ipsum
|
|
58
|
-
// expected e.g. lorem <br/> ipsum
|
|
59
|
-
stringNode += `<${type}/>`;
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if ((!childChildren && (!shouldKeepChild || childPropsCount)) || props.i18nIsDynamicList) {
|
|
63
|
-
// actual e.g. lorem <hr className="test" /> ipsum
|
|
64
|
-
// expected e.g. lorem <0></0> ipsum
|
|
65
|
-
// or
|
|
66
|
-
// we got a dynamic list like
|
|
67
|
-
// e.g. <ul i18nIsDynamicList>{['a', 'b'].map(item => ( <li key={item}>{item}</li> ))}</ul>
|
|
68
|
-
// expected e.g. "<0></0>", not e.g. "<0><0>a</0><1>b</1></0>"
|
|
69
|
-
stringNode += `<${childIndex}></${childIndex}>`;
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
|
|
73
|
-
// actual e.g. dolor <strong>bold</strong> amet
|
|
74
|
-
// expected e.g. dolor <strong>bold</strong> amet
|
|
75
|
-
stringNode += `<${type}>${childChildren}</${type}>`;
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
// regular case mapping the inner children
|
|
79
|
-
const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
|
|
80
|
-
stringNode += `<${childIndex}>${content}</${childIndex}>`;
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (child === null) {
|
|
84
|
-
warn(i18n, 'TRANS_NULL_VALUE', `Passed in a null value as child`, { i18nKey });
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (isObject(child)) {
|
|
88
|
-
// e.g. lorem {{ value, format }} ipsum
|
|
89
|
-
const { format, ...clone } = child;
|
|
90
|
-
const keys = Object.keys(clone);
|
|
91
|
-
|
|
92
|
-
if (keys.length === 1) {
|
|
93
|
-
const value = format ? `${keys[0]}, ${format}` : keys[0];
|
|
94
|
-
stringNode += `{{${value}}}`;
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
warn(
|
|
98
|
-
i18n,
|
|
99
|
-
'TRANS_INVALID_OBJ',
|
|
100
|
-
`Invalid child - Object should only have keys {{ value, format }} (format is optional).`,
|
|
101
|
-
{ i18nKey, child },
|
|
102
|
-
);
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
warn(
|
|
106
|
-
i18n,
|
|
107
|
-
'TRANS_INVALID_VAR',
|
|
108
|
-
`Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`,
|
|
109
|
-
{ i18nKey, child },
|
|
110
|
-
);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
return stringNode;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const renderNodes = (
|
|
117
|
-
children,
|
|
118
|
-
knownComponentsMap,
|
|
119
|
-
targetString,
|
|
120
|
-
i18n,
|
|
121
|
-
i18nOptions,
|
|
122
|
-
combinedTOpts,
|
|
123
|
-
shouldUnescape,
|
|
124
|
-
) => {
|
|
125
|
-
if (targetString === '') return [];
|
|
126
|
-
|
|
127
|
-
// check if contains tags we need to replace from html string to react nodes
|
|
128
|
-
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
129
|
-
const emptyChildrenButNeedsHandling =
|
|
130
|
-
targetString && new RegExp(keepArray.map((keep) => `<${keep}`).join('|')).test(targetString);
|
|
131
|
-
|
|
132
|
-
// no need to replace tags in the targetstring
|
|
133
|
-
if (!children && !knownComponentsMap && !emptyChildrenButNeedsHandling && !shouldUnescape)
|
|
134
|
-
return [targetString];
|
|
135
|
-
|
|
136
|
-
// v2 -> interpolates upfront no need for "some <0>{{var}}</0>"" -> will be just "some {{var}}" in translation file
|
|
137
|
-
const data = knownComponentsMap ?? {};
|
|
138
|
-
|
|
139
|
-
const getData = (childs) => {
|
|
140
|
-
const childrenArray = getAsArray(childs);
|
|
141
|
-
|
|
142
|
-
childrenArray.forEach((child) => {
|
|
143
|
-
if (isString(child)) return;
|
|
144
|
-
if (hasChildren(child)) getData(getChildren(child));
|
|
145
|
-
else if (isObject(child) && !isValidElement(child)) Object.assign(data, child);
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
getData(children);
|
|
150
|
-
|
|
151
|
-
// parse ast from string with additional wrapper tag
|
|
152
|
-
// -> avoids issues in parser removing prepending text nodes
|
|
153
|
-
const ast = HTML.parse(`<0>${targetString}</0>`);
|
|
154
|
-
const opts = { ...data, ...combinedTOpts };
|
|
155
|
-
|
|
156
|
-
const renderInner = (child, node, rootReactNode) => {
|
|
157
|
-
const childs = getChildren(child);
|
|
158
|
-
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
159
|
-
// `mappedChildren` will always be empty if using the `i18nIsDynamicList` prop,
|
|
160
|
-
// but the children might not necessarily be react components
|
|
161
|
-
return (hasValidReactChildren(childs) && mappedChildren.length === 0) ||
|
|
162
|
-
child.props?.i18nIsDynamicList
|
|
163
|
-
? childs
|
|
164
|
-
: mappedChildren;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const pushTranslatedJSX = (child, inner, mem, i, isVoid) => {
|
|
168
|
-
if (child.dummy) {
|
|
169
|
-
child.children = inner; // needed on preact!
|
|
170
|
-
mem.push(cloneElement(child, { key: i }, isVoid ? undefined : inner));
|
|
171
|
-
} else {
|
|
172
|
-
mem.push(
|
|
173
|
-
...Children.map([child], (c) => {
|
|
174
|
-
const props = { ...c.props };
|
|
175
|
-
delete props.i18nIsDynamicList;
|
|
176
|
-
// <c.type {...props} key={i} ref={c.ref} {...(isVoid ? {} : { children: inner })} />;
|
|
177
|
-
return createElement(
|
|
178
|
-
c.type,
|
|
179
|
-
{
|
|
180
|
-
...props,
|
|
181
|
-
key: i,
|
|
182
|
-
ref: c.props.ref ?? c.ref, // ref is a prop in react >= v19
|
|
183
|
-
},
|
|
184
|
-
isVoid ? null : inner,
|
|
185
|
-
);
|
|
186
|
-
}),
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
// reactNode (the jsx root element or child)
|
|
192
|
-
// astNode (the translation string as html ast)
|
|
193
|
-
// rootReactNode (the most outer jsx children array or trans components prop)
|
|
194
|
-
const mapAST = (reactNode, astNode, rootReactNode) => {
|
|
195
|
-
const reactNodes = getAsArray(reactNode);
|
|
196
|
-
const astNodes = getAsArray(astNode);
|
|
197
|
-
|
|
198
|
-
return astNodes.reduce((mem, node, i) => {
|
|
199
|
-
const translationContent =
|
|
200
|
-
node.children?.[0]?.content &&
|
|
201
|
-
i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
202
|
-
|
|
203
|
-
if (node.type === 'tag') {
|
|
204
|
-
// regular array (components or children)
|
|
205
|
-
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
206
|
-
if (!tmp && knownComponentsMap) tmp = knownComponentsMap[node.name];
|
|
207
|
-
|
|
208
|
-
// trans components is an object
|
|
209
|
-
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
210
|
-
|
|
211
|
-
// neither
|
|
212
|
-
if (!tmp) tmp = {};
|
|
213
|
-
|
|
214
|
-
const child =
|
|
215
|
-
Object.keys(node.attrs).length !== 0 ? mergeProps({ props: node.attrs }, tmp) : tmp;
|
|
216
|
-
|
|
217
|
-
const isElement = isValidElement(child);
|
|
218
|
-
|
|
219
|
-
const isValidTranslationWithChildren =
|
|
220
|
-
isElement && hasChildren(node, true) && !node.voidElement;
|
|
221
|
-
|
|
222
|
-
const isEmptyTransWithHTML =
|
|
223
|
-
emptyChildrenButNeedsHandling && isObject(child) && child.dummy && !isElement;
|
|
224
|
-
|
|
225
|
-
const isKnownComponent =
|
|
226
|
-
isObject(knownComponentsMap) && Object.hasOwnProperty.call(knownComponentsMap, node.name);
|
|
227
|
-
|
|
228
|
-
if (isString(child)) {
|
|
229
|
-
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
230
|
-
mem.push(value);
|
|
231
|
-
} else if (
|
|
232
|
-
hasChildren(child) || // the jsx element has children -> loop
|
|
233
|
-
isValidTranslationWithChildren // valid jsx element with no children but the translation has -> loop
|
|
234
|
-
) {
|
|
235
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
236
|
-
pushTranslatedJSX(child, inner, mem, i);
|
|
237
|
-
} else if (isEmptyTransWithHTML) {
|
|
238
|
-
// we have a empty Trans node (the dummy element) with a targetstring that contains html tags needing
|
|
239
|
-
// conversion to react nodes
|
|
240
|
-
// so we just need to map the inner stuff
|
|
241
|
-
const inner = mapAST(
|
|
242
|
-
reactNodes /* wrong but we need something */,
|
|
243
|
-
node.children,
|
|
244
|
-
rootReactNode,
|
|
245
|
-
);
|
|
246
|
-
pushTranslatedJSX(child, inner, mem, i);
|
|
247
|
-
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
248
|
-
if (isKnownComponent) {
|
|
249
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
250
|
-
pushTranslatedJSX(child, inner, mem, i, node.voidElement);
|
|
251
|
-
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
252
|
-
if (node.voidElement) {
|
|
253
|
-
mem.push(createElement(node.name, { key: `${node.name}-${i}` }));
|
|
254
|
-
} else {
|
|
255
|
-
const inner = mapAST(
|
|
256
|
-
reactNodes /* wrong but we need something */,
|
|
257
|
-
node.children,
|
|
258
|
-
rootReactNode,
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
mem.push(createElement(node.name, { key: `${node.name}-${i}` }, inner));
|
|
262
|
-
}
|
|
263
|
-
} else if (node.voidElement) {
|
|
264
|
-
mem.push(`<${node.name} />`);
|
|
265
|
-
} else {
|
|
266
|
-
const inner = mapAST(
|
|
267
|
-
reactNodes /* wrong but we need something */,
|
|
268
|
-
node.children,
|
|
269
|
-
rootReactNode,
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
mem.push(`<${node.name}>${inner}</${node.name}>`);
|
|
273
|
-
}
|
|
274
|
-
} else if (isObject(child) && !isElement) {
|
|
275
|
-
const content = node.children[0] ? translationContent : null;
|
|
276
|
-
|
|
277
|
-
// v1
|
|
278
|
-
// as interpolation was done already we just have a regular content node
|
|
279
|
-
// in the translation AST while having an object in reactNodes
|
|
280
|
-
// -> push the content no need to interpolate again
|
|
281
|
-
if (content) mem.push(content);
|
|
282
|
-
} else {
|
|
283
|
-
// If component does not have children, but translation - has
|
|
284
|
-
// with this in component could be components={[<span class='make-beautiful'/>]} and in translation - 'some text <0>some highlighted message</0>'
|
|
285
|
-
pushTranslatedJSX(
|
|
286
|
-
child,
|
|
287
|
-
translationContent,
|
|
288
|
-
mem,
|
|
289
|
-
i,
|
|
290
|
-
node.children.length !== 1 || !translationContent,
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
} else if (node.type === 'text') {
|
|
294
|
-
const wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
295
|
-
const content = shouldUnescape
|
|
296
|
-
? i18nOptions.unescape(
|
|
297
|
-
i18n.services.interpolator.interpolate(node.content, opts, i18n.language),
|
|
298
|
-
)
|
|
299
|
-
: i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
300
|
-
if (wrapTextNodes) {
|
|
301
|
-
mem.push(createElement(wrapTextNodes, { key: `${node.name}-${i}` }, content));
|
|
302
|
-
} else {
|
|
303
|
-
mem.push(content);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
return mem;
|
|
307
|
-
}, []);
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
// call mapAST with having react nodes nested into additional node like
|
|
311
|
-
// we did for the string ast from translation
|
|
312
|
-
// return the children of that extra node to get expected result
|
|
313
|
-
const result = mapAST(
|
|
314
|
-
[{ dummy: true, children: children || [] }],
|
|
315
|
-
ast,
|
|
316
|
-
getAsArray(children || []),
|
|
317
|
-
);
|
|
318
|
-
return getChildren(result[0]);
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
const fixComponentProps = (component, index, translation) => {
|
|
322
|
-
const componentKey = component.key || index;
|
|
323
|
-
const comp = cloneElement(component, { key: componentKey });
|
|
324
|
-
if (
|
|
325
|
-
!comp.props ||
|
|
326
|
-
!comp.props.children ||
|
|
327
|
-
(translation.indexOf(`${index}/>`) < 0 && translation.indexOf(`${index} />`) < 0)
|
|
328
|
-
) {
|
|
329
|
-
return comp;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
function Componentized() {
|
|
333
|
-
// <>{comp}</>
|
|
334
|
-
return createElement(Fragment, null, comp);
|
|
335
|
-
}
|
|
336
|
-
// <Componentized />
|
|
337
|
-
return createElement(Componentized, { key: componentKey });
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
const generateArrayComponents = (components, translation) =>
|
|
341
|
-
components.map((c, index) => fixComponentProps(c, index, translation));
|
|
342
|
-
|
|
343
|
-
const generateObjectComponents = (components, translation) => {
|
|
344
|
-
const componentMap = {};
|
|
345
|
-
|
|
346
|
-
Object.keys(components).forEach((c) => {
|
|
347
|
-
Object.assign(componentMap, {
|
|
348
|
-
[c]: fixComponentProps(components[c], c, translation),
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
return componentMap;
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
const generateComponents = (components, translation, i18n, i18nKey) => {
|
|
356
|
-
if (!components) return null;
|
|
357
|
-
|
|
358
|
-
// components could be either an array or an object
|
|
359
|
-
|
|
360
|
-
if (Array.isArray(components)) {
|
|
361
|
-
return generateArrayComponents(components, translation);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (isObject(components)) {
|
|
365
|
-
return generateObjectComponents(components, translation);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// if components is not an array or an object, warn the user
|
|
369
|
-
// and return null
|
|
370
|
-
warnOnce(
|
|
371
|
-
i18n,
|
|
372
|
-
'TRANS_INVALID_COMPONENTS',
|
|
373
|
-
`<Trans /> "components" prop expects an object or array`,
|
|
374
|
-
{ i18nKey },
|
|
375
|
-
);
|
|
376
|
-
return null;
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
// A component map is an object like: { Button: <button> }, but not an object like { 1: <button> }
|
|
380
|
-
const isComponentsMap = (object) => {
|
|
381
|
-
if (!isObject(object)) return false;
|
|
382
|
-
if (Array.isArray(object)) return false;
|
|
383
|
-
return Object.keys(object).reduce(
|
|
384
|
-
(acc, key) => acc && Number.isNaN(Number.parseFloat(key)),
|
|
385
|
-
true,
|
|
386
|
-
);
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
export function Trans({
|
|
390
|
-
children,
|
|
391
|
-
count,
|
|
392
|
-
parent,
|
|
393
|
-
i18nKey,
|
|
394
|
-
context,
|
|
395
|
-
tOptions = {},
|
|
396
|
-
values,
|
|
397
|
-
defaults,
|
|
398
|
-
components,
|
|
399
|
-
ns,
|
|
400
|
-
i18n: i18nFromProps,
|
|
401
|
-
t: tFromProps,
|
|
402
|
-
shouldUnescape,
|
|
403
|
-
...additionalProps
|
|
404
|
-
}) {
|
|
405
|
-
const i18n = i18nFromProps || getI18n();
|
|
406
|
-
|
|
407
|
-
if (!i18n) {
|
|
408
|
-
warnOnce(
|
|
409
|
-
i18n,
|
|
410
|
-
'NO_I18NEXT_INSTANCE',
|
|
411
|
-
`Trans: You need to pass in an i18next instance using i18nextReactModule`,
|
|
412
|
-
{ i18nKey },
|
|
413
|
-
);
|
|
414
|
-
return children;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
const t = tFromProps || i18n.t.bind(i18n) || ((k) => k);
|
|
418
|
-
|
|
419
|
-
const reactI18nextOptions = { ...getDefaults(), ...i18n.options?.react };
|
|
420
|
-
|
|
421
|
-
// prepare having a namespace
|
|
422
|
-
let namespaces = ns || t.ns || i18n.options?.defaultNS;
|
|
423
|
-
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
|
|
424
|
-
|
|
425
|
-
const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
|
|
426
|
-
const defaultValue =
|
|
427
|
-
defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
428
|
-
const { hashTransKey } = reactI18nextOptions;
|
|
429
|
-
const key =
|
|
430
|
-
i18nKey ||
|
|
431
|
-
(hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue);
|
|
432
|
-
if (i18n.options?.interpolation?.defaultVariables) {
|
|
433
|
-
// eslint-disable-next-line no-param-reassign
|
|
434
|
-
values =
|
|
435
|
-
values && Object.keys(values).length > 0
|
|
436
|
-
? { ...values, ...i18n.options.interpolation.defaultVariables }
|
|
437
|
-
: { ...i18n.options.interpolation.defaultVariables };
|
|
438
|
-
}
|
|
439
|
-
const interpolationOverride =
|
|
440
|
-
values ||
|
|
441
|
-
(count !== undefined && !i18n.options?.interpolation?.alwaysFormat) || // https://github.com/i18next/react-i18next/issues/1719 + https://github.com/i18next/react-i18next/issues/1801
|
|
442
|
-
!children // if !children gets problems in future, undo that fix: https://github.com/i18next/react-i18next/issues/1729 by removing !children from this condition
|
|
443
|
-
? tOptions.interpolation
|
|
444
|
-
: { interpolation: { ...tOptions.interpolation, prefix: '#$?', suffix: '?$#' } };
|
|
445
|
-
const combinedTOpts = {
|
|
446
|
-
...tOptions,
|
|
447
|
-
context: context || tOptions.context, // Add `context` from the props or fallback to the value from `tOptions`
|
|
448
|
-
count,
|
|
449
|
-
...values,
|
|
450
|
-
...interpolationOverride,
|
|
451
|
-
defaultValue,
|
|
452
|
-
ns: namespaces,
|
|
453
|
-
};
|
|
454
|
-
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
455
|
-
|
|
456
|
-
const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
|
|
457
|
-
let indexedChildren = generatedComponents || children;
|
|
458
|
-
let componentsMap = null;
|
|
459
|
-
if (isComponentsMap(generatedComponents)) {
|
|
460
|
-
componentsMap = generatedComponents;
|
|
461
|
-
indexedChildren = children;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
const content = renderNodes(
|
|
465
|
-
indexedChildren,
|
|
466
|
-
componentsMap,
|
|
467
|
-
translation,
|
|
468
|
-
i18n,
|
|
469
|
-
reactI18nextOptions,
|
|
470
|
-
combinedTOpts,
|
|
471
|
-
shouldUnescape,
|
|
472
|
-
);
|
|
473
|
-
|
|
474
|
-
// allows user to pass `null` to `parent`
|
|
475
|
-
// and override `defaultTransParent` if is present
|
|
476
|
-
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
|
|
477
|
-
|
|
478
|
-
return useAsParent ? createElement(useAsParent, additionalProps, content) : content;
|
|
479
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useTranslation } from './useTranslation.js';
|
|
2
|
-
|
|
3
|
-
export const Translation = ({ ns, children, ...options }) => {
|
|
4
|
-
const [t, i18n, ready] = useTranslation(ns, options);
|
|
5
|
-
|
|
6
|
-
return children(
|
|
7
|
-
t,
|
|
8
|
-
{
|
|
9
|
-
i18n,
|
|
10
|
-
lng: i18n.language,
|
|
11
|
-
},
|
|
12
|
-
ready,
|
|
13
|
-
);
|
|
14
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
2
|
-
import { getDefaults, setDefaults } from './defaults.js';
|
|
3
|
-
import { getI18n, setI18n } from './i18nInstance.js';
|
|
4
|
-
import { initReactI18next } from './initReactI18next.js';
|
|
5
|
-
|
|
6
|
-
export { getDefaults, setDefaults, getI18n, setI18n, initReactI18next };
|
|
7
|
-
|
|
8
|
-
export const I18nContext = createContext();
|
|
9
|
-
|
|
10
|
-
export class ReportNamespaces {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.usedNamespaces = {};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
addUsedNamespaces(namespaces) {
|
|
16
|
-
namespaces.forEach((ns) => {
|
|
17
|
-
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getUsedNamespaces() {
|
|
22
|
-
return Object.keys(this.usedNamespaces);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const composeInitialProps = (ForComponent) => async (ctx) => {
|
|
27
|
-
const componentsInitialProps = (await ForComponent.getInitialProps?.(ctx)) ?? {};
|
|
28
|
-
|
|
29
|
-
const i18nInitialProps = getInitialProps();
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
...componentsInitialProps,
|
|
33
|
-
...i18nInitialProps,
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const getInitialProps = () => {
|
|
38
|
-
const i18n = getI18n();
|
|
39
|
-
const namespaces = i18n.reportNamespaces?.getUsedNamespaces() ?? [];
|
|
40
|
-
|
|
41
|
-
const ret = {};
|
|
42
|
-
const initialI18nStore = {};
|
|
43
|
-
i18n.languages.forEach((l) => {
|
|
44
|
-
initialI18nStore[l] = {};
|
|
45
|
-
namespaces.forEach((ns) => {
|
|
46
|
-
initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
ret.initialI18nStore = initialI18nStore;
|
|
51
|
-
ret.initialLanguage = i18n.language;
|
|
52
|
-
|
|
53
|
-
return ret;
|
|
54
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { unescape } from './unescape.js';
|
|
2
|
-
|
|
3
|
-
let defaultOptions = {
|
|
4
|
-
bindI18n: 'languageChanged',
|
|
5
|
-
bindI18nStore: '',
|
|
6
|
-
// nsMode: 'fallback' // loop through all namespaces given to hook, HOC, render prop for key lookup
|
|
7
|
-
transEmptyNodeValue: '',
|
|
8
|
-
transSupportBasicHtmlNodes: true,
|
|
9
|
-
transWrapTextNodes: '',
|
|
10
|
-
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
|
|
11
|
-
// hashTransKey: key => key // calculate a key for Trans component based on defaultValue
|
|
12
|
-
useSuspense: true,
|
|
13
|
-
unescape,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const setDefaults = (options = {}) => {
|
|
17
|
-
defaultOptions = { ...defaultOptions, ...options };
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const getDefaults = () => defaultOptions;
|