gt-react 10.0.0-alpha.15 → 10.0.0-alpha.17
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/CHANGELOG.md +12 -0
- package/LICENSE.md +1 -1
- package/dist/client.cjs.min.cjs +3 -3
- package/dist/client.d.ts +14 -10
- package/dist/client.esm.min.mjs +3 -3
- package/dist/hooks/useLocaleSelector.d.ts +10 -1
- package/dist/hooks/useLocaleSelector.d.ts.map +1 -1
- package/dist/index.cjs.min.cjs +2 -2
- package/dist/index.esm.min.mjs +3 -3
- package/dist/internal/addGTIdentifier.d.ts.map +1 -1
- package/dist/internal/writeChildrenAsObjects.d.ts +1 -0
- package/dist/internal/writeChildrenAsObjects.d.ts.map +1 -1
- package/dist/internal.cjs.min.cjs +1 -1
- package/dist/internal.esm.min.mjs +1 -1
- package/dist/rendering/renderTranslatedChildren.d.ts.map +1 -1
- package/dist/types/types.d.ts +10 -8
- package/dist/types/types.d.ts.map +1 -1
- package/dist/ui/LocaleSelector.d.ts.map +1 -1
- package/dist/variables/_getVariableProps.d.ts +2 -3
- package/dist/variables/_getVariableProps.d.ts.map +1 -1
- package/package.json +3 -3
@@ -1 +1 @@
|
|
1
|
-
"use strict";var e=require("react");require("generaltranslation");var r=require("react/jsx-runtime");const t=e=>`Duplicate key found in dictionary: "${e}"`;function n(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)r.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(t[n[a]]=e[n[a]])}return t}"function"==typeof SuppressedError&&SuppressedError;var a="en",i=["singular","plural","dual","zero","one","two","few","many","other"];var o=new(function(){function e(){this.cache=new Map}return e.prototype._generateKey=function(e,r,t){void 0===t&&(t={});var n=Array.isArray(r)?r.join(","):r,a=t?JSON.stringify(t,Object.keys(t).sort()):"{}";return"".concat(e,":").concat(n,":").concat(a)},e.prototype.get=function(e,r,t){void 0===t&&(t={});var n=this._generateKey(e,r,t);if(!this.cache.has(n)){var a=new Intl[e](r,t);this.cache.set(n,a)}return this.cache.get(n)},e}());function l(e){var r=e;if(r&&"object"==typeof r&&"string"==typeof r.k){var t=Object.keys(r);if(1===t.length)return!0;if(2===t.length){if("number"==typeof r.i)return!0;if("string"==typeof r.v)return!0}if(3===t.length&&"string"==typeof r.v&&"number"==typeof r.i)return!0}return!1}const s={variable:"value",number:"n",datetime:"date",currency:"cost"};function c(e={},r){var t;if(e.name)return e.name;return`_gt_${s[r]||"value"}_${null===(t=e["data-_gt"])||void 0===t?void 0:t.id}`}var u={pl:"placeholder",ti:"title",alt:"alt",arl:"aria-label",arb:"aria-labelledby",ard:"aria-describedby"},d={variable:"v",number:"n",datetime:"d",currency:"c"},p={v:"variable",n:"number",d:"datetime",c:"currency"};const f=e=>{var r;if(!e)return"";const{type:t,props:n}=e;if(t&&"function"==typeof t){if("displayName"in t&&"string"==typeof t.displayName&&t.displayName)return t.displayName;if("name"in t&&"string"==typeof t.name&&t.name)return t.name}return t&&"string"==typeof t?t:n.href?"a":(null===(r=n["data-_gt"])||void 0===r?void 0:r.id)?`C${n["data-_gt"].id}`:"function"},b=r=>{return t=r,e.isValidElement(t)?(e=>{const{type:r,props:t}=e,n={type:f(e),props:{}};if(t["data-_gt"]){const e=t["data-_gt"];let r=Object.assign({},e);Object.entries(u).forEach((([e,n])=>{t[n]&&(r[e]=t[n])}));const a=e.t;if("variable"===a){const r=d[e.variableType||"variable"];return{v:r,k:c(t,r),i:e.id}}if("plural"===a&&e.b){n.type="Plural";const t={};Object.entries(e.b).forEach((([e,r])=>{t[e]=y(r)})),r=Object.assign(Object.assign({},r),{b:t})}if("branch"===a&&e.b){n.type="Branch";const t={};Object.entries(e.b).forEach((([e,r])=>{t[e]=y(r)})),r=Object.assign(Object.assign({},r),{b:t})}n.props["data-_gt"]=r}return t.children&&(n.props.children=y(t.children)),n})(r):"number"==typeof r?r.toString():r;var t};function y(e){return Array.isArray(e)?e.map(b):b(e)}function v(e,r,t){let n="",a=null;return"number"==typeof e&&!a&&t&&(n=function(e,r,t){void 0===r&&(r=i),void 0===t&&(t=["en"]);var n=o.get("PluralRules",t).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"===n&&r.includes("singular"))return"singular";if(2===a){if(r.includes("dual"))return"dual";if(r.includes("two"))return"two"}return"two"===n&&r.includes("dual")?"dual":r.includes(n)?n:"two"===n&&r.includes("dual")?"dual":"two"===n&&r.includes("plural")?"plural":"two"===n&&r.includes("other")?"other":"few"===n&&r.includes("plural")?"plural":"few"===n&&r.includes("other")?"other":"many"===n&&r.includes("plural")?"plural":"many"===n&&r.includes("other")?"other":"other"===n&&r.includes("plural")?"plural":""}(e,Object.keys(t),r)),n&&!a&&(a=t[n]),a}function g(e){var r;return"object"==typeof e&&!!e&&"data-_gt"in e&&"object"==typeof e["data-_gt"]&&!!e["data-_gt"]&&"transformation"in e["data-_gt"]&&"variable"===(null===(r=e["data-_gt"])||void 0===r?void 0:r.transformation)}function h(e){var r;const t=(null===(r=e["data-_gt"])||void 0===r?void 0:r.variableType)||"variable";return{variableName:c(e,t),variableType:t,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({},void 0!==e.currency&&{currency:e.currency}),void 0!==e.options&&{options: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 m(e){return e&&e.props&&e.props["data-_gt"]?e.props["data-_gt"]:null}function O({children:r,defaultLocale:t=a,renderVariable:i}){const o=r=>e.isValidElement(r)?(r=>{const a=m(r);if(g(r.props)){const{variableType:e,variableValue:n,variableOptions:a}=h(r.props);return i({variableType:e,variableValue:n,variableOptions:a,locales:[t]})}if("plural"===(null==a?void 0:a.transformation)){const e=a.branches||{};return l(v(r.props.n,[t],e)||r.props.children)}if("branch"===(null==a?void 0:a.transformation)){let e=r.props,{children:t,name:i,branch:o,"data-_gt":s}=e,c=n(e,["children","name","branch","data-_gt"]);return c=a.branches||{},l(void 0!==c[o]?c[o]:t)}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,o):o(r);return l(r)}function j({sourceElement:r,targetElement:t,locales:n=[a],renderVariable:i}){var o,l;const{props:s}=r,{props:c}=t,d=s["data-_gt"],p=null==d?void 0:d.t,f=c["data-_gt"],b={};if(f&&Object.entries(u).forEach((([e,r])=>{f[e]&&(b[r]=f[e])})),"plural"===p){const e=r.props.n;return _({source:v(e,n,d.b||{})||r.props.children,target:v(e,n,t.props["data-_gt"].b||{})||t.props.children,locales:n,renderVariable:i})}if("branch"===p){const{branch:e,children:r}=s;return _({source:(d.b||{})[e]||r,target:(t.props["data-_gt"].b||{})[e]||t.props.children,locales:n,renderVariable:i})}return"fragment"===p&&(null===(o=t.props)||void 0===o?void 0:o.children)?e.createElement(r.type,{key:r.props.key,children:_({source:s.children,target:t.props.children,locales:n,renderVariable:i})}):(null==s?void 0:s.children)&&(null===(l=t.props)||void 0===l?void 0:l.children)?e.cloneElement(r,Object.assign(Object.assign(Object.assign({},s),b),{"data-_gt":void 0,children:_({source:s.children,target:t.props.children,locales:n,renderVariable:i})})):O({children:r,defaultLocale:n[0],renderVariable:i})}function _({source:t,target:n,locales:i=[a],renderVariable:o}){if(null==n&&t)return O({children:t,defaultLocale:i[0],renderVariable:o});if("string"==typeof n)return n;if(Array.isArray(n)&&!Array.isArray(t)&&t&&(t=[t]),Array.isArray(t)&&Array.isArray(n)){const a={},s={},c=t.filter((r=>{if(e.isValidElement(r)){if(!g(r.props))return!0;{const{variableName:e,variableValue:t,variableOptions:n}=h(r.props);a[e]=t,s[e]=n}}return!1})),u=e=>c.find((r=>{var t,n;const a=m(r);if(void 0!==(null==a?void 0:a.id)){return a.id===(null===(n=null===(t=null==e?void 0:e.props)||void 0===t?void 0:t["data-_gt"])||void 0===n?void 0:n.id)}return!1}))||c.shift();return n.map(((t,n)=>{if("string"==typeof t)return r.jsx(e.Fragment,{children:t},`string_${n}`);if(l(t))return r.jsx(e.Fragment,{children:o({variableType:p[t.v||"v"],variableValue:a[t.k],variableOptions:s[t.k],locales:i})},`var_${n}`);const c=u(t);return c?r.jsx(e.Fragment,{children:j({sourceElement:c,targetElement:t,locales:i,renderVariable:o})},`element_${n}`):void 0}))}if(n&&"object"==typeof n&&!Array.isArray(n)){const r=l(n)?"variable":"element";if(e.isValidElement(t)){if("element"===r)return j({sourceElement:t,targetElement:n,locales:i,renderVariable:o});const e=m(t);if("variable"===(null==e?void 0:e.transformation)){const{variableValue:e,variableOptions:r,variableType:n}=h(t.props);return o({variableType:n,variableValue:e,variableOptions:r,locales:i})}}}return O({children:t,defaultLocale:i[0],renderVariable:o})}const E={method:"default",timeout:"undefined"!=typeof process&&"development"!==process.env.NODE_ENV?8e3:12e3};const w=e=>"string"==typeof e||Array.isArray(e),A=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);exports.addGTIdentifier=function r(t,a=0){let o=a;const l=e=>{const{type:t,props:a}=e;o+=1;const l={id:o};let s;try{s="function"==typeof t&&t.gtTransformation||""}catch(e){}if(s){const t=s.split("-");if("translate"===t[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"===t[0]&&(l.variableType=(null==t?void 0:t[1])||"variable"),"plural"===t[0]){const e=Object.entries(a).reduce(((e,[t,n])=>(function(e){return i.includes(e)}(t)&&(e[t]=r(n,o)),e)),{});Object.keys(e).length&&(l.b=e)}if("branch"===t[0]){const{children:e,branch:t}=a,i=n(a,["children","branch"]),s=Object.entries(i).reduce(((e,[t,n])=>(e[t]=r(n,o),e)),{});Object.keys(s).length&&(l.b=s)}l.t=t[0]}return l};function s(r){return e.isValidElement(r)?function(r){const{props:t}=r;if(t["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));const n=l(r),a=Object.assign(Object.assign({},t),{"data-_gt":n});return t.children&&!n.variableType&&(a.children=c(t.children)),r.type===e.Fragment&&(a["data-_gt"].t="fragment"),e.cloneElement(r,a)}(r):r}function c(r){return Array.isArray(r)?e.Children.map(r,s):s(r)}return c(t)},exports.defaultLocaleCookieName="generaltranslation.locale",exports.defaultRenderSettings=E,exports.flattenDictionary=function e(r,n=""){const a={};for(const i in r)if(r.hasOwnProperty(i)){const o=n?`${n}.${i}`:i;if("object"!=typeof r[i]||null===r[i]||Array.isArray(r[i])){if(a.hasOwnProperty(o))throw new Error(t(o));a[o]=r[i]}else{const n=e(r[i],o);for(const e in n){if(a.hasOwnProperty(e))throw new Error(t(e));a[e]=n[e]}}}return a},exports.getDictionaryEntry=function(r,t){let n=r;const a=t.split(".");for(const r of a){if("object"!=typeof n||Array.isArray(n)||e.isValidElement(n))return;n=n[r]}return n},exports.getEntryAndMetadata=function(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}},exports.getPluralBranch=v,exports.getVariableName=c,exports.getVariableProps=h,exports.isValidDictionaryEntry=function(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},exports.isVariableObject=function(e){const r=e;if(r&&"object"==typeof r&&"string"==typeof r.k){const e=Object.keys(r);if(1===e.length)return!0;if(2===e.length){if("number"==typeof r.i)return!0;if("string"==typeof r.v)return!0}if(3===e.length&&"string"==typeof r.v&&"number"==typeof r.i)return!0}return!1},exports.mergeDictionaries=function e(r,t){const n=Object.assign(Object.assign({},Object.fromEntries(Object.entries(r).filter((([,e])=>w(e))))),Object.fromEntries(Object.entries(t).filter((([,e])=>w(e))))),a=Object.entries(r).filter((([,e])=>A(e))).map((([e])=>e)),i=Object.entries(t).filter((([,e])=>A(e))).map((([e])=>e)),o=new Set([...a,...i]);for(const a of o)n[a]=e(r[a]||{},t[a]||{});return n},exports.renderDefaultChildren=O,exports.renderSkeleton=function(){return""},exports.renderTranslatedChildren=_,exports.writeChildrenAsObjects=y;
|
1
|
+
"use strict";var e=require("react");require("generaltranslation");var r=require("react/jsx-runtime");const t=e=>`Duplicate key found in dictionary: "${e}"`;function n(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)r.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(t[n[a]]=e[n[a]])}return t}"function"==typeof SuppressedError&&SuppressedError;var a="en",i=["singular","plural","dual","zero","one","two","few","many","other"];var o=new(function(){function e(){this.cache=new Map}return e.prototype._generateKey=function(e,r,t){void 0===t&&(t={});var n=Array.isArray(r)?r.join(","):r,a=t?JSON.stringify(t,Object.keys(t).sort()):"{}";return"".concat(e,":").concat(n,":").concat(a)},e.prototype.get=function(e,r,t){void 0===t&&(t={});var n=this._generateKey(e,r,t);if(!this.cache.has(n)){var a=new Intl[e](r,t);this.cache.set(n,a)}return this.cache.get(n)},e}());function l(e){var r=e;if(r&&"object"==typeof r&&"string"==typeof r.k){var t=Object.keys(r);if(1===t.length)return!0;if(2===t.length){if("number"==typeof r.i)return!0;if("string"==typeof r.v)return!0}if(3===t.length&&"string"==typeof r.v&&"number"==typeof r.i)return!0}return!1}var s={variable:"v",number:"n",datetime:"d",currency:"c"};function c(e){return s[e]}const u={variable:"value",number:"n",datetime:"date",currency:"cost"};function d(e={},r){var t;if(e.name)return e.name;return`_gt_${u[r]||"value"}_${null===(t=e["data-_gt"])||void 0===t?void 0:t.id}`}var p={pl:"placeholder",ti:"title",alt:"alt",arl:"aria-label",arb:"aria-labelledby",ard:"aria-describedby"};const f=e=>{var r;if(!e)return"";const{type:t,props:n}=e;if(t&&"function"==typeof t){if("displayName"in t&&"string"==typeof t.displayName&&t.displayName)return t.displayName;if("name"in t&&"string"==typeof t.name&&t.name)return t.name}return t&&"string"==typeof t?t:n.href?"a":(null===(r=n["data-_gt"])||void 0===r?void 0:r.id)?`C${n["data-_gt"].id}`:"function"},b=r=>{return t=r,e.isValidElement(t)?(e=>{const{props:r}=e,t={type:f(e),props:{}};if(r["data-_gt"]){const e=r["data-_gt"];let n={id:e.id};Object.entries(p).forEach((([e,t])=>{r[t]&&(n[e]=r[t])}));const a=e.transformation;if("variable"===a){const t=c(e.variableType||"variable");return{v:t,k:d(r,t),i:e.id}}if("plural"===a&&e.branches){t.type="Plural";const r={};Object.entries(e.branches).forEach((([e,t])=>{r[e]=y(t)})),n=Object.assign(Object.assign({},n),{b:r,t:"p"})}if("branch"===a&&e.branches){t.type="Branch";const r={};Object.entries(e.branches).forEach((([e,t])=>{r[e]=y(t)})),n=Object.assign(Object.assign({},n),{b:r,t:"b"})}t.props["data-_gt"]=n}return r.children&&(t.props.children=y(r.children)),t})(r):"number"==typeof r?r.toString():r;var t};function y(e){return Array.isArray(e)?e.map(b):b(e)}function v(e,r,t){let n="",a=null;return"number"==typeof e&&!a&&t&&(n=function(e,r,t){void 0===r&&(r=i),void 0===t&&(t=["en"]);var n=o.get("PluralRules",t).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"===n&&r.includes("singular"))return"singular";if(2===a){if(r.includes("dual"))return"dual";if(r.includes("two"))return"two"}return"two"===n&&r.includes("dual")?"dual":r.includes(n)?n:"two"===n&&r.includes("dual")?"dual":"two"===n&&r.includes("plural")?"plural":"two"===n&&r.includes("other")?"other":"few"===n&&r.includes("plural")?"plural":"few"===n&&r.includes("other")?"other":"many"===n&&r.includes("plural")?"plural":"many"===n&&r.includes("other")?"other":"other"===n&&r.includes("plural")?"plural":""}(e,Object.keys(t),r)),n&&!a&&(a=t[n]),a}function h(e){var r;return"object"==typeof e&&!!e&&"data-_gt"in e&&"object"==typeof e["data-_gt"]&&!!e["data-_gt"]&&"transformation"in e["data-_gt"]&&"variable"===(null===(r=e["data-_gt"])||void 0===r?void 0:r.transformation)}function g(e){var r;const t=(null===(r=e["data-_gt"])||void 0===r?void 0:r.variableType)||"variable";return{variableName:d(e,t),variableType:c(t),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({},void 0!==e.currency&&{currency:e.currency}),void 0!==e.options&&{options: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 m(e){return e&&e.props&&e.props["data-_gt"]?e.props["data-_gt"]:null}function O({children:r,defaultLocale:t=a,renderVariable:i}){const o=r=>e.isValidElement(r)?(r=>{const a=m(r);if(h(r.props)){const{variableType:e,variableValue:n,variableOptions:a}=g(r.props);return i({variableType:e,variableValue:n,variableOptions:a,locales:[t]})}if("plural"===(null==a?void 0:a.transformation)){const e=a.branches||{};return l(v(r.props.n,[t],e)||r.props.children)}if("branch"===(null==a?void 0:a.transformation)){let e=r.props,{children:t,name:i,branch:o,"data-_gt":s}=e,c=n(e,["children","name","branch","data-_gt"]);return c=a.branches||{},l(void 0!==c[o]?c[o]:t)}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,o):o(r);return l(r)}function j({sourceElement:r,targetElement:t,locales:n=[a],renderVariable:i}){var o,l;const{props:s}=r,{props:c}=t,u=s["data-_gt"],d=null==u?void 0:u.transformation,f=c["data-_gt"],b={};if(f&&Object.entries(p).forEach((([e,r])=>{f[e]&&(b[r]=f[e])})),"plural"===d){const e=r.props.n;return _({source:v(e,n,u.branches||{})||r.props.children,target:v(e,n,t.props["data-_gt"].b||{})||t.props.children,locales:n,renderVariable:i})}if("branch"===d){const{branch:e,children:r}=s;return _({source:(u.branches||{})[e]||r,target:(t.props["data-_gt"].b||{})[e]||t.props.children,locales:n,renderVariable:i})}return"fragment"===d&&(null===(o=t.props)||void 0===o?void 0:o.children)?e.createElement(r.type,{key:r.props.key,children:_({source:s.children,target:t.props.children,locales:n,renderVariable:i})}):(null==s?void 0:s.children)&&(null===(l=t.props)||void 0===l?void 0:l.children)?e.cloneElement(r,Object.assign(Object.assign(Object.assign({},s),b),{"data-_gt":void 0,children:_({source:s.children,target:t.props.children,locales:n,renderVariable:i})})):O({children:r,defaultLocale:n[0],renderVariable:i})}function _({source:t,target:n,locales:i=[a],renderVariable:o}){if(null==n&&t)return O({children:t,defaultLocale:i[0],renderVariable:o});if("string"==typeof n)return n;if(Array.isArray(n)&&!Array.isArray(t)&&t&&(t=[t]),Array.isArray(t)&&Array.isArray(n)){const a={},s={},c=t.filter((r=>{if(e.isValidElement(r)){if(!h(r.props))return!0;{const{variableName:e,variableValue:t,variableOptions:n}=g(r.props);a[e]=t,s[e]=n}}return!1})),u=e=>c.find((r=>{var t,n;const a=m(r);if(void 0!==(null==a?void 0:a.id)){return a.id===(null===(n=null===(t=null==e?void 0:e.props)||void 0===t?void 0:t["data-_gt"])||void 0===n?void 0:n.id)}return!1}))||c.shift();return n.map(((t,n)=>{if("string"==typeof t)return r.jsx(e.Fragment,{children:t},`string_${n}`);if(l(t))return r.jsx(e.Fragment,{children:o({variableType:t.v||"v",variableValue:a[t.k],variableOptions:s[t.k],locales:i})},`var_${n}`);const c=u(t);return c?r.jsx(e.Fragment,{children:j({sourceElement:c,targetElement:t,locales:i,renderVariable:o})},`element_${n}`):void 0}))}if(n&&"object"==typeof n&&!Array.isArray(n)){const r=l(n)?"variable":"element";if(e.isValidElement(t)){if("element"===r)return j({sourceElement:t,targetElement:n,locales:i,renderVariable:o});if(h(t.props)){const{variableValue:e,variableOptions:r,variableType:n}=g(t.props);return o({variableType:n,variableValue:e,variableOptions:r,locales:i})}}}return O({children:t,defaultLocale:i[0],renderVariable:o})}const E={method:"default",timeout:"undefined"!=typeof process&&"development"!==process.env.NODE_ENV?8e3:12e3};const w=e=>"string"==typeof e||Array.isArray(e),A=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);exports.addGTIdentifier=function r(t,a=0){let o=a;const l=e=>{const{type:t,props:a}=e;o+=1;const l={id:o};let s;try{s="function"==typeof t&&t.gtTransformation||""}catch(e){}if(s){const t=s.split("-");if("translate"===t[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"===t[0]&&(l.variableType=(null==t?void 0:t[1])||"variable"),"plural"===t[0]){const e=Object.entries(a).reduce(((e,[t,n])=>{var a;return a=t,i.includes(a)&&(e[t]=r(n,o)),e}),{});Object.keys(e).length&&(l.branches=e)}if("branch"===t[0]){const{children:e,branch:t}=a,i=n(a,["children","branch"]),s=Object.entries(i).reduce(((e,[t,n])=>(e[t]=r(n,o),e)),{});Object.keys(s).length&&(l.branches=s)}l.transformation=t[0]}return l};function s(r){return e.isValidElement(r)?function(r){const{props:t}=r;if(t["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));const n=l(r),a=Object.assign(Object.assign({},t),{"data-_gt":n});return t.children&&!n.variableType&&(a.children=c(t.children)),r.type===e.Fragment&&(a["data-_gt"].transformation="fragment"),e.cloneElement(r,a)}(r):r}function c(r){return Array.isArray(r)?e.Children.map(r,s):s(r)}return c(t)},exports.defaultLocaleCookieName="generaltranslation.locale",exports.defaultRenderSettings=E,exports.flattenDictionary=function e(r,n=""){const a={};for(const i in r)if(r.hasOwnProperty(i)){const o=n?`${n}.${i}`:i;if("object"!=typeof r[i]||null===r[i]||Array.isArray(r[i])){if(a.hasOwnProperty(o))throw new Error(t(o));a[o]=r[i]}else{const n=e(r[i],o);for(const e in n){if(a.hasOwnProperty(e))throw new Error(t(e));a[e]=n[e]}}}return a},exports.getDictionaryEntry=function(r,t){let n=r;const a=t.split(".");for(const r of a){if("object"!=typeof n||Array.isArray(n)||e.isValidElement(n))return;n=n[r]}return n},exports.getEntryAndMetadata=function(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}},exports.getPluralBranch=v,exports.getVariableName=d,exports.getVariableProps=g,exports.isValidDictionaryEntry=function(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},exports.isVariableObject=function(e){const r=e;if(r&&"object"==typeof r&&"string"==typeof r.k){const e=Object.keys(r);if(1===e.length)return!0;if(2===e.length){if("number"==typeof r.i)return!0;if("string"==typeof r.v)return!0}if(3===e.length&&"string"==typeof r.v&&"number"==typeof r.i)return!0}return!1},exports.mergeDictionaries=function e(r,t){const n=Object.assign(Object.assign({},Object.fromEntries(Object.entries(r).filter((([,e])=>w(e))))),Object.fromEntries(Object.entries(t).filter((([,e])=>w(e))))),a=Object.entries(r).filter((([,e])=>A(e))).map((([e])=>e)),i=Object.entries(t).filter((([,e])=>A(e))).map((([e])=>e)),o=new Set([...a,...i]);for(const a of o)n[a]=e(r[a]||{},t[a]||{});return n},exports.renderDefaultChildren=O,exports.renderSkeleton=function(){return""},exports.renderTranslatedChildren=_,exports.writeChildrenAsObjects=y;
|
@@ -1 +1 @@
|
|
1
|
-
import e,{isValidElement as r}from"react";import"generaltranslation";import{jsx as t}from"react/jsx-runtime";const n=e=>`Duplicate key found in dictionary: "${e}"`;function a(e,r=""){const t={};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(t.hasOwnProperty(o))throw new Error(n(o));t[o]=e[i]}else{const r=a(e[i],o);for(const e in r){if(t.hasOwnProperty(e))throw new Error(n(e));t[e]=r[e]}}}return t}function i(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)r.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(t[n[a]]=e[n[a]])}return t}"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,t){void 0===t&&(t={});var n=Array.isArray(r)?r.join(","):r,a=t?JSON.stringify(t,Object.keys(t).sort()):"{}";return"".concat(e,":").concat(n,":").concat(a)},e.prototype.get=function(e,r,t){void 0===t&&(t={});var n=this._generateKey(e,r,t);if(!this.cache.has(n)){var a=new Intl[e](r,t);this.cache.set(n,a)}return this.cache.get(n)},e}());function c(e){var r=e;if(r&&"object"==typeof r&&"string"==typeof r.k){var t=Object.keys(r);if(1===t.length)return!0;if(2===t.length){if("number"==typeof r.i)return!0;if("string"==typeof r.v)return!0}if(3===t.length&&"string"==typeof r.v&&"number"==typeof r.i)return!0}return!1}function u(t,n=0){let a=n;const o=e=>{const{type:r,props:t}=e;a+=1;const n={id:a};let o;try{o="function"==typeof r&&r.gtTransformation||""}catch(e){}if(o){const r=o.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]&&(n.variableType=(null==r?void 0:r[1])||"variable"),"plural"===r[0]){const e=Object.entries(t).reduce(((e,[r,t])=>(function(e){return l.includes(e)}(r)&&(e[r]=u(t,a)),e)),{});Object.keys(e).length&&(n.b=e)}if("branch"===r[0]){const{children:e,branch:r}=t,o=i(t,["children","branch"]),l=Object.entries(o).reduce(((e,[r,t])=>(e[r]=u(t,a),e)),{});Object.keys(l).length&&(n.b=l)}n.t=r[0]}return n};function s(t){return r(t)?function(r){const{props:t}=r;if(t["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));const n=o(r),a=Object.assign(Object.assign({},t),{"data-_gt":n});return t.children&&!n.variableType&&(a.children=c(t.children)),r.type===e.Fragment&&(a["data-_gt"].t="fragment"),e.cloneElement(r,a)}(t):t}function c(r){return Array.isArray(r)?e.Children.map(r,s):s(r)}return c(t)}const d={variable:"value",number:"n",datetime:"date",currency:"cost"};function p(e={},r){var t;if(e.name)return e.name;return`_gt_${d[r]||"value"}_${null===(t=e["data-_gt"])||void 0===t?void 0:t.id}`}var f={pl:"placeholder",ti:"title",alt:"alt",arl:"aria-label",arb:"aria-labelledby",ard:"aria-describedby"},b={variable:"v",number:"n",datetime:"d",currency:"c"},y={v:"variable",n:"number",d:"datetime",c:"currency"};const v=e=>{var r;if(!e)return"";const{type:t,props:n}=e;if(t&&"function"==typeof t){if("displayName"in t&&"string"==typeof t.displayName&&t.displayName)return t.displayName;if("name"in t&&"string"==typeof t.name&&t.name)return t.name}return t&&"string"==typeof t?t:n.href?"a":(null===(r=n["data-_gt"])||void 0===r?void 0:r.id)?`C${n["data-_gt"].id}`:"function"},g=r=>{return t=r,e.isValidElement(t)?(e=>{const{type:r,props:t}=e,n={type:v(e),props:{}};if(t["data-_gt"]){const e=t["data-_gt"];let r=Object.assign({},e);Object.entries(f).forEach((([e,n])=>{t[n]&&(r[e]=t[n])}));const a=e.t;if("variable"===a){const r=b[e.variableType||"variable"];return{v:r,k:p(t,r),i:e.id}}if("plural"===a&&e.b){n.type="Plural";const t={};Object.entries(e.b).forEach((([e,r])=>{t[e]=h(r)})),r=Object.assign(Object.assign({},r),{b:t})}if("branch"===a&&e.b){n.type="Branch";const t={};Object.entries(e.b).forEach((([e,r])=>{t[e]=h(r)})),r=Object.assign(Object.assign({},r),{b:t})}n.props["data-_gt"]=r}return t.children&&(n.props.children=h(t.children)),n})(r):"number"==typeof r?r.toString():r;var t};function h(e){return Array.isArray(e)?e.map(g):g(e)}function m(e,r,t){let n="",a=null;return"number"==typeof e&&!a&&t&&(n=function(e,r,t){void 0===r&&(r=l),void 0===t&&(t=["en"]);var n=s.get("PluralRules",t).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"===n&&r.includes("singular"))return"singular";if(2===a){if(r.includes("dual"))return"dual";if(r.includes("two"))return"two"}return"two"===n&&r.includes("dual")?"dual":r.includes(n)?n:"two"===n&&r.includes("dual")?"dual":"two"===n&&r.includes("plural")?"plural":"two"===n&&r.includes("other")?"other":"few"===n&&r.includes("plural")?"plural":"few"===n&&r.includes("other")?"other":"many"===n&&r.includes("plural")?"plural":"many"===n&&r.includes("other")?"other":"other"===n&&r.includes("plural")?"plural":""}(e,Object.keys(t),r)),n&&!a&&(a=t[n]),a}function O(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 j(r,t){let n=r;const a=t.split(".");for(const r of a){if("object"!=typeof n||Array.isArray(n)||e.isValidElement(n))return;n=n[r]}return n}function _(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 E(e){var r;return"object"==typeof e&&!!e&&"data-_gt"in e&&"object"==typeof e["data-_gt"]&&!!e["data-_gt"]&&"transformation"in e["data-_gt"]&&"variable"===(null===(r=e["data-_gt"])||void 0===r?void 0:r.transformation)}function w(e){var r;const t=(null===(r=e["data-_gt"])||void 0===r?void 0:r.variableType)||"variable";return{variableName:p(e,t),variableType:t,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({},void 0!==e.currency&&{currency:e.currency}),void 0!==e.options&&{options: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 A(e){const r=e;if(r&&"object"==typeof r&&"string"==typeof r.k){const e=Object.keys(r);if(1===e.length)return!0;if(2===e.length){if("number"==typeof r.i)return!0;if("string"==typeof r.v)return!0}if(3===e.length&&"string"==typeof r.v&&"number"==typeof r.i)return!0}return!1}function V(e){return e&&e.props&&e.props["data-_gt"]?e.props["data-_gt"]:null}function T({children:r,defaultLocale:t=o,renderVariable:n}){const a=r=>e.isValidElement(r)?(r=>{const a=V(r);if(E(r.props)){const{variableType:e,variableValue:a,variableOptions:i}=w(r.props);return n({variableType:e,variableValue:a,variableOptions:i,locales:[t]})}if("plural"===(null==a?void 0:a.transformation)){const e=a.branches||{};return l(m(r.props.n,[t],e)||r.props.children)}if("branch"===(null==a?void 0:a.transformation)){let e=r.props,{children:t,name:n,branch:o,"data-_gt":s}=e,c=i(e,["children","name","branch","data-_gt"]);return c=a.branches||{},l(void 0!==c[o]?c[o]:t)}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 k({sourceElement:r,targetElement:t,locales:n=[o],renderVariable:a}){var i,l;const{props:s}=r,{props:c}=t,u=s["data-_gt"],d=null==u?void 0:u.t,p=c["data-_gt"],b={};if(p&&Object.entries(f).forEach((([e,r])=>{p[e]&&(b[r]=p[e])})),"plural"===d){const e=r.props.n;return N({source:m(e,n,u.b||{})||r.props.children,target:m(e,n,t.props["data-_gt"].b||{})||t.props.children,locales:n,renderVariable:a})}if("branch"===d){const{branch:e,children:r}=s;return N({source:(u.b||{})[e]||r,target:(t.props["data-_gt"].b||{})[e]||t.props.children,locales:n,renderVariable:a})}return"fragment"===d&&(null===(i=t.props)||void 0===i?void 0:i.children)?e.createElement(r.type,{key:r.props.key,children:N({source:s.children,target:t.props.children,locales:n,renderVariable:a})}):(null==s?void 0:s.children)&&(null===(l=t.props)||void 0===l?void 0:l.children)?e.cloneElement(r,Object.assign(Object.assign(Object.assign({},s),b),{"data-_gt":void 0,children:N({source:s.children,target:t.props.children,locales:n,renderVariable:a})})):T({children:r,defaultLocale:n[0],renderVariable:a})}function N({source:r,target:n,locales:a=[o],renderVariable:i}){if(null==n&&r)return T({children:r,defaultLocale:a[0],renderVariable:i});if("string"==typeof n)return n;if(Array.isArray(n)&&!Array.isArray(r)&&r&&(r=[r]),Array.isArray(r)&&Array.isArray(n)){const o={},l={},s=r.filter((r=>{if(e.isValidElement(r)){if(!E(r.props))return!0;{const{variableName:e,variableValue:t,variableOptions:n}=w(r.props);o[e]=t,l[e]=n}}return!1})),u=e=>s.find((r=>{var t,n;const a=V(r);if(void 0!==(null==a?void 0:a.id)){return a.id===(null===(n=null===(t=null==e?void 0:e.props)||void 0===t?void 0:t["data-_gt"])||void 0===n?void 0:n.id)}return!1}))||s.shift();return n.map(((r,n)=>{if("string"==typeof r)return t(e.Fragment,{children:r},`string_${n}`);if(c(r))return t(e.Fragment,{children:i({variableType:y[r.v||"v"],variableValue:o[r.k],variableOptions:l[r.k],locales:a})},`var_${n}`);const s=u(r);return s?t(e.Fragment,{children:k({sourceElement:s,targetElement:r,locales:a,renderVariable:i})},`element_${n}`):void 0}))}if(n&&"object"==typeof n&&!Array.isArray(n)){const t=c(n)?"variable":"element";if(e.isValidElement(r)){if("element"===t)return k({sourceElement:r,targetElement:n,locales:a,renderVariable:i});const e=V(r);if("variable"===(null==e?void 0:e.transformation)){const{variableValue:e,variableOptions:t,variableType:n}=w(r.props);return i({variableType:n,variableValue:e,variableOptions:t,locales:a})}}}return T({children:r,defaultLocale:a[0],renderVariable:i})}const $={method:"default",timeout:"undefined"!=typeof process&&"development"!==process.env.NODE_ENV?8e3:12e3};function P(){return""}const S="generaltranslation.locale",x=e=>"string"==typeof e||Array.isArray(e),F=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);function L(e,r){const t=Object.assign(Object.assign({},Object.fromEntries(Object.entries(e).filter((([,e])=>x(e))))),Object.fromEntries(Object.entries(r).filter((([,e])=>x(e))))),n=Object.entries(e).filter((([,e])=>F(e))).map((([e])=>e)),a=Object.entries(r).filter((([,e])=>F(e))).map((([e])=>e)),i=new Set([...n,...a]);for(const n of i)t[n]=L(e[n]||{},r[n]||{});return t}export{u as addGTIdentifier,S as defaultLocaleCookieName,$ as defaultRenderSettings,a as flattenDictionary,j as getDictionaryEntry,_ as getEntryAndMetadata,m as getPluralBranch,p as getVariableName,w as getVariableProps,O as isValidDictionaryEntry,A as isVariableObject,L as mergeDictionaries,T as renderDefaultChildren,P as renderSkeleton,N as renderTranslatedChildren,h as writeChildrenAsObjects};
|
1
|
+
import e,{isValidElement as r}from"react";import"generaltranslation";import{jsx as t}from"react/jsx-runtime";const n=e=>`Duplicate key found in dictionary: "${e}"`;function a(e,r=""){const t={};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(t.hasOwnProperty(o))throw new Error(n(o));t[o]=e[i]}else{const r=a(e[i],o);for(const e in r){if(t.hasOwnProperty(e))throw new Error(n(e));t[e]=r[e]}}}return t}function i(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)r.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(t[n[a]]=e[n[a]])}return t}"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,t){void 0===t&&(t={});var n=Array.isArray(r)?r.join(","):r,a=t?JSON.stringify(t,Object.keys(t).sort()):"{}";return"".concat(e,":").concat(n,":").concat(a)},e.prototype.get=function(e,r,t){void 0===t&&(t={});var n=this._generateKey(e,r,t);if(!this.cache.has(n)){var a=new Intl[e](r,t);this.cache.set(n,a)}return this.cache.get(n)},e}());function c(e){var r=e;if(r&&"object"==typeof r&&"string"==typeof r.k){var t=Object.keys(r);if(1===t.length)return!0;if(2===t.length){if("number"==typeof r.i)return!0;if("string"==typeof r.v)return!0}if(3===t.length&&"string"==typeof r.v&&"number"==typeof r.i)return!0}return!1}var u={variable:"v",number:"n",datetime:"d",currency:"c"};function p(e){return u[e]}function d(t,n=0){let a=n;const o=e=>{const{type:r,props:t}=e;a+=1;const n={id:a};let o;try{o="function"==typeof r&&r.gtTransformation||""}catch(e){}if(o){const r=o.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]&&(n.variableType=(null==r?void 0:r[1])||"variable"),"plural"===r[0]){const e=Object.entries(t).reduce(((e,[r,t])=>{var n;return n=r,l.includes(n)&&(e[r]=d(t,a)),e}),{});Object.keys(e).length&&(n.branches=e)}if("branch"===r[0]){const{children:e,branch:r}=t,o=i(t,["children","branch"]),l=Object.entries(o).reduce(((e,[r,t])=>(e[r]=d(t,a),e)),{});Object.keys(l).length&&(n.branches=l)}n.transformation=r[0]}return n};function s(t){return r(t)?function(r){const{props:t}=r;if(t["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));const n=o(r),a=Object.assign(Object.assign({},t),{"data-_gt":n});return t.children&&!n.variableType&&(a.children=c(t.children)),r.type===e.Fragment&&(a["data-_gt"].transformation="fragment"),e.cloneElement(r,a)}(t):t}function c(r){return Array.isArray(r)?e.Children.map(r,s):s(r)}return c(t)}const f={variable:"value",number:"n",datetime:"date",currency:"cost"};function b(e={},r){var t;if(e.name)return e.name;return`_gt_${f[r]||"value"}_${null===(t=e["data-_gt"])||void 0===t?void 0:t.id}`}var y={pl:"placeholder",ti:"title",alt:"alt",arl:"aria-label",arb:"aria-labelledby",ard:"aria-describedby"};const v=e=>{var r;if(!e)return"";const{type:t,props:n}=e;if(t&&"function"==typeof t){if("displayName"in t&&"string"==typeof t.displayName&&t.displayName)return t.displayName;if("name"in t&&"string"==typeof t.name&&t.name)return t.name}return t&&"string"==typeof t?t:n.href?"a":(null===(r=n["data-_gt"])||void 0===r?void 0:r.id)?`C${n["data-_gt"].id}`:"function"},h=r=>{return t=r,e.isValidElement(t)?(e=>{const{props:r}=e,t={type:v(e),props:{}};if(r["data-_gt"]){const e=r["data-_gt"];let n={id:e.id};Object.entries(y).forEach((([e,t])=>{r[t]&&(n[e]=r[t])}));const a=e.transformation;if("variable"===a){const t=p(e.variableType||"variable");return{v:t,k:b(r,t),i:e.id}}if("plural"===a&&e.branches){t.type="Plural";const r={};Object.entries(e.branches).forEach((([e,t])=>{r[e]=g(t)})),n=Object.assign(Object.assign({},n),{b:r,t:"p"})}if("branch"===a&&e.branches){t.type="Branch";const r={};Object.entries(e.branches).forEach((([e,t])=>{r[e]=g(t)})),n=Object.assign(Object.assign({},n),{b:r,t:"b"})}t.props["data-_gt"]=n}return r.children&&(t.props.children=g(r.children)),t})(r):"number"==typeof r?r.toString():r;var t};function g(e){return Array.isArray(e)?e.map(h):h(e)}function m(e,r,t){let n="",a=null;return"number"==typeof e&&!a&&t&&(n=function(e,r,t){void 0===r&&(r=l),void 0===t&&(t=["en"]);var n=s.get("PluralRules",t).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"===n&&r.includes("singular"))return"singular";if(2===a){if(r.includes("dual"))return"dual";if(r.includes("two"))return"two"}return"two"===n&&r.includes("dual")?"dual":r.includes(n)?n:"two"===n&&r.includes("dual")?"dual":"two"===n&&r.includes("plural")?"plural":"two"===n&&r.includes("other")?"other":"few"===n&&r.includes("plural")?"plural":"few"===n&&r.includes("other")?"other":"many"===n&&r.includes("plural")?"plural":"many"===n&&r.includes("other")?"other":"other"===n&&r.includes("plural")?"plural":""}(e,Object.keys(t),r)),n&&!a&&(a=t[n]),a}function O(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 j(r,t){let n=r;const a=t.split(".");for(const r of a){if("object"!=typeof n||Array.isArray(n)||e.isValidElement(n))return;n=n[r]}return n}function _(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 E(e){var r;return"object"==typeof e&&!!e&&"data-_gt"in e&&"object"==typeof e["data-_gt"]&&!!e["data-_gt"]&&"transformation"in e["data-_gt"]&&"variable"===(null===(r=e["data-_gt"])||void 0===r?void 0:r.transformation)}function w(e){var r;const t=(null===(r=e["data-_gt"])||void 0===r?void 0:r.variableType)||"variable";return{variableName:b(e,t),variableType:p(t),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({},void 0!==e.currency&&{currency:e.currency}),void 0!==e.options&&{options: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 A(e){const r=e;if(r&&"object"==typeof r&&"string"==typeof r.k){const e=Object.keys(r);if(1===e.length)return!0;if(2===e.length){if("number"==typeof r.i)return!0;if("string"==typeof r.v)return!0}if(3===e.length&&"string"==typeof r.v&&"number"==typeof r.i)return!0}return!1}function V(e){return e&&e.props&&e.props["data-_gt"]?e.props["data-_gt"]:null}function T({children:r,defaultLocale:t=o,renderVariable:n}){const a=r=>e.isValidElement(r)?(r=>{const a=V(r);if(E(r.props)){const{variableType:e,variableValue:a,variableOptions:i}=w(r.props);return n({variableType:e,variableValue:a,variableOptions:i,locales:[t]})}if("plural"===(null==a?void 0:a.transformation)){const e=a.branches||{};return l(m(r.props.n,[t],e)||r.props.children)}if("branch"===(null==a?void 0:a.transformation)){let e=r.props,{children:t,name:n,branch:o,"data-_gt":s}=e,c=i(e,["children","name","branch","data-_gt"]);return c=a.branches||{},l(void 0!==c[o]?c[o]:t)}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 k({sourceElement:r,targetElement:t,locales:n=[o],renderVariable:a}){var i,l;const{props:s}=r,{props:c}=t,u=s["data-_gt"],p=null==u?void 0:u.transformation,d=c["data-_gt"],f={};if(d&&Object.entries(y).forEach((([e,r])=>{d[e]&&(f[r]=d[e])})),"plural"===p){const e=r.props.n;return N({source:m(e,n,u.branches||{})||r.props.children,target:m(e,n,t.props["data-_gt"].b||{})||t.props.children,locales:n,renderVariable:a})}if("branch"===p){const{branch:e,children:r}=s;return N({source:(u.branches||{})[e]||r,target:(t.props["data-_gt"].b||{})[e]||t.props.children,locales:n,renderVariable:a})}return"fragment"===p&&(null===(i=t.props)||void 0===i?void 0:i.children)?e.createElement(r.type,{key:r.props.key,children:N({source:s.children,target:t.props.children,locales:n,renderVariable:a})}):(null==s?void 0:s.children)&&(null===(l=t.props)||void 0===l?void 0:l.children)?e.cloneElement(r,Object.assign(Object.assign(Object.assign({},s),f),{"data-_gt":void 0,children:N({source:s.children,target:t.props.children,locales:n,renderVariable:a})})):T({children:r,defaultLocale:n[0],renderVariable:a})}function N({source:r,target:n,locales:a=[o],renderVariable:i}){if(null==n&&r)return T({children:r,defaultLocale:a[0],renderVariable:i});if("string"==typeof n)return n;if(Array.isArray(n)&&!Array.isArray(r)&&r&&(r=[r]),Array.isArray(r)&&Array.isArray(n)){const o={},l={},s=r.filter((r=>{if(e.isValidElement(r)){if(!E(r.props))return!0;{const{variableName:e,variableValue:t,variableOptions:n}=w(r.props);o[e]=t,l[e]=n}}return!1})),u=e=>s.find((r=>{var t,n;const a=V(r);if(void 0!==(null==a?void 0:a.id)){return a.id===(null===(n=null===(t=null==e?void 0:e.props)||void 0===t?void 0:t["data-_gt"])||void 0===n?void 0:n.id)}return!1}))||s.shift();return n.map(((r,n)=>{if("string"==typeof r)return t(e.Fragment,{children:r},`string_${n}`);if(c(r))return t(e.Fragment,{children:i({variableType:r.v||"v",variableValue:o[r.k],variableOptions:l[r.k],locales:a})},`var_${n}`);const s=u(r);return s?t(e.Fragment,{children:k({sourceElement:s,targetElement:r,locales:a,renderVariable:i})},`element_${n}`):void 0}))}if(n&&"object"==typeof n&&!Array.isArray(n)){const t=c(n)?"variable":"element";if(e.isValidElement(r)){if("element"===t)return k({sourceElement:r,targetElement:n,locales:a,renderVariable:i});if(E(r.props)){const{variableValue:e,variableOptions:t,variableType:n}=w(r.props);return i({variableType:n,variableValue:e,variableOptions:t,locales:a})}}}return T({children:r,defaultLocale:a[0],renderVariable:i})}const $={method:"default",timeout:"undefined"!=typeof process&&"development"!==process.env.NODE_ENV?8e3:12e3};function P(){return""}const S="generaltranslation.locale",x=e=>"string"==typeof e||Array.isArray(e),F=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);function L(e,r){const t=Object.assign(Object.assign({},Object.fromEntries(Object.entries(e).filter((([,e])=>x(e))))),Object.fromEntries(Object.entries(r).filter((([,e])=>x(e))))),n=Object.entries(e).filter((([,e])=>F(e))).map((([e])=>e)),a=Object.entries(r).filter((([,e])=>F(e))).map((([e])=>e)),i=new Set([...n,...a]);for(const n of i)t[n]=L(e[n]||{},r[n]||{});return t}export{d as addGTIdentifier,S as defaultLocaleCookieName,$ as defaultRenderSettings,a as flattenDictionary,j as getDictionaryEntry,_ as getEntryAndMetadata,m as getPluralBranch,b as getVariableName,w as getVariableProps,O as isValidDictionaryEntry,A as isVariableObject,L as mergeDictionaries,T as renderDefaultChildren,P as renderSkeleton,N as renderTranslatedChildren,g as writeChildrenAsObjects};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"renderTranslatedChildren.d.ts","sourceRoot":"","sources":["../../src/rendering/renderTranslatedChildren.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,EACL,cAAc,EAEd,kBAAkB,EAClB,cAAc,EAEf,MAAM,gBAAgB,CAAC;
|
1
|
+
{"version":3,"file":"renderTranslatedChildren.d.ts","sourceRoot":"","sources":["../../src/rendering/renderTranslatedChildren.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,EACL,cAAc,EAEd,kBAAkB,EAClB,cAAc,EAEf,MAAM,gBAAgB,CAAC;AAmHxB,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAAC,EAC/C,MAAM,EACN,MAAM,EACN,OAAgC,EAChC,cAAc,GACf,EAAE;IACD,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,SAAS,CAgIZ"}
|
package/dist/types/types.d.ts
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
import { JsxChildren } from 'generaltranslation/internal';
|
2
|
-
import {
|
2
|
+
import { Variable, VariableTransformationSuffix, TransformationPrefix, GTProp, VariableType } from 'generaltranslation/types';
|
3
3
|
import React from 'react';
|
4
4
|
/**
|
5
5
|
* TaggedElement is a React element with a GTProp property.
|
6
6
|
*/
|
7
|
+
export type GTTag = {
|
8
|
+
id: number;
|
9
|
+
transformation?: TransformationPrefix;
|
10
|
+
branches?: Record<string, JsxChildren>;
|
11
|
+
variableType?: VariableTransformationSuffix;
|
12
|
+
};
|
7
13
|
export type TaggedElementProps = Record<string, any> & {
|
8
|
-
'data-_gt':
|
14
|
+
'data-_gt': GTTag;
|
9
15
|
};
|
10
16
|
export type TaggedElement = React.ReactElement<TaggedElementProps>;
|
11
17
|
export type TaggedChild = Exclude<React.ReactNode, React.ReactElement> | TaggedElement;
|
@@ -31,11 +37,7 @@ export type FlattenedDictionary = {
|
|
31
37
|
export type TranslatedElement = {
|
32
38
|
type: string;
|
33
39
|
props: {
|
34
|
-
'data-_gt':
|
35
|
-
id: number;
|
36
|
-
transformation?: string;
|
37
|
-
b?: Record<string, JsxChildren>;
|
38
|
-
} & HtmlContentPropKeysRecord;
|
40
|
+
'data-_gt': GTProp;
|
39
41
|
children?: TranslatedChildren;
|
40
42
|
};
|
41
43
|
};
|
@@ -77,7 +79,7 @@ export type RuntimeTranslationOptions = {
|
|
77
79
|
locale?: string;
|
78
80
|
} & Omit<InlineTranslationOptions, 'id'>;
|
79
81
|
export type VariableProps = {
|
80
|
-
variableType:
|
82
|
+
variableType: VariableType;
|
81
83
|
variableValue: any;
|
82
84
|
variableOptions: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions;
|
83
85
|
variableName: string;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACL,
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"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"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"LocaleSelector.d.ts","sourceRoot":"","sources":["../../src/ui/LocaleSelector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAkB1B;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACrC,OAAO,EAAE,QAAQ,EACjB,WAAW,EACX,GAAG,KAAK,EACT,EAAE;IACD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACxC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,
|
1
|
+
{"version":3,"file":"LocaleSelector.d.ts","sourceRoot":"","sources":["../../src/ui/LocaleSelector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAkB1B;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACrC,OAAO,EAAE,QAAQ,EACjB,WAAW,EACX,GAAG,KAAK,EACT,EAAE;IACD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACxC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAsC3B"}
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import { VariableProps } from '../types/types';
|
1
|
+
import { GTTag, VariableProps } from '../types/types';
|
3
2
|
type VariableElementProps = {
|
4
|
-
'data-_gt':
|
3
|
+
'data-_gt': GTTag & {
|
5
4
|
transformation: 'variable';
|
6
5
|
};
|
7
6
|
[key: string]: unknown;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"_getVariableProps.d.ts","sourceRoot":"","sources":["../../src/variables/_getVariableProps.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"_getVariableProps.d.ts","sourceRoot":"","sources":["../../src/variables/_getVariableProps.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAItD,KAAK,oBAAoB,GAAG;IAC1B,UAAU,EAAE,KAAK,GAAG;QAClB,cAAc,EAAE,UAAU,CAAC;KAC5B,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,oBAAoB,CAU/B;AAED,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,KAAK,EAAE,oBAAoB,GAC1B,aAAa,CA+Bf"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "gt-react",
|
3
|
-
"version": "10.0.0-alpha.
|
3
|
+
"version": "10.0.0-alpha.17",
|
4
4
|
"description": "A React library for automatic internationalization.",
|
5
5
|
"main": "./dist/index.cjs.min.cjs",
|
6
6
|
"module": "./dist/index.esm.min.mjs",
|
@@ -14,8 +14,8 @@
|
|
14
14
|
"react-dom": ">=16.8.0"
|
15
15
|
},
|
16
16
|
"dependencies": {
|
17
|
-
"@generaltranslation/supported-locales": "^2.0.11-alpha.
|
18
|
-
"generaltranslation": "^7.0.0-alpha.
|
17
|
+
"@generaltranslation/supported-locales": "^2.0.11-alpha.17",
|
18
|
+
"generaltranslation": "^7.0.0-alpha.17"
|
19
19
|
},
|
20
20
|
"scripts": {
|
21
21
|
"patch": "npm version patch",
|