1 line
9.1 KiB
JavaScript
1 line
9.1 KiB
JavaScript
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8585],{5138:(e,t,n)=>{n.d(t,{f:()=>r.useClientTranslations,useLocale:()=>s,useTranslations:()=>i});var a=n(12115),o=n(25668),r=n(76703);function i(e){var t;if(!(0,a.useContext)(o.x))throw Error("useTranslations must be used within a TranslationProvider");let n=(null===(t=Error().stack)||void 0===t?void 0:t.split("\n"))||[],i=n.length>2?n[2].trim():"unknown location";return console.warn("[i18n] useTranslations is deprecated. Use useClientTranslations instead. Called from ".concat(i)),(0,r.useClientTranslations)(e)}function s(){var e;if(!(0,a.useContext)(o.x))throw Error("useLocale must be used within a TranslationProvider");let t=(null===(e=Error().stack)||void 0===e?void 0:e.split("\n"))||[],n=t.length>2?t[2].trim():"unknown location";return console.warn("[i18n] useLocale is deprecated. Use useClientLocale instead. Called from ".concat(n)),(0,r.useClientLocale)()}},15484:(e,t,n)=>{n.d(t,{ClientTranslationAdapter:()=>r,withClientTranslations:()=>i});var a=n(95155);n(12115);var o=n(52014);function r(e){let{locale:t,translations:n,namespaces:r,children:i}=e;if("string"!=typeof t)throw console.error("ClientTranslationAdapter received invalid locale type: ".concat(typeof t,". Expected string.")),Error("ClientTranslationAdapter requires a string locale, received: ".concat(typeof t));if(!n||"object"!=typeof n)throw console.error("ClientTranslationAdapter received invalid translations type: ".concat(typeof n,". Expected object.")),Error("ClientTranslationAdapter requires an object for translations, received: ".concat(typeof n));return Array.isArray(r)||console.warn("ClientTranslationAdapter received invalid namespaces type: ".concat(typeof r,". Expected array.")),(0,a.jsx)(o.ClientTranslationProvider,{locale:t,translations:n,children:i})}function i(e,t){if(!e)throw Error("withClientTranslations requires a valid component");return Array.isArray(t)&&0!==t.length||console.warn("[i18n] withClientTranslations called with empty or invalid namespaces array"),function(n){let{locale:o,translations:i,...s}=n;return(0,a.jsx)(r,{locale:o,translations:i,namespaces:t,children:(0,a.jsx)(e,{...s})})}}},36893:(e,t,n)=>{n.r(t),n.d(t,{NamespaceProcessor:()=>o});var a=n(86696);class o{processNestedNamespace(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!n||0===Object.keys(n).length||!t)return;let o=t.includes(".")?t.split("."):[t];if(1===o.length){e[t]=JSON.parse(JSON.stringify(n));return}let r=e;for(let e=0;e<o.length-1;e++){let t=o[e];r[t]||(r[t]={}),r=r[t]}let i=o[o.length-1];r[i]&&"object"==typeof r[i]&&!Array.isArray(r[i])?this.deepMerge(r[i],n):r[i]=JSON.parse(JSON.stringify(n)),a&&t.includes(".")&&(e[t]=JSON.parse(JSON.stringify(n)))}deepMerge(e,t){for(let n in t)t.hasOwnProperty(n)&&(t[n]&&"object"==typeof t[n]&&!Array.isArray(t[n])&&e[n]&&"object"==typeof e[n]&&!Array.isArray(e[n])?this.deepMerge(e[n],t[n]):e[n]=t[n])}flattenObject(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o={};if(!e)return o;for(let r of Object.keys(e)){let i=e[r],s=t?a.TranslationAccessService.createKey(t,r):r;"object"!=typeof i||null===i||Array.isArray(i)?o[s]=i:(Object.assign(o,this.flattenObject(i,s)),n&&(o[s]=i))}return o}}},52014:(e,t,n)=>{n.r(t),n.d(t,{ClientTranslationProvider:()=>c,LanguageSwitcherLink:()=>l,TranslationProvider:()=>s,withClientTranslations:()=>d});var a=n(95155),o=n(12115),r=n(25668);class i{static getInstance(){return i.instance||(i.instance=new i),i.instance}get(e,t){let n=this.storage.get(e);if(n)return n.get(t)}set(e,t,n){let a=this.storage.get(e);a||(a=new Map,this.storage.set(e,a)),a.set(t,n)}getNamespace(e,t){let n=this.namespaceStorage.get(e);if(n)return n.get(t)}setNamespace(e,t,n){let a=this.namespaceStorage.get(e);a||(a=new Map,this.namespaceStorage.set(e,a)),a.set(t,n)}has(e,t){let n=this.storage.get(e);return!!n&&n.has(t)}hasNamespace(e,t){let n=this.namespaceStorage.get(e);return!!n&&n.has(t)}delete(e,t){let n=this.storage.get(e);return!!n&&n.delete(t)}deleteNamespace(e,t){let n=this.namespaceStorage.get(e);return!!n&&n.delete(t)}clearLocale(e){this.storage.delete(e),this.namespaceStorage.delete(e)}clear(){this.storage.clear(),this.namespaceStorage.clear()}getStats(){let e={},t={},n=0,a=0;for(let[t,a]of this.storage.entries()){let o=a.size;e[t]=o,n+=o}for(let[e,n]of this.namespaceStorage.entries()){let o=n.size;t[e]=o,a+=o}return{totalEntries:n,entriesByLocale:e,totalNamespaces:a,namespacesByLocale:t}}constructor(){this.storage=new Map,this.namespaceStorage=new Map}}function s(e){let{locale:t,children:s,initialTranslations:l}=e,c=t&&"string"==typeof t?t:"en"===window.location.pathname.split("/")[1]||"de"===window.location.pathname.split("/")[1]?window.location.pathname.split("/")[1]:"en";if("string"!=typeof t&&console.warn("TranslationProvider received invalid locale type: ".concat(typeof t,". Using fallback: ").concat(c)),!l||"object"!=typeof l)throw console.error("TranslationProvider received invalid initialTranslations type: ".concat(typeof l,". Expected object.")),Error("TranslationProvider requires an object for initialTranslations, received: ".concat(typeof l));let d=(0,o.useMemo)(()=>{let e={...l};if(Object.keys(l).filter(e=>e.includes(".")).length<10&&Object.keys(l).length>20)try{let{NamespaceProcessor:t}=n(36893),a=new t().flattenObject(l);Object.assign(e,a)}catch(e){console.error("[i18n] Error flattening translations:",e)}return e},[l]),[p,h]=(0,o.useState)(d);(0,o.useEffect)(()=>{i.getInstance(),console.log("[i18n] Using permanent storage for translations (".concat(c,")"))},[c]);let f=(e,t)=>{console.warn('[i18n] Dynamic loading of translations is disabled. Namespace "'.concat(e,'" should be pre-loaded on the server.'))},u=(0,o.useMemo)(()=>({locale:c,translations:p,setNamespaceTranslations:f}),[c,p]);return(0,a.jsx)(r.x.Provider,{value:u,children:s})}function l(e){let{locale:t,href:n,children:o,...r}=e,i=t&&"string"==typeof t?t:"en"===window.location.pathname.split("/")[1]||"de"===window.location.pathname.split("/")[1]?window.location.pathname.split("/")[1]:"en";return"string"!=typeof t&&console.warn("LanguageSwitcherLink received invalid locale type: ".concat(typeof t,". Using fallback: ").concat(i)),(0,a.jsx)("a",{href:"/".concat(i).concat(n),...r,children:o})}function c(e){let{locale:t,translations:n,children:o}=e,r=t&&"string"==typeof t?t:"en"===window.location.pathname.split("/")[1]||"de"===window.location.pathname.split("/")[1]?window.location.pathname.split("/")[1]:"en";if("string"!=typeof t&&console.warn("ClientTranslationProvider received invalid locale type: ".concat(typeof t,". Using fallback: ").concat(r)),!n||"object"!=typeof n)throw console.error("ClientTranslationProvider received invalid translations type: ".concat(typeof n,". Expected object.")),Error("ClientTranslationProvider requires an object for translations, received: ".concat(typeof n));return(0,a.jsx)(s,{locale:r,initialTranslations:n,children:o})}function d(e,t){if(!e)throw Error("withClientTranslations requires a valid component");return Array.isArray(t)&&0!==t.length||console.warn("[i18n] withClientTranslations called with empty or invalid namespaces array"),function(n){let{locale:r,translations:i,...s}=n,l=r&&"string"==typeof r?r:"en"===window.location.pathname.split("/")[1]||"de"===window.location.pathname.split("/")[1]?window.location.pathname.split("/")[1]:"en";r&&"string"==typeof r||console.warn("Component wrapped with withClientTranslations received invalid locale: ".concat(r,". Using fallback: ").concat(l)),i&&"object"==typeof i||(console.error("Component wrapped with withClientTranslations requires a valid translations object"),i={Common:{loading:"Loading...",error:"Error occurred"},Auth:{UserMenu:{account:"Account",login:"Login"}},Home:{hero:{scrollIndicator:"Scroll down",scrollIndicatorMobile:"Scroll"}}},console.warn("[i18n] Using fallback translations due to invalid translations object"));let d=(0,o.useMemo)(()=>{let e={};return t.forEach(t=>{i[t]&&(e[t]=i[t])}),Object.entries(i).forEach(n=>{let[a,o]=n;if(a.includes(".")){let n=a.split(".")[0];t.includes(n)&&(e[a]=o)}}),!t.some(t=>e[t]||Object.keys(e).some(e=>e.startsWith("".concat(t,"."))))&&t.length>0&&(console.warn("[i18n] No translations found for namespaces: ".concat(t.join(", "),". Using fallbacks.")),t.some(e=>e.includes("."))&&console.warn('[i18n] IMPORTANT: It appears you\'re passing key paths (containing dots) as namespaces. The withClientTranslations HOC expects namespace names (e.g., "Common"), not key paths (e.g., "Common.whatsapp"). To fix this issue, pass only the top-level namespace name and then access nested keys in your component.'),t.forEach(t=>{e[t]||("Home"===t?(e[t]={hero:{title:"Photorealistic 3D Cable Modeling",scrollIndicator:"Scroll down",scrollIndicatorMobile:"Scroll"}},e["".concat(t,".hero.scrollIndicator")]="Scroll down",e["".concat(t,".hero.scrollIndicatorMobile")]="Scroll"):"Common"===t?(e[t]={loading:"Loading...",error:"Error occurred"},e["".concat(t,".loading")]="Loading...",e["".concat(t,".error")]="Error occurred"):(e[t]={title:t,description:"".concat(t," content")},e["".concat(t,".title")]=t,e["".concat(t,".description")]="".concat(t," content")))})),e},[i,t]);return(0,a.jsx)(c,{locale:l,translations:d,children:(0,a.jsx)(e,{...s})})}}}}]); |