generaltranslation
Version:
A language toolkit for AI developers
3 lines (2 loc) • 12.6 kB
JavaScript
;var t=require("@formatjs/icu-messageformat-parser"),r=require("@formatjs/icu-messageformat-parser/types.js"),e=require("@formatjs/icu-messageformat-parser/printer.js"),n=require("fast-json-stable-stringify"),o=require("crypto-js"),i="en",a=["singular","plural","dual","zero","one","two","few","many","other"];var l=function(){return l=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t},l.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var u,s,c="ellipsis",p="DEFAULT_TERMINATOR_KEY",d={ellipsis:(u={fr:{terminator:"…",separator:" "},zh:{terminator:"……",separator:void 0},ja:{terminator:"……",separator:void 0}},u[p]={terminator:"…",separator:void 0},u),none:(s={},s[p]={terminator:void 0,separator:void 0},s)},f=function(){function t(t,r){var e,n,o,a,l,u,s,f,v;void 0===r&&(r={});try{var h=t?Array.isArray(t)?t.map(function(t){return String(t)}):[String(t)]:[i],g=Intl.getCanonicalLocales(h);this.locale=g.length?g[0]:i}catch(t){this.locale=i}if(!d[null!==(e=r.style)&&void 0!==e?e:c])throw new Error(function(t){return"generaltranslation Formatting Error: Invalid cutoff style: ".concat(t,".")}(null!==(n=r.style)&&void 0!==n?n:c));if(void 0!==r.maxChars){f=null!==(o=r.style)&&void 0!==o?o:c;var m=new Intl.Locale(this.locale).language;v=d[f][m]||d[f][p]}var y=null!==(a=r.terminator)&&void 0!==a?a:null==v?void 0:v.terminator,b=null!=y?null!==(l=r.separator)&&void 0!==l?l:null==v?void 0:v.separator:void 0;this.additionLength=(null!==(u=null==y?void 0:y.length)&&void 0!==u?u:0)+(null!==(s=null==b?void 0:b.length)&&void 0!==s?s:0),void 0!==r.maxChars&&Math.abs(r.maxChars)<this.additionLength&&(y=void 0,b=void 0),this.options={maxChars:r.maxChars,style:f,terminator:y,separator:b}}return t.prototype.format=function(t){return this.formatToParts(t).join("")},t.prototype.formatToParts=function(t){var r=this.options,e=r.maxChars,n=r.terminator,o=r.separator,i=void 0===e||Math.abs(e)>=t.length?e:e>=0?Math.max(0,e-this.additionLength):Math.min(0,e+this.additionLength),a=void 0!==i&&i>-1?t.slice(0,i):t.slice(i);return null==e||null==i||0===i||null==n||t.length<=Math.abs(e)?[a]:i>0?null!=o?[a,o,n]:[a,n]:null!=o?[n,o,a]:[n,a]},t.prototype.resolvedOptions=function(){return this.options},t}(),v={Collator:Intl.Collator,DateTimeFormat:Intl.DateTimeFormat,DisplayNames:Intl.DisplayNames,ListFormat:Intl.ListFormat,Locale:Intl.Locale,NumberFormat:Intl.NumberFormat,PluralRules:Intl.PluralRules,RelativeTimeFormat:Intl.RelativeTimeFormat,Segmenter:Intl.Segmenter,CutoffFormat:f},h=function(){function t(){this.cache={}}return t.prototype._generateKey=function(t,r){void 0===r&&(r={});var e=t?Array.isArray(t)?t.map(function(t){return String(t)}).join(","):String(t):"undefined",n=r?JSON.stringify(r,Object.keys(r).sort()):"{}";return"".concat(e,":").concat(n)},t.prototype.get=function(t){for(var r,e,n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];var a=n[0],l=void 0===a?i:a,u=n[1],s=void 0===u?{}:u,c=this._generateKey(l,s),p=null===(e=this.cache[t])||void 0===e?void 0:e[c];return void 0===p&&(p=new((r=v[t]).bind.apply(r,function(t,r,e){if(e||2===arguments.length)for(var n,o=0,i=r.length;o<i;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return t.concat(n||Array.prototype.slice.call(r))}([void 0],n,!1))),this.cache[t]||(this.cache[t]={}),this.cache[t][c]=p),p},t}(),g=new h;var m={variable:"v",number:"n",datetime:"d",currency:"c"};function y(r){var e=r.icuString,n=r.shouldVisit,o=r.visitor,i=r.options,a=i.recurseIntoVisited,l=void 0===a||a,u=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(e[n[o]]=t[n[o]])}return e}(i,["recurseIntoVisited"]),s=t.parse(e,u);return c(s),s;function c(t){t.map(p)}function p(r){var e=!1;n(r)&&(o(r),e=!0),e&&!l||(r.type===t.TYPE.select||r.type===t.TYPE.plural?Object.values(r.options).map(function(t){return t.value}).map(c):r.type===t.TYPE.tag&&c(r.children))}}var b="_gt_",x="_gt_var_name",O=new RegExp("^".concat(b,"\\d+$")),j=new RegExp("^".concat(b,"$"));function w(t){var e;return t.type===r.TYPE.select&&O.test(t.value)&&!!t.options.other&&(0===t.options.other.value.length||t.options.other.value.length>0&&(null===(e=t.options.other.value[0])||void 0===e?void 0:e.type)===r.TYPE.literal)}function E(t){var e;return t.type===r.TYPE.select&&j.test(t.value)&&!!t.options.other&&(0===t.options.other.value.length||t.options.other.value.length>0&&(null===(e=t.options.other.value[0])||void 0===e?void 0:e.type)===r.TYPE.literal)}function T(t){var r=t.replace(/['\']/g,"''"),e=/[{}<>]/,n=r.search(e);if(-1===n)return r;for(var o=-1,i=r.length-1;i>=0;i--)if(e.test(r[i])){o=i;break}return r=r.slice(0,n)+"'"+r.slice(n,o+1)+"'"+r.slice(o+1)}function S(t){return"object"==typeof t&&null!=t&&"key"in t}function I(t){return"object"==typeof t&&null!=t&&"k"in t}function V(t){return"string"==typeof t||(!!S(t)||function(t){return"object"==typeof t&&null!=t&&"type"in t&&"props"in t}(t))}function A(t){return"string"==typeof t||(Array.isArray(t)?!t.some(function(t){return!V(t)}):V(t))}function P(t){return"string"==typeof t?t:S(t)?L(t):F(t)}function C(t){return"string"==typeof t?t:Array.isArray(t)?t.map(P):P(t)}function F(t){var r;if("string"==typeof t)return t;var e=void 0;null!=t.type&&(e=t.type);var n=void 0;return null!=(null===(r=t.props)||void 0===r?void 0:r.children)&&(n=C(t.props.children)),l(l(l({},e&&{t:e}),n&&{c:n}),{d:R(t.props["data-_gt"]),i:t.props["data-_gt"].id})}function _(t){return"branch"===t?"b":"p"}function N(t){switch(t){case"number":return"n";case"variable":default:return"v";case"datetime":return"d";case"currency":return"c"}}function L(t){var r=void 0;null!=t.variable&&(r=N(t.variable));var e=void 0;return null!=t.id&&(e=t.id),l(l({k:t.key},r&&{v:r}),e&&{i:e})}function R(t){var r,e=void 0;return t.branches&&(e=Object.fromEntries(Object.entries(t.branches).map(function(t){return[t[0],C(t[1])]}))),t.transformation&&(r=_(t.transformation)),l(l({},e&&{b:e}),r&&{t:r})}function k(t){return"string"==typeof t?t:I(t)?B(t):J(t)}function D(t){return A(t)||"string"==typeof t?t:Array.isArray(t)?t.map(k):k(t)}function J(t){var r=t.t,e=void 0;return null!=t.c&&(e=D(t.c)),{type:r,props:{children:e,"data-_gt":q(t.d||{},t.i)}}}function Y(t){return"b"===t?"branch":"plural"}function M(t){switch(t){case"n":return"number";case"v":default:return"variable";case"d":return"datetime";case"c":return"currency"}}function B(t){var r=void 0;null!=t.v&&(r=M(t.v));var e=void 0;return null!=t.i&&(e=t.i),l(l({key:t.k},r&&{variable:r}),e&&{id:e})}function q(t,r){var e=void 0;null!=t.t&&(e=Y(t.t));var n=void 0;return null!=t.b&&(n=Object.fromEntries(Object.entries(t.b).map(function(t){return[t[0],D(t[1])]}))),l(l({id:r},e&&{transformation:e}),n&&{branches:n})}function U(t){return o.SHA256(t).toString(o.enc.Hex)}var z=function(t){var r,e,n,o;if(t&&"object"==typeof t){if("props"in t){var i={},a=null===(r=null==t?void 0:t.props)||void 0===r?void 0:r["data-_gt"];return(null==a?void 0:a.branches)&&(i.branches=Object.fromEntries(Object.entries(a.branches).map(function(t){return[t[0],H(t[1])]}))),(null===(e=null==t?void 0:t.props)||void 0===e?void 0:e.children)&&(i.children=H(t.props.children)),(null===(o=null===(n=null==t?void 0:t.props)||void 0===n?void 0:n["data-_gt"])||void 0===o?void 0:o.transformation)&&(i.transformation=t.props["data-_gt"].transformation),i}if("key"in t)return l({key:t.key},t.variable&&{variable:t.variable})}return t};function H(t){return Array.isArray(t)?t.map(z):z(t)}exports.VAR_IDENTIFIER=b,exports.VAR_NAME_IDENTIFIER=x,exports.condenseVars=function(t){if(!t.includes(b))return t;var n=y({icuString:t,shouldVisit:w,visitor:function(t){t.type=r.TYPE.argument,delete t.options},options:{recurseIntoVisited:!1}});return e.printAST(n)},exports.declareStatic=function(t){return t},exports.declareVar=function(t,r){var e=T(String(null!=t?t:"")),n=" other {".concat(e,"}"),o="";if(null==r?void 0:r.$name){var i=T(r.$name);o=" ".concat(x," {").concat(i,"}")}return"{".concat(b,", select,").concat(n).concat(o,"}")},exports.decode=function(t){if("undefined"!=typeof Buffer)return Buffer.from(t,"base64").toString("utf8");for(var r=atob(t),e=new Uint8Array(r.length),n=0;n<r.length;n++)e[n]=r.charCodeAt(n);return(new TextDecoder).decode(e)},exports.decodeVars=function(t){if(!t.includes(b))return t;var r=[];y({icuString:t,shouldVisit:E,visitor:function(t){var e,n,o,i;r.push({start:null!==(n=null===(e=t.location)||void 0===e?void 0:e.start.offset)&&void 0!==n?n:0,end:null!==(i=null===(o=t.location)||void 0===o?void 0:o.end.offset)&&void 0!==i?i:0,value:t.options.other.value.length>0?t.options.other.value[0].value:""})},options:{recurseIntoVisited:!1,captureLocation:!0}});for(var e=0,n=[],o=0;o<r.length;o++)n.push(t.slice(e,r[o].start)),n.push(r[o].value),e=r[o].end;return e<t.length&&n.push(t.slice(e)),n.join("")},exports.defaultBaseUrl="https://api2.gtx.dev",exports.defaultCacheUrl="https://cdn.gtx.dev",exports.defaultRuntimeApiUrl="https://runtime2.gtx.dev",exports.defaultTimeout=6e4,exports.encode=function(t){if("undefined"!=typeof Buffer)return Buffer.from(t,"utf8").toString("base64");for(var r=(new TextEncoder).encode(t),e="",n=0;n<r.length;n++)e+=String.fromCharCode(r[n]);return btoa(e)},exports.extractVars=function(t){if(!t.includes(b))return{};var r=1,e={};return y({icuString:t,shouldVisit:E,visitor:function(t){var n;e[t.value+r]=t.options.other.value.length?null===(n=t.options.other.value[0])||void 0===n?void 0:n.value:"",r+=1},options:{recurseIntoVisited:!1}}),e},exports.getNewBranchType=_,exports.getNewGTProp=R,exports.getNewJsxChild=P,exports.getNewJsxChildren=C,exports.getNewJsxElement=F,exports.getNewVariableObject=L,exports.getNewVariableType=N,exports.getOldBranchType=Y,exports.getOldGTProp=q,exports.getOldJsxChild=k,exports.getOldJsxChildren=D,exports.getOldJsxElement=J,exports.getOldVariableObject=B,exports.getOldVariableType=M,exports.getPluralForm=function(t,r,e){void 0===r&&(r=a),void 0===e&&(e=[i]);var n=g.get("PluralRules",e).select(t),o=Math.abs(t);if(0===o&&r.includes("zero"))return"zero";if(1===o){if(r.includes("singular"))return"singular";if(r.includes("one"))return"one"}if("one"===n&&r.includes("singular"))return"singular";if(2===o){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":""},exports.indexVars=function(t){if(!t.includes(b))return t;var r=[];y({icuString:t,shouldVisit:E,visitor:function(t){var e,n,o,i,a,l,u,s;r.push({start:null!==(n=null===(e=t.location)||void 0===e?void 0:e.start.offset)&&void 0!==n?n:0,end:null!==(i=null===(o=t.location)||void 0===o?void 0:o.end.offset)&&void 0!==i?i:0,otherStart:null!==(l=null===(a=t.options.other.location)||void 0===a?void 0:a.start.offset)&&void 0!==l?l:0,otherEnd:null!==(s=null===(u=t.options.other.location)||void 0===u?void 0:u.end.offset)&&void 0!==s?s:0})},options:{recurseIntoVisited:!1,captureLocation:!0}});for(var e=[],n=0,o=0;o<r.length;o++){var i=r[o],a=i.start,l=i.end,u=i.otherStart,s=i.otherEnd;e.push(t.slice(n,a)),e.push(t.slice(a,a+4+1)),e.push(String(o+1)),e.push(t.slice(a+4+1,u)),e.push("{}"),e.push(t.slice(s,l)),n=l}return e.push(t.slice(n,t.length)),e.join("")},exports.isAcceptedPluralForm=function(t){return a.includes(t)},exports.isNewVariableObject=I,exports.isOldJsxChildren=A,exports.isOldVariableObject=S,exports.isVariable=function(t){var r=t;if(r&&"object"==typeof r&&"string"==typeof r.k){var 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.libraryDefaultLocale=i,exports.minifyVariableType=function(t){return m[t]},exports.oldHashJsxChildren=function(t,r){var e=t.source,o=t.context,i=t.id,a=t.dataFormat;return void 0===r&&(r=U),r(n(l(l(l({source:H(e)},i&&{id:i}),o&&{context:o}),a&&{dataFormat:a})))},exports.oldHashString=U,exports.pluralForms=a;
//# sourceMappingURL=internal.cjs.min.cjs.map