gt-react 9.2.14-alpha.3 → 9.2.15-alpha.0
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/client.cjs.min.cjs +3 -3
- package/dist/client.d.ts +7 -3
- package/dist/client.esm.min.mjs +3 -3
- package/dist/hooks/internal/useDetermineLocale.d.ts +2 -2
- package/dist/hooks/internal/useDetermineLocale.d.ts.map +1 -1
- package/dist/index.cjs.min.cjs +3 -3
- package/dist/index.esm.min.mjs +3 -3
- package/dist/internal.cjs.min.cjs +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.esm.min.mjs +1 -1
- package/dist/provider/ClientProvider.d.ts +1 -1
- package/dist/provider/ClientProvider.d.ts.map +1 -1
- package/dist/provider/GTProvider.d.ts +4 -1
- package/dist/provider/GTProvider.d.ts.map +1 -1
- package/dist/types/providers.d.ts +2 -1
- package/dist/types/providers.d.ts.map +1 -1
- package/dist/utils/cookies.d.ts +5 -0
- package/dist/utils/cookies.d.ts.map +1 -0
- package/dist/utils/utils.d.ts +0 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
import e,{isValidElement as r}from"react";import"generaltranslation";import{jsx as n}from"react/jsx-runtime";const t=e=>`Duplicate key found in dictionary: "${e}"`;function a(e,r=""){const n={};for(const i in e)if(e.hasOwnProperty(i)){const o=r?`${r}.${i}`:i;if("object"!=typeof e[i]||null===e[i]||Array.isArray(e[i])){if(n.hasOwnProperty(o))throw new Error(t(o));n[o]=e[i]}else{const r=a(e[i],o);for(const e in r){if(n.hasOwnProperty(e))throw new Error(t(e));n[e]=r[e]}}}return n}function i(e,r){var n={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&r.indexOf(t)<0&&(n[t]=e[t]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(t=Object.getOwnPropertySymbols(e);a<t.length;a++)r.indexOf(t[a])<0&&Object.prototype.propertyIsEnumerable.call(e,t[a])&&(n[t[a]]=e[t[a]])}return n}"function"==typeof SuppressedError&&SuppressedError;var o="en",l=["singular","plural","dual","zero","one","two","few","many","other"];var s=new(function(){function e(){this.cache=new Map}return e.prototype._generateKey=function(e,r,n){void 0===n&&(n={});var t=Array.isArray(r)?r.join(","):r,a=n?JSON.stringify(n,Object.keys(n).sort()):"{}";return"".concat(e,":").concat(t,":").concat(a)},e.prototype.get=function(e,r,n){void 0===n&&(n={});var t=this._generateKey(e,r,n);if(!this.cache.has(t)){var a=new Intl[e](r,n);this.cache.set(t,a)}return this.cache.get(t)},e}());function c(n,t=0){let a=t;const o=e=>{const{type:r,props:n}=e;a+=1;let t,o={id:a};try{t="function"==typeof r&&r.gtTransformation||""}catch(e){t=""}if(t){const r=t.split("-");if("translate"===r[0])throw new Error((e=>{var r;return`General Translation: Nested <T> components. The inner <T> has the id: "${null===(r=null==e?void 0:e.props)||void 0===r?void 0:r.id}".`})(e));if("variable"===r[0]&&(o.variableType=(null==r?void 0:r[1])||"variable"),"plural"===r[0]){const e=Object.entries(n).reduce(((e,[r,n])=>{var t;return t=r,l.includes(t)&&(e[r]=c(n,a)),e}),{});Object.keys(e).length&&(o.branches=e)}if("branch"===r[0]){const e=i(n,["children","branch"]),r=Object.entries(e).reduce(((e,[r,n])=>(e[r]=c(n,a),e)),{});Object.keys(r).length&&(o.branches=r)}o.transformation=r[0]}return o};function s(n){return r(n)?function(r){const{props:n}=r;if(n["data-_gt"])throw new Error((e=>`General Translation already in use on child with props: ${e.props}. This usually occurs when you nest <T> components within the same file. Remove one of the <T> components to continue.`)(r));let t=o(r),a=Object.assign(Object.assign({},n),{"data-_gt":t});return n.children&&!t.variableType&&(a.children=u(n.children)),r.type===e.Fragment&&(a["data-_gt"].transformation="fragment"),e.cloneElement(r,a)}(n):n}function u(r){return Array.isArray(r)?e.Children.map(r,s):s(r)}return u(n)}const u={variable:"value",number:"n",datetime:"date",currency:"cost"};function d(e={},r){var n;if(e.name)return e.name;return`_gt_${u[r]||"value"}_${null===(n=e["data-_gt"])||void 0===n?void 0:n.id}`}const p="generaltranslation.middleware.locale-reset";const f=e=>{var r;if(!e)return"";const{type:n,props:t}=e;if(n&&"function"==typeof n){if("displayName"in n&&"string"==typeof n.displayName&&n.displayName)return n.displayName;if("name"in n&&"string"==typeof n.name&&n.name)return n.name}return n&&"string"==typeof n?n:t.href?"a":(null===(r=t["data-_gt"])||void 0===r?void 0:r.id)?`C${t["data-_gt"].id}`:"function"},b=r=>{return n=r,e.isValidElement(n)?(e=>{const{type:r,props:n}=e;let t={type:f(e),props:{}};if(n["data-_gt"]){const e=n["data-_gt"];let r=Object.assign({},e);const a=e.transformation;if("variable"===a){const r=e.variableType||"variable";return{variable:r,key:d(n,r),id:e.id}}if("plural"===a&&e.branches){t.type="Plural";let n={};Object.entries(e.branches).forEach((([e,r])=>{n[e]=h(r)})),r=Object.assign(Object.assign({},r),{branches:n})}if("branch"===a&&e.branches){t.type="Branch";let n={};Object.entries(e.branches).forEach((([e,r])=>{n[e]=h(r)})),r=Object.assign(Object.assign({},r),{branches:n})}t.props["data-_gt"]=r}return n.children&&(t.props.children=h(n.children)),t})(r):"number"==typeof r?r.toString():r;var n};function h(e){return Array.isArray(e)?e.map(b):b(e)}function y(e,r,n){let t="",a=null;return"number"==typeof e&&!a&&n&&(t=function(e,r,n){void 0===r&&(r=l),void 0===n&&(n=["en"]);var t=s.get("PluralRules",n).select(e),a=Math.abs(e);if(0===a&&r.includes("zero"))return"zero";if(1===a){if(r.includes("singular"))return"singular";if(r.includes("one"))return"one"}if("one"===t&&r.includes("singular"))return"singular";if(2===a){if(r.includes("dual"))return"dual";if(r.includes("two"))return"two"}return"two"===t&&r.includes("dual")?"dual":r.includes(t)?t:"two"===t&&r.includes("dual")?"dual":"two"===t&&r.includes("plural")?"plural":"two"===t&&r.includes("other")?"other":"few"===t&&r.includes("plural")?"plural":"few"===t&&r.includes("other")?"other":"many"===t&&r.includes("plural")?"plural":"many"===t&&r.includes("other")?"other":"other"===t&&r.includes("plural")?"plural":""}(e,Object.keys(n),r)),t&&!a&&(a=n[t]),a}function v(e){if("string"==typeof e)return!0;if(Array.isArray(e)){if("string"!=typeof(null==e?void 0:e[0]))return!1;const r=null==e?void 0:e[1];if(void 0===r)return!0;if(r&&"object"==typeof r)return!0}return!1}function g(r,n){let t=r,a=n.split(".");for(const r of a){if("object"!=typeof t||Array.isArray(t)||e.isValidElement(t))return;t=t[r]}return t}function m(e){if(Array.isArray(e)){if(1===e.length)return{entry:e[0]};if(2===e.length)return{entry:e[0],metadata:e[1]}}return{entry:e}}function O(e){var r;const n=(null===(r=e["data-_gt"])||void 0===r?void 0:r.variableType)||"variable";return{variableName:d(e,n),variableType:n,variableValue:void 0!==e.value?e.value:void 0!==e["data-_gt-unformatted-value"]?e["data-_gt-unformatted-value"]:void 0!==e.children?e.children:void 0,variableOptions:(()=>{const r=Object.assign(Object.assign({},e.currency&&{currency:e.currency}),e.options&&Object.assign({},e.options));return Object.keys(r).length?r:"string"==typeof e["data-_gt-variable-options"]?JSON.parse(e["data-_gt-variable-options"]):e["data-_gt-variable-options"]||void 0})()}}function j(e){const r=e;if(r&&"object"==typeof r&&"string"==typeof r.key){const e=Object.keys(r);if(1===e.length)return!0;if(2===e.length){if("number"==typeof r.id)return!0;if("string"==typeof r.variable)return!0}if(3===e.length&&"string"==typeof r.variable&&"number"==typeof r.id)return!0}return!1}function _(e){return e&&e.props&&e.props["data-_gt"]?e.props["data-_gt"]:null}function w({children:r,defaultLocale:n=o,renderVariable:t}){const a=r=>e.isValidElement(r)?(r=>{const a=_(r);if("variable"===(null==a?void 0:a.transformation)){const{variableType:e,variableValue:a,variableOptions:i}=O(r.props);return t({variableType:e,variableValue:a,variableOptions:i,locales:[n]})}if("plural"===(null==a?void 0:a.transformation)){const e=a.branches||{};return l(y(r.props.n,[n],e)||r.props.children)}if("branch"===(null==a?void 0:a.transformation)){let e=r.props,{children:n,name:t,branch:o,"data-_gt":s}=e,c=i(e,["children","name","branch","data-_gt"]);return t=t||r.props["data-_gt-name"]||"branch",c=a.branches||{},l(void 0!==c[o]?c[o]:n)}return"fragment"===(null==a?void 0:a.transformation)?e.createElement(r.type,{key:r.props.key,children:l(r.props.children)}):r.props.children?e.cloneElement(r,Object.assign(Object.assign({},r.props),{"data-_gt":void 0,children:l(r.props.children)})):e.cloneElement(r,Object.assign(Object.assign({},r.props),{"data-_gt":void 0}))})(r):r,l=r=>Array.isArray(r)?e.Children.map(r,a):a(r);return l(r)}function E({sourceElement:r,targetElement:n,locales:t=[o],renderVariable:a}){var i,l;const{props:s}=r,c=s["data-_gt"],u=null==c?void 0:c.transformation;if("plural"===u){const e=r.props.n;return A({source:y(e,t,c.branches||{})||r.props.children,target:y(e,t,n.props["data-_gt"].branches||{})||n.props.children,locales:t,renderVariable:a})}if("branch"===u){let{name:e,branch:i,children:o}=s;e=e||r.props["data-_gt-name"]||"branch";return A({source:(c.branches||{})[i]||o,target:(n.props["data-_gt"].branches||{})[i]||n.props.children,locales:t,renderVariable:a})}return"fragment"===u&&(null===(i=n.props)||void 0===i?void 0:i.children)?e.createElement(r.type,{key:r.props.key,children:A({source:s.children,target:n.props.children,locales:t,renderVariable:a})}):(null==s?void 0:s.children)&&(null===(l=n.props)||void 0===l?void 0:l.children)?e.cloneElement(r,Object.assign(Object.assign({},s),{"data-_gt":void 0,children:A({source:s.children,target:n.props.children,locales:t,renderVariable:a})})):w({children:r,defaultLocale:t[0],renderVariable:a})}function A({source:r,target:t,locales:a=[o],renderVariable:i}){if(null==t&&r)return w({children:r,defaultLocale:a[0],renderVariable:i});if("string"==typeof t)return t;if(Array.isArray(t)&&!Array.isArray(r)&&r&&(r=[r]),Array.isArray(r)&&Array.isArray(t)){const o={},l={},s=r.filter((r=>{if(e.isValidElement(r)){const e=_(r);if("variable"!==(null==e?void 0:e.transformation))return!0;{let{variableName:e,variableValue:n,variableOptions:t}=O(r.props);o[e]=n,l[e]=t}}})),c=e=>s.find((r=>{var n,t;const a=_(r);if(void 0!==(null==a?void 0:a.id)){return a.id===(null===(t=null===(n=null==e?void 0:e.props)||void 0===n?void 0:n["data-_gt"])||void 0===t?void 0:t.id)}return!1}))||s.shift();return t.map(((r,t)=>{if("string"==typeof r)return n(e.Fragment,{children:r},`string_${t}`);if(j(r))return n(e.Fragment,{children:i({variableType:r.variable||"variable",variableValue:o[r.key],variableOptions:l[r.key],locales:a})},`var_${t}`);const s=c(r);return s?n(e.Fragment,{children:E({sourceElement:s,targetElement:r,locales:a,renderVariable:i})},`element_${t}`):void 0}))}if(t&&"object"==typeof t&&!Array.isArray(t)){const n=j(t)?"variable":"element";if(e.isValidElement(r)){if("element"===n)return E({sourceElement:r,targetElement:t,locales:a,renderVariable:i});const e=_(r);if("variable"===(null==e?void 0:e.transformation)){const{variableValue:e,variableOptions:n,variableType:t}=O(r.props);return i({variableType:t,variableValue:e,variableOptions:n,locales:a})}}}return w({children:r,defaultLocale:a[0],renderVariable:i})}const V={method:"default",timeout:"undefined"!=typeof process&&"development"!==process.env.NODE_ENV?8e3:12e3};function T(){return""}class k extends Error{constructor(e,r){super(e),this.error=e,this.code=r,this.code=r}toTranslationError(){return{state:"error",error:this.error,code:this.code}}}export{k as GTTranslationError,c as addGTIdentifier,V as defaultRenderSettings,a as flattenDictionary,g as getDictionaryEntry,m as getEntryAndMetadata,y as getPluralBranch,d as getVariableName,O as getVariableProps,v as isValidDictionaryEntry,j as isVariableObject,p as middlewareLocaleResetFlagName,w as renderDefaultChildren,T as renderSkeleton,A as renderTranslatedChildren,h as writeChildrenAsObjects};
|
1
|
+
import e,{isValidElement as r}from"react";import"generaltranslation";import{jsx as n}from"react/jsx-runtime";const t=e=>`Duplicate key found in dictionary: "${e}"`;function a(e,r=""){const n={};for(const i in e)if(e.hasOwnProperty(i)){const o=r?`${r}.${i}`:i;if("object"!=typeof e[i]||null===e[i]||Array.isArray(e[i])){if(n.hasOwnProperty(o))throw new Error(t(o));n[o]=e[i]}else{const r=a(e[i],o);for(const e in r){if(n.hasOwnProperty(e))throw new Error(t(e));n[e]=r[e]}}}return n}function i(e,r){var n={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&r.indexOf(t)<0&&(n[t]=e[t]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(t=Object.getOwnPropertySymbols(e);a<t.length;a++)r.indexOf(t[a])<0&&Object.prototype.propertyIsEnumerable.call(e,t[a])&&(n[t[a]]=e[t[a]])}return n}"function"==typeof SuppressedError&&SuppressedError;var o="en",l=["singular","plural","dual","zero","one","two","few","many","other"];var s=new(function(){function e(){this.cache=new Map}return e.prototype._generateKey=function(e,r,n){void 0===n&&(n={});var t=Array.isArray(r)?r.join(","):r,a=n?JSON.stringify(n,Object.keys(n).sort()):"{}";return"".concat(e,":").concat(t,":").concat(a)},e.prototype.get=function(e,r,n){void 0===n&&(n={});var t=this._generateKey(e,r,n);if(!this.cache.has(t)){var a=new Intl[e](r,n);this.cache.set(t,a)}return this.cache.get(t)},e}());function c(n,t=0){let a=t;const o=e=>{const{type:r,props:n}=e;a+=1;let t,o={id:a};try{t="function"==typeof r&&r.gtTransformation||""}catch(e){t=""}if(t){const r=t.split("-");if("translate"===r[0])throw new Error((e=>{var r;return`General Translation: Nested <T> components. The inner <T> has the id: "${null===(r=null==e?void 0:e.props)||void 0===r?void 0:r.id}".`})(e));if("variable"===r[0]&&(o.variableType=(null==r?void 0:r[1])||"variable"),"plural"===r[0]){const e=Object.entries(n).reduce(((e,[r,n])=>{var t;return t=r,l.includes(t)&&(e[r]=c(n,a)),e}),{});Object.keys(e).length&&(o.branches=e)}if("branch"===r[0]){const e=i(n,["children","branch"]),r=Object.entries(e).reduce(((e,[r,n])=>(e[r]=c(n,a),e)),{});Object.keys(r).length&&(o.branches=r)}o.transformation=r[0]}return o};function s(n){return r(n)?function(r){const{props:n}=r;if(n["data-_gt"])throw new Error((e=>`General Translation already in use on child with props: ${e.props}. This usually occurs when you nest <T> components within the same file. Remove one of the <T> components to continue.`)(r));let t=o(r),a=Object.assign(Object.assign({},n),{"data-_gt":t});return n.children&&!t.variableType&&(a.children=u(n.children)),r.type===e.Fragment&&(a["data-_gt"].transformation="fragment"),e.cloneElement(r,a)}(n):n}function u(r){return Array.isArray(r)?e.Children.map(r,s):s(r)}return u(n)}const u={variable:"value",number:"n",datetime:"date",currency:"cost"};function d(e={},r){var n;if(e.name)return e.name;return`_gt_${u[r]||"value"}_${null===(n=e["data-_gt"])||void 0===n?void 0:n.id}`}const p=e=>{var r;if(!e)return"";const{type:n,props:t}=e;if(n&&"function"==typeof n){if("displayName"in n&&"string"==typeof n.displayName&&n.displayName)return n.displayName;if("name"in n&&"string"==typeof n.name&&n.name)return n.name}return n&&"string"==typeof n?n:t.href?"a":(null===(r=t["data-_gt"])||void 0===r?void 0:r.id)?`C${t["data-_gt"].id}`:"function"},f=r=>{return n=r,e.isValidElement(n)?(e=>{const{type:r,props:n}=e;let t={type:p(e),props:{}};if(n["data-_gt"]){const e=n["data-_gt"];let r=Object.assign({},e);const a=e.transformation;if("variable"===a){const r=e.variableType||"variable";return{variable:r,key:d(n,r),id:e.id}}if("plural"===a&&e.branches){t.type="Plural";let n={};Object.entries(e.branches).forEach((([e,r])=>{n[e]=b(r)})),r=Object.assign(Object.assign({},r),{branches:n})}if("branch"===a&&e.branches){t.type="Branch";let n={};Object.entries(e.branches).forEach((([e,r])=>{n[e]=b(r)})),r=Object.assign(Object.assign({},r),{branches:n})}t.props["data-_gt"]=r}return n.children&&(t.props.children=b(n.children)),t})(r):"number"==typeof r?r.toString():r;var n};function b(e){return Array.isArray(e)?e.map(f):f(e)}function h(e,r,n){let t="",a=null;return"number"==typeof e&&!a&&n&&(t=function(e,r,n){void 0===r&&(r=l),void 0===n&&(n=["en"]);var t=s.get("PluralRules",n).select(e),a=Math.abs(e);if(0===a&&r.includes("zero"))return"zero";if(1===a){if(r.includes("singular"))return"singular";if(r.includes("one"))return"one"}if("one"===t&&r.includes("singular"))return"singular";if(2===a){if(r.includes("dual"))return"dual";if(r.includes("two"))return"two"}return"two"===t&&r.includes("dual")?"dual":r.includes(t)?t:"two"===t&&r.includes("dual")?"dual":"two"===t&&r.includes("plural")?"plural":"two"===t&&r.includes("other")?"other":"few"===t&&r.includes("plural")?"plural":"few"===t&&r.includes("other")?"other":"many"===t&&r.includes("plural")?"plural":"many"===t&&r.includes("other")?"other":"other"===t&&r.includes("plural")?"plural":""}(e,Object.keys(n),r)),t&&!a&&(a=n[t]),a}function y(e){if("string"==typeof e)return!0;if(Array.isArray(e)){if("string"!=typeof(null==e?void 0:e[0]))return!1;const r=null==e?void 0:e[1];if(void 0===r)return!0;if(r&&"object"==typeof r)return!0}return!1}function v(r,n){let t=r,a=n.split(".");for(const r of a){if("object"!=typeof t||Array.isArray(t)||e.isValidElement(t))return;t=t[r]}return t}function g(e){if(Array.isArray(e)){if(1===e.length)return{entry:e[0]};if(2===e.length)return{entry:e[0],metadata:e[1]}}return{entry:e}}function m(e){var r;const n=(null===(r=e["data-_gt"])||void 0===r?void 0:r.variableType)||"variable";return{variableName:d(e,n),variableType:n,variableValue:void 0!==e.value?e.value:void 0!==e["data-_gt-unformatted-value"]?e["data-_gt-unformatted-value"]:void 0!==e.children?e.children:void 0,variableOptions:(()=>{const r=Object.assign(Object.assign({},e.currency&&{currency:e.currency}),e.options&&Object.assign({},e.options));return Object.keys(r).length?r:"string"==typeof e["data-_gt-variable-options"]?JSON.parse(e["data-_gt-variable-options"]):e["data-_gt-variable-options"]||void 0})()}}function O(e){const r=e;if(r&&"object"==typeof r&&"string"==typeof r.key){const e=Object.keys(r);if(1===e.length)return!0;if(2===e.length){if("number"==typeof r.id)return!0;if("string"==typeof r.variable)return!0}if(3===e.length&&"string"==typeof r.variable&&"number"==typeof r.id)return!0}return!1}function j(e){return e&&e.props&&e.props["data-_gt"]?e.props["data-_gt"]:null}function _({children:r,defaultLocale:n=o,renderVariable:t}){const a=r=>e.isValidElement(r)?(r=>{const a=j(r);if("variable"===(null==a?void 0:a.transformation)){const{variableType:e,variableValue:a,variableOptions:i}=m(r.props);return t({variableType:e,variableValue:a,variableOptions:i,locales:[n]})}if("plural"===(null==a?void 0:a.transformation)){const e=a.branches||{};return l(h(r.props.n,[n],e)||r.props.children)}if("branch"===(null==a?void 0:a.transformation)){let e=r.props,{children:n,name:t,branch:o,"data-_gt":s}=e,c=i(e,["children","name","branch","data-_gt"]);return t=t||r.props["data-_gt-name"]||"branch",c=a.branches||{},l(void 0!==c[o]?c[o]:n)}return"fragment"===(null==a?void 0:a.transformation)?e.createElement(r.type,{key:r.props.key,children:l(r.props.children)}):r.props.children?e.cloneElement(r,Object.assign(Object.assign({},r.props),{"data-_gt":void 0,children:l(r.props.children)})):e.cloneElement(r,Object.assign(Object.assign({},r.props),{"data-_gt":void 0}))})(r):r,l=r=>Array.isArray(r)?e.Children.map(r,a):a(r);return l(r)}function w({sourceElement:r,targetElement:n,locales:t=[o],renderVariable:a}){var i,l;const{props:s}=r,c=s["data-_gt"],u=null==c?void 0:c.transformation;if("plural"===u){const e=r.props.n;return E({source:h(e,t,c.branches||{})||r.props.children,target:h(e,t,n.props["data-_gt"].branches||{})||n.props.children,locales:t,renderVariable:a})}if("branch"===u){let{name:e,branch:i,children:o}=s;e=e||r.props["data-_gt-name"]||"branch";return E({source:(c.branches||{})[i]||o,target:(n.props["data-_gt"].branches||{})[i]||n.props.children,locales:t,renderVariable:a})}return"fragment"===u&&(null===(i=n.props)||void 0===i?void 0:i.children)?e.createElement(r.type,{key:r.props.key,children:E({source:s.children,target:n.props.children,locales:t,renderVariable:a})}):(null==s?void 0:s.children)&&(null===(l=n.props)||void 0===l?void 0:l.children)?e.cloneElement(r,Object.assign(Object.assign({},s),{"data-_gt":void 0,children:E({source:s.children,target:n.props.children,locales:t,renderVariable:a})})):_({children:r,defaultLocale:t[0],renderVariable:a})}function E({source:r,target:t,locales:a=[o],renderVariable:i}){if(null==t&&r)return _({children:r,defaultLocale:a[0],renderVariable:i});if("string"==typeof t)return t;if(Array.isArray(t)&&!Array.isArray(r)&&r&&(r=[r]),Array.isArray(r)&&Array.isArray(t)){const o={},l={},s=r.filter((r=>{if(e.isValidElement(r)){const e=j(r);if("variable"!==(null==e?void 0:e.transformation))return!0;{let{variableName:e,variableValue:n,variableOptions:t}=m(r.props);o[e]=n,l[e]=t}}})),c=e=>s.find((r=>{var n,t;const a=j(r);if(void 0!==(null==a?void 0:a.id)){return a.id===(null===(t=null===(n=null==e?void 0:e.props)||void 0===n?void 0:n["data-_gt"])||void 0===t?void 0:t.id)}return!1}))||s.shift();return t.map(((r,t)=>{if("string"==typeof r)return n(e.Fragment,{children:r},`string_${t}`);if(O(r))return n(e.Fragment,{children:i({variableType:r.variable||"variable",variableValue:o[r.key],variableOptions:l[r.key],locales:a})},`var_${t}`);const s=c(r);return s?n(e.Fragment,{children:w({sourceElement:s,targetElement:r,locales:a,renderVariable:i})},`element_${t}`):void 0}))}if(t&&"object"==typeof t&&!Array.isArray(t)){const n=O(t)?"variable":"element";if(e.isValidElement(r)){if("element"===n)return w({sourceElement:r,targetElement:t,locales:a,renderVariable:i});const e=j(r);if("variable"===(null==e?void 0:e.transformation)){const{variableValue:e,variableOptions:n,variableType:t}=m(r.props);return i({variableType:t,variableValue:e,variableOptions:n,locales:a})}}}return _({children:r,defaultLocale:a[0],renderVariable:i})}const A={method:"default",timeout:"undefined"!=typeof process&&"development"!==process.env.NODE_ENV?8e3:12e3};function V(){return""}class T extends Error{constructor(e,r){super(e),this.error=e,this.code=r,this.code=r}toTranslationError(){return{state:"error",error:this.error,code:this.code}}}const k="generaltranslation.locale";export{T as GTTranslationError,c as addGTIdentifier,k as defaultLocaleCookieName,A as defaultRenderSettings,a as flattenDictionary,v as getDictionaryEntry,g as getEntryAndMetadata,h as getPluralBranch,d as getVariableName,m as getVariableProps,y as isValidDictionaryEntry,O as isVariableObject,_ as renderDefaultChildren,V as renderSkeleton,E as renderTranslatedChildren,b as writeChildrenAsObjects};
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { ClientProviderProps } from '../types/providers';
|
3
|
-
export default function ClientProvider({ children, dictionary, initialTranslations, dictionaryTranslations, locale: _locale, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, runtimeTranslationEnabled,
|
3
|
+
export default function ClientProvider({ children, dictionary, initialTranslations, dictionaryTranslations, locale: _locale, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, runtimeTranslationEnabled, resetLocaleCookieName, localeCookieName, }: ClientProviderProps): React.JSX.Element;
|
4
4
|
//# sourceMappingURL=ClientProvider.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ClientProvider.d.ts","sourceRoot":"","sources":["../../src/provider/ClientProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
1
|
+
{"version":3,"file":"ClientProvider.d.ts","sourceRoot":"","sources":["../../src/provider/ClientProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAQzD,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACrC,QAAQ,EACR,UAAU,EACV,mBAAmB,EACnB,sBAAsB,EACtB,MAAM,EAAE,OAAO,EACf,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,0BAA0B,EAC1B,OAAY,EACZ,cAAc,EACd,SAAS,EACT,SAAS,EACT,UAAU,EACV,yBAAyB,EACzB,qBAAqB,EACrB,gBAA0C,GAC3C,EAAE,mBAAmB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAgIzC"}
|
@@ -15,11 +15,13 @@ import { CustomLoader, RenderMethod } from '../types/types';
|
|
15
15
|
* @param {string} [_versionId] - The version ID for fetching translations.
|
16
16
|
* @param {string} [devApiKey] - The API key for development environments.
|
17
17
|
* @param {object} [metadata] - Additional metadata to pass to the context.
|
18
|
+
* @param {boolean} [ssr=isSSREnabled()] - Whether to enable server-side rendering.
|
19
|
+
* @param {string} [localeCookieName=defaultLocaleCookieName] - The name of the cookie to store the locale.
|
18
20
|
* @param {React.ReactNode} [fallback = undefined] - Custom fallback to display while loading
|
19
21
|
*
|
20
22
|
* @returns {JSX.Element} The provider component for General Translation context.
|
21
23
|
*/
|
22
|
-
export default function GTProvider({ children, projectId: _projectId, devApiKey: _devApiKey, dictionary: _dictionary, locales, defaultLocale, locale: _locale, cacheUrl, runtimeUrl, renderSettings, loadDictionary, loadTranslations, fallback, ssr, _versionId, ...metadata }: {
|
24
|
+
export default function GTProvider({ children, projectId: _projectId, devApiKey: _devApiKey, dictionary: _dictionary, locales, defaultLocale, locale: _locale, cacheUrl, runtimeUrl, renderSettings, loadDictionary, loadTranslations, fallback, ssr, localeCookieName, _versionId, ...metadata }: {
|
23
25
|
children?: React.ReactNode;
|
24
26
|
projectId?: string;
|
25
27
|
devApiKey?: string;
|
@@ -37,6 +39,7 @@ export default function GTProvider({ children, projectId: _projectId, devApiKey:
|
|
37
39
|
loadTranslations?: CustomLoader;
|
38
40
|
_versionId?: string;
|
39
41
|
ssr?: boolean;
|
42
|
+
localeCookieName?: string;
|
40
43
|
[key: string]: any;
|
41
44
|
}): React.JSX.Element;
|
42
45
|
//# sourceMappingURL=GTProvider.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"GTProvider.d.ts","sourceRoot":"","sources":["../../src/provider/GTProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAO5D,OAAO,EACL,YAAY,EAGZ,YAAY,EAEb,MAAM,gBAAgB,CAAC;
|
1
|
+
{"version":3,"file":"GTProvider.d.ts","sourceRoot":"","sources":["../../src/provider/GTProvider.tsx"],"names":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ClientProviderProps = {
|
|
40
40
|
projectId?: string;
|
41
41
|
devApiKey?: string;
|
42
42
|
runtimeUrl?: string | null;
|
43
|
-
cookieName?: string;
|
44
43
|
gtServicesEnabled?: boolean;
|
44
|
+
localeCookieName?: string;
|
45
|
+
resetLocaleCookieName: string;
|
45
46
|
};
|
46
47
|
//# sourceMappingURL=providers.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/types/providers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,wBAAwB,EACxB,4BAA4B,EAC5B,UAAU,EACV,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAEhF,MAAM,MAAM,aAAa,GAAG;IAC1B,6BAA6B,EAAE,wBAAwB,CAAC;IACxD,yBAAyB,EAAE,yBAAyB,CAAC;IACrD,sBAAsB,EAAE,CACtB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,wBAAwB,KAC/B,MAAM,CAAC;IACZ,wBAAwB,EAAE,CACxB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,4BAA4B,KACnC,MAAM,CAAC;IACZ,yBAAyB,EAAE,OAAO,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,sBAAsB,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAChD,mBAAmB,EAAE,OAAO,CAAC;IAC7B,0BAA0B,EAAE,OAAO,CAAC;IACpC,cAAc,EAAE;QAAE,MAAM,EAAE,YAAY,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,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MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;CAC/B,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/utils/cookies.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,uBAAuB,8BAA8B,CAAC"}
|
package/dist/utils/utils.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import { TaggedElement } from '../types/types';
|
2
|
-
export declare const middlewareLocaleResetFlagName = "generaltranslation.middleware.locale-reset";
|
3
2
|
export declare function isValidTaggedElement(target: unknown): target is TaggedElement;
|
4
3
|
export declare function readAuthFromEnv(projectId?: string, devApiKey?: string): {
|
5
4
|
projectId: string;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAsB,MAAM,gBAAgB,CAAC;AAEnE,
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAsB,MAAM,gBAAgB,CAAC;AAEnE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,aAAa,CAE7E;AAED,wBAAgB,eAAe,CAC7B,SAAS,CAAC,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,MAAM,GACjB;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CA2CA"}
|