generaltranslation 3.3.0 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(){return t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},t.apply(this,arguments)};function e(t,e,n,r){return new(n||(n=Promise))((function(a,o){function i(t){try{c(r.next(t))}catch(t){o(t)}}function u(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,u)}c((r=r.apply(t,e||[])).next())}))}function n(t,e){var n,r,a,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=u(0),i.throw=u(1),i.return=u(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(o=0)),o;)try{if(n=1,r&&(a=2&u[0]?r.return:u[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,u[1])).done)return a;switch(r=0,a&&(u=[2&u[0],a.value]),u[0]){case 0:case 1:a=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(a=o.trys,(a=a.length>0&&a[a.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!a||u[1]>a[0]&&u[1]<a[3])){o.label=u[1];break}if(6===u[0]&&o.label<a[1]){o.label=a[1],a=u;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(u);break}a[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],r=0}finally{n=a=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}"function"==typeof SuppressedError&&SuppressedError;var r="/v1/translate/batch",a="/v1/translate/react",o="/v1/translate/content",i="/v1/project/dictionary/update",u="/v1/project/languages";function c(t,a){return e(this,void 0,void 0,(function(){var e,o,i,u,c,s,l,f,p;return n(this,(function(n){switch(n.label){case 0:return e=new AbortController,o=e.signal,(null===(p=null===(f=null===(l=a[0])||void 0===l?void 0:l.data)||void 0===f?void 0:f.metadata)||void 0===p?void 0:p.timeout)&&setTimeout((function(){return e.abort()}),a[0].data.metadata.timeout),[4,fetch("".concat(t.baseURL).concat(r),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify(a),signal:o})];case 1:return(i=n.sent()).ok?[3,3]:(u=Error.bind,s=(c="".concat(i.status,": ")).concat,[4,i.text()]);case 2:throw new(u.apply(Error,[void 0,s.apply(c,[n.sent()])]));case 3:return[4,i.json()];case 4:return[2,n.sent()]}}))}))}var s="en",l=function(t){try{var e=new Intl.Locale(t).maximize(),n=e.language,r=e.region,a=e.script;if(new Intl.DisplayNames([s],{type:"language"}).of(n)===n)return!1;if(r)if(new Intl.DisplayNames([s],{type:"region"}).of(r)===r)return!1;if(a)if(new Intl.DisplayNames([s],{type:"script"}).of(a)===a)return!1;return!0}catch(t){return!1}},f=function(t){try{return new Intl.Locale(t).toString()}catch(t){return""}};function p(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{var n=t.flat().map((function(t){return new Intl.Locale(t).language}));return n.every((function(t){return t===n[0]}))}catch(t){return console.error(t),!1}}function g(t,r,a,i){return e(this,void 0,void 0,(function(){var e,u,c,s,l,f;return n(this,(function(n){switch(n.label){case 0:return e=new AbortController,u=e.signal,i.timeout&&setTimeout((function(){return e.abort()}),i.timeout),[4,fetch("".concat(t.baseURL).concat(o),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({content:r,targetLanguage:a,metadata:i}),signal:u})];case 1:return(c=n.sent()).ok?[3,3]:(s=Error.bind,f=(l="".concat(c.status,": ")).concat,[4,c.text()]);case 2:throw new(s.apply(Error,[void 0,f.apply(l,[n.sent()])]));case 3:return[4,c.json()];case 4:return[2,n.sent()]}}))}))}function d(t,r,o,i){return e(this,void 0,void 0,(function(){var e,u,c,s,l,f;return n(this,(function(n){switch(n.label){case 0:return e=new AbortController,u=e.signal,i.timeout&&setTimeout((function(){return e.abort()}),i.timeout),[4,fetch("".concat(t.baseURL).concat(a),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({children:r,targetLanguage:o,metadata:i}),signal:u})];case 1:return(c=n.sent()).ok?[3,3]:(s=Error.bind,f=(l="".concat(c.status,": ")).concat,[4,c.text()]);case 2:throw new(s.apply(Error,[void 0,f.apply(l,[n.sent()])]));case 3:return[4,c.json()];case 4:return[2,n.sent()]}}))}))}function v(t,r,a,o){return e(this,void 0,void 0,(function(){var e,u,c,s,l;return n(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat(t.baseURL).concat(i),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({updates:r,languages:a,options:o})})];case 1:return(e=n.sent()).ok?[3,3]:(u=Error.bind,s=(c="".concat(e.status,": ")).concat,[4,e.text()]);case 2:throw new(u.apply(Error,[void 0,s.apply(c,[n.sent()])]));case 3:return[4,e.json()];case 4:return[2,null==(l=n.sent())?void 0:l.languages]}}))}))}function y(t,r){return e(this,void 0,void 0,(function(){var e,a,o,i,c;return n(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat(t.baseURL).concat(u,"?projectID=").concat(r),{method:"GET",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey}})];case 1:return(e=n.sent()).ok?[3,3]:(a=Error.bind,i=(o="".concat(e.status,": ")).concat,[4,e.text()]);case 2:throw new(a.apply(Error,[void 0,i.apply(o,[n.sent()])]));case 3:return[4,e.json()];case 4:return[2,null==(c=n.sent())?void 0:c.languages]}}))}))}function m(e){var n=e.value,r=e.languages,a=void 0===r?[s]:r,o=e.options,i=void 0===o?{}:o;return new Intl.NumberFormat(a,t({numberingSystem:"latn"},i)).format(n)}function h(e){var n=e.value,r=e.languages,a=void 0===r?[s]:r,o=e.options,i=void 0===o?{}:o;return new Intl.DateTimeFormat(a,t({calendar:"gregory",numberingSystem:"latn"},i)).format(n)}function b(e){var n=e.value,r=e.languages,a=void 0===r?[s]:r,o=e.currency,i=void 0===o?"USD":o,u=e.options,c=void 0===u?{}:u;return new Intl.NumberFormat(a,t({style:"currency",currency:i,numberingSystem:"latn"},c)).format(n)}function N(e){var n=e.value,r=e.languages,a=void 0===r?[s]:r,o=e.options,i=void 0===o?{}:o;return new Intl.ListFormat(a,t({type:"conjunction",style:"long"},i)).format(n)}var w={var:"variable",num:"number",datetime:"datetime",currency:"currency"};function S(e){if("string"!=typeof e)throw new Error("splitStringToContent: ".concat(e," is not a string!"));for(var n,r=[],a=/{([^}]+)}/g,o=0;null!==(n=a.exec(e));){var i=n[0],u=n[1],c=n.index;if("^"!==e[c-1]){c>o&&r.push(e.slice(o,c));var s=u.split(",").map((function(t){return t.trim()})),l=s[0],f=s[1]?w[s[1]]:void 0,p=t({key:l},f&&{variable:f});r.push(p),o=c+i.length}else c-1>o&&r.push(e.slice(o,c-1)),r.push(i),o=c+i.length}return o<e.length&&r.push(e.slice(o)),r}function L(t,e){if(void 0===e&&(e={}),!l(t))return I;var n=new Intl.Locale(t);if(e[t=n.toString()])return e[t];var r=n.region;if(r&&x[r])return x[r];var a=n.maximize(),o=a.region||"";return T[a.language]||x[o]||I}var C="🌍",I=C,T={ca:C,eu:C,ku:C,bo:"🌏",ug:"🌏",gd:"🏴󠁧󠁢󠁳󠁣󠁴󠁿",cy:"🏴󠁧󠁢󠁷󠁬󠁳󠁿",gv:"🇮🇲",grc:"🏺"},x={AF:"🇦🇫",AX:"🇦🇽",AL:"🇦🇱",DZ:"🇩🇿",AS:"🇦🇸",AD:"🇦🇩",AO:"🇦🇴",AI:"🇦🇮",AQ:"🇦🇶",AG:"🇦🇬",AR:"🇦🇷",AM:"🇦🇲",AW:"🇦🇼",AU:"🇦🇺",AT:"🇦🇹",AZ:"🇦🇿",BS:"🇧🇸",BH:"🇧🇭",BD:"🇧🇩",BB:"🇧🇧",BY:"🇧🇾",BE:"🇧🇪",BZ:"🇧🇿",BJ:"🇧🇯",BM:"🇧🇲",BT:"🇧🇹",BO:"🇧🇴",BQ:"🇧🇶",BA:"🇧🇦",BW:"🇧🇼",BV:"🇧🇻",BR:"🇧🇷",IO:"🇮🇴",BN:"🇧🇳",BG:"🇧🇬",BF:"🇧🇫",BI:"🇧🇮",CV:"🇨🇻",KH:"🇰🇭",CM:"🇨🇲",CA:"🇨🇦",KY:"🇰🇾",CF:"🇨🇫",TD:"🇹🇩",CL:"🇨🇱",CN:"🇨🇳",CX:"🇨🇽",CC:"🇨🇨",CO:"🇨🇴",KM:"🇰🇲",CD:"🇨🇩",CG:"🇨🇬",CK:"🇨🇰",CR:"🇨🇷",CI:"🇨🇮",HR:"🇭🇷",CU:"🇨🇺",CW:"🇨🇼",CY:"🇨🇾",CZ:"🇨🇿",DK:"🇩🇰",DJ:"🇩🇯",DM:"🇩🇲",DO:"🇩🇴",EC:"🇪🇨",EG:"🇪🇬",SV:"🇸🇻",GQ:"🇬🇶",ER:"🇪🇷",EE:"🇪🇪",SZ:"🇸🇿",ET:"🇪🇹",FK:"🇫🇰",FO:"🇫🇴",FJ:"🇫🇯",FI:"🇫🇮",FR:"🇫🇷",GF:"🇬🇫",PF:"🇵🇫",TF:"🇹🇫",GA:"🇬🇦",GM:"🇬🇲",GE:"🇬🇪",DE:"🇩🇪",GH:"🇬🇭",GI:"🇬🇮",GR:"🇬🇷",GL:"🇬🇱",GD:"🇬🇩",GP:"🇬🇵",GU:"🇬🇺",GT:"🇬🇹",GG:"🇬🇬",GN:"🇬🇳",GW:"🇬🇼",GY:"🇬🇾",HT:"🇭🇹",HM:"🇭🇲",VA:"🇻🇦",HN:"🇭🇳",HK:"🇭🇰",HU:"🇭🇺",IS:"🇮🇸",IN:"🇮🇳",ID:"🇮🇩",IR:"🇮🇷",IQ:"🇮🇶",IE:"🇮🇪",IM:"🇮🇲",IL:"🇮🇱",IT:"🇮🇹",JM:"🇯🇲",JP:"🇯🇵",JE:"🇯🇪",JO:"🇯🇴",KZ:"🇰🇿",KE:"🇰🇪",KI:"🇰🇮",KP:"🇰🇵",KR:"🇰🇷",KW:"🇰🇼",KG:"🇰🇬",LA:"🇱🇦",LV:"🇱🇻",LB:"🇱🇧",LS:"🇱🇸",LR:"🇱🇷",LY:"🇱🇾",LI:"🇱🇮",LT:"🇱🇹",LU:"🇱🇺",MO:"🇲🇴",MG:"🇲🇬",MW:"🇲🇼",MY:"🇲🇾",MV:"🇲🇻",ML:"🇲🇱",MT:"🇲🇹",MH:"🇲🇭",MQ:"🇲🇶",MR:"🇲🇷",MU:"🇲🇺",YT:"🇾🇹",MX:"🇲🇽",FM:"🇫🇲",MD:"🇲🇩",MC:"🇲🇨",MN:"🇲🇳",ME:"🇲🇪",MS:"🇲🇸",MA:"🇲🇦",MZ:"🇲🇿",MM:"🇲🇲",NA:"🇳🇦",NR:"🇳🇷",NP:"🇳🇵",NL:"🇳🇱",NC:"🇳🇨",NZ:"🇳🇿",NI:"🇳🇮",NE:"🇳🇪",NG:"🇳🇬",NU:"🇳🇺",NF:"🇳🇫",MK:"🇲🇰",MP:"🇲🇵",NO:"🇳🇴",OM:"🇴🇲",PK:"🇵🇰",PW:"🇵🇼",PS:"🇵🇸",PA:"🇵🇦",PG:"🇵🇬",PY:"🇵🇾",PE:"🇵🇪",PH:"🇵🇭",PN:"🇵🇳",PL:"🇵🇱",PT:"🇵🇹",PR:"🇵🇷",QA:"🇶🇦",RE:"🇷🇪",RO:"🇷🇴",RU:"🇷🇺",RW:"🇷🇼",BL:"🇧🇱",SH:"🇸🇭",KN:"🇰🇳",LC:"🇱🇨",MF:"🇲🇫",PM:"🇵🇲",VC:"🇻🇨",WS:"🇼🇸",SM:"🇸🇲",ST:"🇸🇹",SA:"🇸🇦",SN:"🇸🇳",RS:"🇷🇸",SC:"🇸🇨",SL:"🇸🇱",SG:"🇸🇬",SX:"🇸🇽",SK:"🇸🇰",SI:"🇸🇮",SB:"🇸🇧",SO:"🇸🇴",ZA:"🇿🇦",GS:"🇬🇸",SS:"🇸🇸",ES:"🇪🇸",LK:"🇱🇰",SD:"🇸🇩",SR:"🇸🇷",SJ:"🇸🇯",SE:"🇸🇪",CH:"🇨🇭",SY:"🇸🇾",TW:"🇹🇼",TJ:"🇹🇯",TZ:"🇹🇿",TH:"🇹🇭",TL:"🇹🇱",TG:"🇹🇬",TK:"🇹🇰",TO:"🇹🇴",TT:"🇹🇹",TN:"🇹🇳",TR:"🇹🇷",TM:"🇹🇲",TC:"🇹🇨",TV:"🇹🇻",UG:"🇺🇬",UA:"🇺🇦",AE:"🇦🇪",GB:"🇬🇧",US:"🇺🇸",UM:"🇺🇲",UY:"🇺🇾",UZ:"🇺🇿",VU:"🇻🇺",VE:"🇻🇪",VN:"🇻🇳",VG:"🇻🇬",VI:"🇻🇮",WF:"🇼🇫",EH:"🇪🇭",YE:"🇾🇪",ZM:"🇿🇲",ZW:"🇿🇼"};var M=function(t){return"undefined"!=typeof process&&process.env&&process.env[t]||""},E=function(){function r(t){var e=void 0===t?{}:t,n=e.apiKey,r=void 0===n?"":n,a=e.defaultLanguage,o=void 0===a?s:a,i=e.projectID,u=void 0===i?"":i,c=e.baseURL,l=void 0===c?"https://prod.gtx.dev":c;this.apiKey=r||M("GT_API_KEY"),this.projectID=u||M("GT_PROJECT_ID"),this.defaultLanguage=o.toLowerCase(),this.baseURL=l}return r.prototype.translate=function(r,a,o){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,g(this,r,a,t({defaultLanguage:this.defaultLanguage},o))];case 1:return[2,e.sent()]}}))}))},r.prototype.translateReact=function(r,a,o){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,d(this,r,a,t({defaultLanguage:this.defaultLanguage},o))];case 1:return[2,e.sent()]}}))}))},r.prototype.translateBatch=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){return[2,c(this,t)]}))}))},r.prototype.updateProjectDictionary=function(t){return e(this,arguments,void 0,(function(t,e,r){return void 0===e&&(e=[]),void 0===r&&(r={}),n(this,(function(n){return[2,v(this,t,e,r)]}))}))},r.prototype.getProjectLanguages=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){return[2,y(this,t||this.projectID)]}))}))},r}();exports.default=E,exports.determineLanguage=function(t,e){return function(t,e){if("string"==typeof t&&(t=[t]),!e)return t[0];for(var n=function(t){var n=e.find((function(e){return e===t}));if(n)return{value:n};var r=e.find((function(e){return p(e,t)}));return r?{value:r}:void 0},r=0,a=t;r<a.length;r++){var o=n(a[r]);if("object"==typeof o)return o.value}}(t,e)},exports.formatCurrency=function(t){return b(t)},exports.formatDateTime=function(t){return h(t)},exports.formatList=function(t){return N(t)},exports.formatNum=function(t){return m(t)},exports.formatRelativeTime=function(e){return r=(n=e).value,a=n.unit,o=n.languages,i=void 0===o?[s]:o,u=n.options,c=void 0===u?{}:u,new Intl.RelativeTimeFormat(i,t({style:"long",numeric:"auto"},c)).format(r,a);var n,r,a,o,i,u,c},exports.getLanguageDirection=function(t){return function(t){var e;try{var n=new Intl.Locale(t);return"rtl"===(null===(e=null==n?void 0:n.textInfo)||void 0===e?void 0:e.direction)?"rtl":"ltr"}catch(t){return"ltr"}}(t)},exports.getLanguageEmoji=function(t,e){return L(t,e)},exports.getLanguageName=function(t,e){return function(t,e){void 0===e&&(e=s);try{var n=new Intl.DisplayNames([e,s],{type:"language"});return"string"==typeof t?n.of(t)||"":Array.isArray(t)?t.map((function(t){return n.of(t)||""})):""}catch(e){return"string"==typeof t?"":Array.isArray(t)?t.map((function(){return""})):""}}(t,e)},exports.getLanguageNames=function(t,e){return function(t,e){void 0===e&&(e=s);try{var n=new Intl.Locale(t);t=n.toString();var r=n.language,a=n.region,o=new Intl.Locale(t).maximize(),i=o.toString(),u=o.region||"",c=o.script||"",l=new Intl.Locale(t).minimize().toString(),f=new Intl.DisplayNames([e,t,s],{type:"language"}),p=new Intl.DisplayNames([t,e,s],{type:"language"}),g=f.of(t)||t,d=p.of(t)||t,v=f.of(i)||t,y=p.of(i)||t,m=f.of(l)||t,h=p.of(l)||t,b=f.of(r)||t,N=p.of(r)||t,w=a?"".concat(b," (").concat(a,")"):b,S=a?"".concat(N," (").concat(a,")"):N,C=new Intl.DisplayNames([e,t,s],{type:"region"}),I=new Intl.DisplayNames([t,e,s],{type:"region"}),T=C.of(u)||"",x=I.of(u)||"",M=new Intl.DisplayNames([e,t,s],{type:"script"}),E=new Intl.DisplayNames([t,e,s],{type:"script"});return{code:t,name:g,nativeName:d,maximizedCode:i,maximizedName:v,nativeMaximizedName:y,minimizedCode:l,minimizedName:m,nativeMinimizedName:h,languageCode:r,languageName:b,nativeLanguageName:N,nameWithRegionCode:w,nativeNameWithRegionCode:S,regionCode:u,regionName:T,nativeRegionName:x,scriptCode:c,scriptName:M.of(c)||"",nativeScriptName:E.of(c)||"",emoji:L(t)}}catch(e){t||(t="");var A=null==t?void 0:t.split("-");return{code:t,name:t,nativeName:t,maximizedCode:t,maximizedName:t,nativeMaximizedName:t,minimizedCode:t,minimizedName:t,nativeMinimizedName:t,languageCode:r=(null==A?void 0:A[0])||t||"",languageName:r,nativeLanguageName:r,regionCode:u=A.length>2?null==A?void 0:A[2]:(null==A?void 0:A[1])||"",regionName:u,nativeRegionName:u,scriptCode:c=(null==A?void 0:A[3])||"",scriptName:c,nativeScriptName:c,nameWithRegionCode:w=r?u?"".concat(r," (").concat(u,")"):r:"",nativeNameWithRegionCode:t,emoji:L(t)}}}(t,e)},exports.isSameLanguage=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return p.apply(void 0,t)},exports.isValidLanguageCode=function(t){return l(t)},exports.renderContentToString=function(e,n,r,a){return function(e,n,r,a){if(void 0===n&&(n=s),void 0===r&&(r={}),void 0===a&&(a={}),"string"==typeof e&&(e=S(e)),"string"==typeof e)return e;if(!Array.isArray(e))throw new Error("renderContentToString: content ".concat(e," is invalid"));return e.map((function(e){var o;if("string"==typeof e)return e;if("object"==typeof e){var i=r[e.key];return e.variable?"number"===e.variable?m({value:i,languages:n,options:a[e.key]}):"currency"===e.variable?b(t(t({value:i,languages:n},a[e.key]&&{options:a[e.key]}),(null===(o=a[e.key])||void 0===o?void 0:o.currency)&&{currency:a[e.key].currency})):"datetime"===e.variable?h(t({value:i,languages:n},a[e.key]&&{options:a[e.key]})):"list"===e.variable?N(t({value:i,languages:n},a[e.key]&&{options:a[e.key]})):i:i}})).join("")}(e,n,r,a)},exports.requiresTranslation=function(t,e,n){return function(t,e,n){if(!e)return!1;if(f(e)===f(t))return!1;var r=new Intl.Locale(t),a=r.language,o=r.region,i=new Intl.Locale(e),u=i.language,c=i.region;return!(!(o&&c||!p(a,u))||n&&!n.some((function(t){return p(e,t)})))}(t,e,n)},exports.splitStringToContent=function(t){return S(t)},exports.standardizeLanguageCode=function(t){return f(t)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(){return t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},t.apply(this,arguments)};function e(t,e,n,r){return new(n||(n=Promise))((function(a,o){function i(t){try{c(r.next(t))}catch(t){o(t)}}function u(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,u)}c((r=r.apply(t,e||[])).next())}))}function n(t,e){var n,r,a,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=u(0),i.throw=u(1),i.return=u(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(o=0)),o;)try{if(n=1,r&&(a=2&u[0]?r.return:u[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,u[1])).done)return a;switch(r=0,a&&(u=[2&u[0],a.value]),u[0]){case 0:case 1:a=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(a=o.trys,(a=a.length>0&&a[a.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!a||u[1]>a[0]&&u[1]<a[3])){o.label=u[1];break}if(6===u[0]&&o.label<a[1]){o.label=a[1],a=u;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(u);break}a[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],r=0}finally{n=a=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}"function"==typeof SuppressedError&&SuppressedError;var r="/v1/translate/batch",a="/v1/translate/react",o="/v1/translate/content",i="/v1/project/dictionary/update",u="/v1/project/languages";function c(t,a){return e(this,void 0,void 0,(function(){var e,o,i,u,c,s,l,f,p;return n(this,(function(n){switch(n.label){case 0:return e=new AbortController,o=e.signal,(null===(p=null===(f=null===(l=a[0])||void 0===l?void 0:l.data)||void 0===f?void 0:f.metadata)||void 0===p?void 0:p.timeout)&&setTimeout((function(){return e.abort()}),a[0].data.metadata.timeout),[4,fetch("".concat(t.baseURL).concat(r),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify(a),signal:o})];case 1:return(i=n.sent()).ok?[3,3]:(u=Error.bind,s=(c="".concat(i.status,": ")).concat,[4,i.text()]);case 2:throw new(u.apply(Error,[void 0,s.apply(c,[n.sent()])]));case 3:return[4,i.json()];case 4:return[2,n.sent()]}}))}))}var s="en",l=["Cham","Jamo","Kawi","Lisu","Toto","Thai"],f=function(t){try{var e=new Intl.Locale(t),n=e.language,r=e.region,a=e.script;if(new Intl.DisplayNames([s],{type:"language"}).of(n)===n)return!1;if(r)if(new Intl.DisplayNames([s],{type:"region"}).of(r)===r)return!1;if(a)if(new Intl.DisplayNames([s],{type:"script"}).of(a)===a&&!l.includes(a))return!1;return!0}catch(t){return!1}},p=function(t){try{return Intl.getCanonicalLocales(t)[0]}catch(t){return""}};function g(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{var n=t.flat().map((function(t){return new Intl.Locale(t).language}));return n.every((function(t){return t===n[0]}))}catch(t){return console.error(t),!1}}function d(t,r,a,i){return e(this,void 0,void 0,(function(){var e,u,c,s,l,f;return n(this,(function(n){switch(n.label){case 0:return e=new AbortController,u=e.signal,i.timeout&&setTimeout((function(){return e.abort()}),i.timeout),[4,fetch("".concat(t.baseURL).concat(o),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({content:r,targetLanguage:a,metadata:i}),signal:u})];case 1:return(c=n.sent()).ok?[3,3]:(s=Error.bind,f=(l="".concat(c.status,": ")).concat,[4,c.text()]);case 2:throw new(s.apply(Error,[void 0,f.apply(l,[n.sent()])]));case 3:return[4,c.json()];case 4:return[2,n.sent()]}}))}))}function v(t,r,o,i){return e(this,void 0,void 0,(function(){var e,u,c,s,l,f;return n(this,(function(n){switch(n.label){case 0:return e=new AbortController,u=e.signal,i.timeout&&setTimeout((function(){return e.abort()}),i.timeout),[4,fetch("".concat(t.baseURL).concat(a),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({children:r,targetLanguage:o,metadata:i}),signal:u})];case 1:return(c=n.sent()).ok?[3,3]:(s=Error.bind,f=(l="".concat(c.status,": ")).concat,[4,c.text()]);case 2:throw new(s.apply(Error,[void 0,f.apply(l,[n.sent()])]));case 3:return[4,c.json()];case 4:return[2,n.sent()]}}))}))}function y(t,r,a,o){return e(this,void 0,void 0,(function(){var e,u,c,s,l;return n(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat(t.baseURL).concat(i),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({updates:r,languages:a,options:o})})];case 1:return(e=n.sent()).ok?[3,3]:(u=Error.bind,s=(c="".concat(e.status,": ")).concat,[4,e.text()]);case 2:throw new(u.apply(Error,[void 0,s.apply(c,[n.sent()])]));case 3:return[4,e.json()];case 4:return[2,null==(l=n.sent())?void 0:l.languages]}}))}))}function m(t,r){return e(this,void 0,void 0,(function(){var e,a,o,i,c;return n(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat(t.baseURL).concat(u,"?projectID=").concat(r),{method:"GET",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey}})];case 1:return(e=n.sent()).ok?[3,3]:(a=Error.bind,i=(o="".concat(e.status,": ")).concat,[4,e.text()]);case 2:throw new(a.apply(Error,[void 0,i.apply(o,[n.sent()])]));case 3:return[4,e.json()];case 4:return[2,null==(c=n.sent())?void 0:c.languages]}}))}))}function h(e){var n=e.value,r=e.languages,a=void 0===r?[s]:r,o=e.options,i=void 0===o?{}:o;return new Intl.NumberFormat(a,t({numberingSystem:"latn"},i)).format(n)}function b(e){var n=e.value,r=e.languages,a=void 0===r?[s]:r,o=e.options,i=void 0===o?{}:o;return new Intl.DateTimeFormat(a,t({calendar:"gregory",numberingSystem:"latn"},i)).format(n)}function N(e){var n=e.value,r=e.languages,a=void 0===r?[s]:r,o=e.currency,i=void 0===o?"USD":o,u=e.options,c=void 0===u?{}:u;return new Intl.NumberFormat(a,t({style:"currency",currency:i,numberingSystem:"latn"},c)).format(n)}function w(e){var n=e.value,r=e.languages,a=void 0===r?[s]:r,o=e.options,i=void 0===o?{}:o;return new Intl.ListFormat(a,t({type:"conjunction",style:"long"},i)).format(n)}var L={var:"variable",num:"number",datetime:"datetime",currency:"currency"};function C(e){if("string"!=typeof e)throw new Error("splitStringToContent: ".concat(e," is not a string!"));for(var n,r=[],a=/{([^}]+)}/g,o=0;null!==(n=a.exec(e));){var i=n[0],u=n[1],c=n.index;if("^"!==e[c-1]){c>o&&r.push(e.slice(o,c));var s=u.split(",").map((function(t){return t.trim()})),l=s[0],f=s[1]?L[s[1]]:void 0,p=t({key:l},f&&{variable:f});r.push(p),o=c+i.length}else c-1>o&&r.push(e.slice(o,c-1)),r.push(i),o=c+i.length}return o<e.length&&r.push(e.slice(o)),r}function S(t,e){if(void 0===e&&(e={}),!f(t))return I;var n=new Intl.Locale(t);if(e[t=n.toString()])return e[t];var r=n.region;if(r&&M[r])return M[r];var a=n.maximize(),o=a.region||"";return x[a.language]||M[o]||I}var T="🌍",I=T,x={ca:T,eu:T,ku:T,bo:"🌏",ug:"🌏",gd:"🏴󠁧󠁢󠁳󠁣󠁴󠁿",cy:"🏴󠁧󠁢󠁷󠁬󠁳󠁿",gv:"🇮🇲",grc:"🏺"},M={AF:"🇦🇫",AX:"🇦🇽",AL:"🇦🇱",DZ:"🇩🇿",AS:"🇦🇸",AD:"🇦🇩",AO:"🇦🇴",AI:"🇦🇮",AQ:"🇦🇶",AG:"🇦🇬",AR:"🇦🇷",AM:"🇦🇲",AW:"🇦🇼",AU:"🇦🇺",AT:"🇦🇹",AZ:"🇦🇿",BS:"🇧🇸",BH:"🇧🇭",BD:"🇧🇩",BB:"🇧🇧",BY:"🇧🇾",BE:"🇧🇪",BZ:"🇧🇿",BJ:"🇧🇯",BM:"🇧🇲",BT:"🇧🇹",BO:"🇧🇴",BQ:"🇧🇶",BA:"🇧🇦",BW:"🇧🇼",BV:"🇧🇻",BR:"🇧🇷",IO:"🇮🇴",BN:"🇧🇳",BG:"🇧🇬",BF:"🇧🇫",BI:"🇧🇮",CV:"🇨🇻",KH:"🇰🇭",CM:"🇨🇲",CA:"🇨🇦",KY:"🇰🇾",CF:"🇨🇫",TD:"🇹🇩",CL:"🇨🇱",CN:"🇨🇳",CX:"🇨🇽",CC:"🇨🇨",CO:"🇨🇴",KM:"🇰🇲",CD:"🇨🇩",CG:"🇨🇬",CK:"🇨🇰",CR:"🇨🇷",CI:"🇨🇮",HR:"🇭🇷",CU:"🇨🇺",CW:"🇨🇼",CY:"🇨🇾",CZ:"🇨🇿",DK:"🇩🇰",DJ:"🇩🇯",DM:"🇩🇲",DO:"🇩🇴",EC:"🇪🇨",EG:"🇪🇬",SV:"🇸🇻",GQ:"🇬🇶",ER:"🇪🇷",EE:"🇪🇪",SZ:"🇸🇿",ET:"🇪🇹",FK:"🇫🇰",FO:"🇫🇴",FJ:"🇫🇯",FI:"🇫🇮",FR:"🇫🇷",GF:"🇬🇫",PF:"🇵🇫",TF:"🇹🇫",GA:"🇬🇦",GM:"🇬🇲",GE:"🇬🇪",DE:"🇩🇪",GH:"🇬🇭",GI:"🇬🇮",GR:"🇬🇷",GL:"🇬🇱",GD:"🇬🇩",GP:"🇬🇵",GU:"🇬🇺",GT:"🇬🇹",GG:"🇬🇬",GN:"🇬🇳",GW:"🇬🇼",GY:"🇬🇾",HT:"🇭🇹",HM:"🇭🇲",VA:"🇻🇦",HN:"🇭🇳",HK:"🇭🇰",HU:"🇭🇺",IS:"🇮🇸",IN:"🇮🇳",ID:"🇮🇩",IR:"🇮🇷",IQ:"🇮🇶",IE:"🇮🇪",IM:"🇮🇲",IL:"🇮🇱",IT:"🇮🇹",JM:"🇯🇲",JP:"🇯🇵",JE:"🇯🇪",JO:"🇯🇴",KZ:"🇰🇿",KE:"🇰🇪",KI:"🇰🇮",KP:"🇰🇵",KR:"🇰🇷",KW:"🇰🇼",KG:"🇰🇬",LA:"🇱🇦",LV:"🇱🇻",LB:"🇱🇧",LS:"🇱🇸",LR:"🇱🇷",LY:"🇱🇾",LI:"🇱🇮",LT:"🇱🇹",LU:"🇱🇺",MO:"🇲🇴",MG:"🇲🇬",MW:"🇲🇼",MY:"🇲🇾",MV:"🇲🇻",ML:"🇲🇱",MT:"🇲🇹",MH:"🇲🇭",MQ:"🇲🇶",MR:"🇲🇷",MU:"🇲🇺",YT:"🇾🇹",MX:"🇲🇽",FM:"🇫🇲",MD:"🇲🇩",MC:"🇲🇨",MN:"🇲🇳",ME:"🇲🇪",MS:"🇲🇸",MA:"🇲🇦",MZ:"🇲🇿",MM:"🇲🇲",NA:"🇳🇦",NR:"🇳🇷",NP:"🇳🇵",NL:"🇳🇱",NC:"🇳🇨",NZ:"🇳🇿",NI:"🇳🇮",NE:"🇳🇪",NG:"🇳🇬",NU:"🇳🇺",NF:"🇳🇫",MK:"🇲🇰",MP:"🇲🇵",NO:"🇳🇴",OM:"🇴🇲",PK:"🇵🇰",PW:"🇵🇼",PS:"🇵🇸",PA:"🇵🇦",PG:"🇵🇬",PY:"🇵🇾",PE:"🇵🇪",PH:"🇵🇭",PN:"🇵🇳",PL:"🇵🇱",PT:"🇵🇹",PR:"🇵🇷",QA:"🇶🇦",RE:"🇷🇪",RO:"🇷🇴",RU:"🇷🇺",RW:"🇷🇼",BL:"🇧🇱",SH:"🇸🇭",KN:"🇰🇳",LC:"🇱🇨",MF:"🇲🇫",PM:"🇵🇲",VC:"🇻🇨",WS:"🇼🇸",SM:"🇸🇲",ST:"🇸🇹",SA:"🇸🇦",SN:"🇸🇳",RS:"🇷🇸",SC:"🇸🇨",SL:"🇸🇱",SG:"🇸🇬",SX:"🇸🇽",SK:"🇸🇰",SI:"🇸🇮",SB:"🇸🇧",SO:"🇸🇴",ZA:"🇿🇦",GS:"🇬🇸",SS:"🇸🇸",ES:"🇪🇸",LK:"🇱🇰",SD:"🇸🇩",SR:"🇸🇷",SJ:"🇸🇯",SE:"🇸🇪",CH:"🇨🇭",SY:"🇸🇾",TW:"🇹🇼",TJ:"🇹🇯",TZ:"🇹🇿",TH:"🇹🇭",TL:"🇹🇱",TG:"🇹🇬",TK:"🇹🇰",TO:"🇹🇴",TT:"🇹🇹",TN:"🇹🇳",TR:"🇹🇷",TM:"🇹🇲",TC:"🇹🇨",TV:"🇹🇻",UG:"🇺🇬",UA:"🇺🇦",AE:"🇦🇪",GB:"🇬🇧",US:"🇺🇸",UM:"🇺🇲",UY:"🇺🇾",UZ:"🇺🇿",VU:"🇻🇺",VE:"🇻🇪",VN:"🇻🇳",VG:"🇻🇬",VI:"🇻🇮",WF:"🇼🇫",EH:"🇪🇭",YE:"🇾🇪",ZM:"🇿🇲",ZW:"🇿🇼",EU:"🇪🇺"};var E=function(t){return"undefined"!=typeof process&&process.env&&process.env[t]||""},A=function(){function r(t){var e=void 0===t?{}:t,n=e.apiKey,r=void 0===n?"":n,a=e.defaultLanguage,o=void 0===a?s:a,i=e.projectID,u=void 0===i?"":i,c=e.baseURL,l=void 0===c?"https://prod.gtx.dev":c;this.apiKey=r||E("GT_API_KEY"),this.projectID=u||E("GT_PROJECT_ID"),this.defaultLanguage=o.toLowerCase(),this.baseURL=l}return r.prototype.translate=function(r,a,o){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,d(this,r,a,t({defaultLanguage:this.defaultLanguage},o))];case 1:return[2,e.sent()]}}))}))},r.prototype.translateReact=function(r,a,o){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,v(this,r,a,t({defaultLanguage:this.defaultLanguage},o))];case 1:return[2,e.sent()]}}))}))},r.prototype.translateBatch=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){return[2,c(this,t)]}))}))},r.prototype.updateProjectDictionary=function(t){return e(this,arguments,void 0,(function(t,e,r){return void 0===e&&(e=[]),void 0===r&&(r={}),n(this,(function(n){return[2,y(this,t,e,r)]}))}))},r.prototype.getProjectLanguages=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){return[2,m(this,t||this.projectID)]}))}))},r}();exports.default=A,exports.determineLanguage=function(t,e){return function(t,e){if("string"==typeof t&&(t=[t]),!e)return t[0];for(var n=function(t){var n=e.find((function(e){return e===t}));if(n)return{value:n};var r=e.find((function(e){return g(e,t)}));return r?{value:r}:void 0},r=0,a=t;r<a.length;r++){var o=n(a[r]);if("object"==typeof o)return o.value}}(t,e)},exports.formatCurrency=function(t){return N(t)},exports.formatDateTime=function(t){return b(t)},exports.formatList=function(t){return w(t)},exports.formatNum=function(t){return h(t)},exports.formatRelativeTime=function(e){return r=(n=e).value,a=n.unit,o=n.languages,i=void 0===o?[s]:o,u=n.options,c=void 0===u?{}:u,new Intl.RelativeTimeFormat(i,t({style:"long",numeric:"auto"},c)).format(r,a);var n,r,a,o,i,u,c},exports.getLanguageDirection=function(t){return function(t){var e;try{var n=new Intl.Locale(t);return"rtl"===(null===(e=null==n?void 0:n.textInfo)||void 0===e?void 0:e.direction)?"rtl":"ltr"}catch(t){return"ltr"}}(t)},exports.getLanguageEmoji=function(t,e){return S(t,e)},exports.getLanguageName=function(t,e){return function(t,e){void 0===e&&(e=s);try{var n=new Intl.DisplayNames([e,s],{type:"language"});return"string"==typeof t?n.of(t)||"":Array.isArray(t)?t.map((function(t){return n.of(t)||""})):""}catch(e){return"string"==typeof t?"":Array.isArray(t)?t.map((function(){return""})):""}}(t,e)},exports.getLanguageNames=function(t,e){return function(t,e){void 0===e&&(e=s);try{var n=new Intl.Locale(t);t=n.toString();var r=n.language,a=n.region,o=new Intl.Locale(t).maximize(),i=o.toString(),u=o.region||"",c=o.script||"",l=new Intl.Locale(t).minimize().toString(),f=new Intl.DisplayNames([e,t,s],{type:"language"}),p=new Intl.DisplayNames([t,e,s],{type:"language"}),g=f.of(t)||t,d=p.of(t)||t,v=f.of(i)||t,y=p.of(i)||t,m=f.of(l)||t,h=p.of(l)||t,b=f.of(r)||t,N=p.of(r)||t,w=a?"".concat(b," (").concat(a,")"):b,L=a?"".concat(N," (").concat(a,")"):N,C=new Intl.DisplayNames([e,t,s],{type:"region"}),T=new Intl.DisplayNames([t,e,s],{type:"region"}),I=C.of(u)||"",x=T.of(u)||"",M=new Intl.DisplayNames([e,t,s],{type:"script"}),E=new Intl.DisplayNames([t,e,s],{type:"script"});return{code:t,name:g,nativeName:d,maximizedCode:i,maximizedName:v,nativeMaximizedName:y,minimizedCode:l,minimizedName:m,nativeMinimizedName:h,languageCode:r,languageName:b,nativeLanguageName:N,nameWithRegionCode:w,nativeNameWithRegionCode:L,regionCode:u,regionName:I,nativeRegionName:x,scriptCode:c,scriptName:M.of(c)||"",nativeScriptName:E.of(c)||"",emoji:S(t)}}catch(e){t||(t="");var A=null==t?void 0:t.split("-");return{code:t,name:t,nativeName:t,maximizedCode:t,maximizedName:t,nativeMaximizedName:t,minimizedCode:t,minimizedName:t,nativeMinimizedName:t,languageCode:r=(null==A?void 0:A[0])||t||"",languageName:r,nativeLanguageName:r,regionCode:u=A.length>2?null==A?void 0:A[2]:(null==A?void 0:A[1])||"",regionName:u,nativeRegionName:u,scriptCode:c=(null==A?void 0:A[3])||"",scriptName:c,nativeScriptName:c,nameWithRegionCode:w=r?u?"".concat(r," (").concat(u,")"):r:"",nativeNameWithRegionCode:t,emoji:S(t)}}}(t,e)},exports.isSameLanguage=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return g.apply(void 0,t)},exports.isValidLanguageCode=function(t){return f(t)},exports.renderContentToString=function(e,n,r,a){return function(e,n,r,a){if(void 0===n&&(n=s),void 0===r&&(r={}),void 0===a&&(a={}),"string"==typeof e&&(e=C(e)),"string"==typeof e)return e;if(!Array.isArray(e))throw new Error("renderContentToString: content ".concat(e," is invalid"));return e.map((function(e){var o;if("string"==typeof e)return e;if("object"==typeof e){var i=r[e.key];return e.variable?"number"===e.variable?h({value:i,languages:n,options:a[e.key]}):"currency"===e.variable?N(t(t({value:i,languages:n},a[e.key]&&{options:a[e.key]}),(null===(o=a[e.key])||void 0===o?void 0:o.currency)&&{currency:a[e.key].currency})):"datetime"===e.variable?b(t({value:i,languages:n},a[e.key]&&{options:a[e.key]})):"list"===e.variable?w(t({value:i,languages:n},a[e.key]&&{options:a[e.key]})):i:i}})).join("")}(e,n,r,a)},exports.requiresTranslation=function(t,e,n){return function(t,e,n){if(!e)return!1;if(p(e)===p(t))return!1;var r=new Intl.Locale(t),a=r.language,o=r.region,i=new Intl.Locale(e),u=i.language,c=i.region;return!(!(o&&c||!g(a,u))||n&&!n.some((function(t){return g(e,t)})))}(t,e,n)},exports.splitStringToContent=function(t){return C(t)},exports.standardizeLanguageCode=function(t){return p(t)};
2
2
  //# sourceMappingURL=index.cjs.min.cjs.map