dgz-ui-shared
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library
2 lines (1 loc) • 3.96 kB
JavaScript
;const d=require("react"),k=(e,s,n,a)=>{var t,f,h,m;const r=[n,{code:s,...a||{}}];if((f=(t=e==null?void 0:e.services)==null?void 0:t.logger)!=null&&f.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);N(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),(m=(h=e==null?void 0:e.services)==null?void 0:h.logger)!=null&&m.warn?e.services.logger.warn(...r):console!=null&&console.warn&&console.warn(...r)},F={},x=(e,s,n,a)=>{N(n)&&F[n]||(N(n)&&(F[n]=new Date),k(e,s,n,a))},A=(e,s)=>()=>{if(e.isInitialized)s();else{const n=()=>{setTimeout(()=>{e.off("initialized",n)},0),s()};e.on("initialized",n)}},S=(e,s,n)=>{e.loadNamespaces(s,A(e,n))},L=(e,s,n,a)=>{if(N(n)&&(n=[n]),e.options.preload&&e.options.preload.indexOf(s)>-1)return S(e,n,a);n.forEach(r=>{e.options.ns.indexOf(r)<0&&e.options.ns.push(r)}),e.loadLanguages(s,A(e,a))},H=(e,s,n={})=>!s.languages||!s.languages.length?(x(s,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:s.languages}),!0):s.hasLoadedNamespace(e,{lng:n.lng,precheck:(a,r)=>{var t;if(((t=n.bindI18n)==null?void 0:t.indexOf("languageChanging"))>-1&&a.services.backendConnector.backend&&a.isLanguageChangingTo&&!r(a.isLanguageChangingTo,e))return!1}}),N=e=>typeof e=="string",M=e=>typeof e=="object"&&e!==null,U=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,_={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},$=e=>_[e],q=e=>e.replace(U,$);let G={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:q};const B=()=>G;let W;const J=()=>W,K=d.createContext();class X{constructor(){this.usedNamespaces={}}addUsedNamespaces(s){s.forEach(n=>{this.usedNamespaces[n]||(this.usedNamespaces[n]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const Y=(e,s)=>{const n=d.useRef();return d.useEffect(()=>{n.current=e},[e,s]),n.current},P=(e,s,n,a)=>e.getFixedT(s,n,a),D=(e,s,n,a)=>d.useCallback(P(e,s,n,a),[e,s,n,a]),Q=(e,s={})=>{var O,R,v,z;const{i18n:n}=s,{i18n:a,defaultNS:r}=d.useContext(K)||{},t=n||a||J();if(t&&!t.reportNamespaces&&(t.reportNamespaces=new X),!t){x(t,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const i=(u,l)=>N(l)?l:M(l)&&N(l.defaultValue)?l.defaultValue:Array.isArray(u)?u[u.length-1]:u,c=[i,{},!1];return c.t=i,c.i18n={},c.ready=!1,c}(O=t.options.react)!=null&&O.wait&&x(t,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const f={...B(),...t.options.react,...s},{useSuspense:h,keyPrefix:m}=f;let o=r||((R=t.options)==null?void 0:R.defaultNS);o=N(o)?[o]:o||["translation"],(z=(v=t.reportNamespaces).addUsedNamespaces)==null||z.call(v,o);const g=(t.isInitialized||t.initializedStoreOnce)&&o.every(i=>H(i,t,f)),j=D(t,s.lng||null,f.nsMode==="fallback"?o:o[0],m),b=()=>j,E=()=>P(t,s.lng||null,f.nsMode==="fallback"?o:o[0],m),[C,y]=d.useState(b);let w=o.join();s.lng&&(w=`${s.lng}${w}`);const I=Y(w),p=d.useRef(!0);d.useEffect(()=>{const{bindI18n:i,bindI18nStore:c}=f;p.current=!0,!g&&!h&&(s.lng?L(t,s.lng,o,()=>{p.current&&y(E)}):S(t,o,()=>{p.current&&y(E)})),g&&I&&I!==w&&p.current&&y(E);const u=()=>{p.current&&y(E)};return i&&(t==null||t.on(i,u)),c&&(t==null||t.store.on(c,u)),()=>{p.current=!1,t&&(i==null||i.split(" ").forEach(l=>t.off(l,u))),c&&t&&c.split(" ").forEach(l=>t.store.off(l,u))}},[t,w]),d.useEffect(()=>{p.current&&g&&y(b)},[t,m,g]);const T=[C,t,g];if(T.t=C,T.i18n=t,T.ready=g,g||!g&&!h)return T;throw new Promise(i=>{s.lng?L(t,s.lng,o,()=>i()):S(t,o,()=>i())})};exports.useTranslation=Q;