generaltranslation 3.3.0 â 3.3.2
Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.esm.min.mjs
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var t=function(){return t=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var a in n=arguments[e])Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a]);return t},t.apply(this,arguments)};function n(t,n,e,r){return new(e||(e=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 n;t.done?a(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(i,u)}c((r=r.apply(t,n||[])).next())}))}function e(t,n){var e,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(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(o=0)),o;)try{if(e=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=n.call(t,o)}catch(t){u=[6,t],r=0}finally{e=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 n(this,void 0,void 0,(function(){var n,o,i,u,c,s,l,f,p;return e(this,(function(e){switch(e.label){case 0:return n=new AbortController,o=n.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 n.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=e.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,[e.sent()])]));case 3:return[4,i.json()];case 4:return[2,e.sent()]}}))}))}var s="en",l=function(t){try{var n=new Intl.Locale(t).maximize(),e=n.language,r=n.region,a=n.script;if(new Intl.DisplayNames([s],{type:"language"}).of(e)===e)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=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{var e=t.flat().map((function(t){return new Intl.Locale(t).language}));return e.every((function(t){return t===e[0]}))}catch(t){return console.error(t),!1}}function v(t,r,a,i){return n(this,void 0,void 0,(function(){var n,u,c,s,l,f;return e(this,(function(e){switch(e.label){case 0:return n=new AbortController,u=n.signal,i.timeout&&setTimeout((function(){return n.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=e.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,[e.sent()])]));case 3:return[4,c.json()];case 4:return[2,e.sent()]}}))}))}function d(t,r,o,i){return n(this,void 0,void 0,(function(){var n,u,c,s,l,f;return e(this,(function(e){switch(e.label){case 0:return n=new AbortController,u=n.signal,i.timeout&&setTimeout((function(){return n.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=e.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,[e.sent()])]));case 3:return[4,c.json()];case 4:return[2,e.sent()]}}))}))}function g(t,r,a,o){return n(this,void 0,void 0,(function(){var n,u,c,s,l;return e(this,(function(e){switch(e.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(n=e.sent()).ok?[3,3]:(u=Error.bind,s=(c="".concat(n.status,": ")).concat,[4,n.text()]);case 2:throw new(u.apply(Error,[void 0,s.apply(c,[e.sent()])]));case 3:return[4,n.json()];case 4:return[2,null==(l=e.sent())?void 0:l.languages]}}))}))}function y(t,r){return n(this,void 0,void 0,(function(){var n,a,o,i,c;return e(this,(function(e){switch(e.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(n=e.sent()).ok?[3,3]:(a=Error.bind,i=(o="".concat(n.status,": ")).concat,[4,n.text()]);case 2:throw new(a.apply(Error,[void 0,i.apply(o,[e.sent()])]));case 3:return[4,n.json()];case 4:return[2,null==(c=e.sent())?void 0:c.languages]}}))}))}function m(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.options,i=void 0===o?{}:o;return new Intl.NumberFormat(a,t({numberingSystem:"latn"},i)).format(e)}function h(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.options,i=void 0===o?{}:o;return new Intl.DateTimeFormat(a,t({calendar:"gregory",numberingSystem:"latn"},i)).format(e)}function b(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.currency,i=void 0===o?"USD":o,u=n.options,c=void 0===u?{}:u;return new Intl.NumberFormat(a,t({style:"currency",currency:i,numberingSystem:"latn"},c)).format(e)}function N(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.options,i=void 0===o?{}:o;return new Intl.ListFormat(a,t({type:"conjunction",style:"long"},i)).format(e)}var w={var:"variable",num:"number",datetime:"datetime",currency:"currency"};function S(n){if("string"!=typeof n)throw new Error("splitStringToContent: ".concat(n," is not a string!"));for(var e,r=[],a=/{([^}]+)}/g,o=0;null!==(e=a.exec(n));){var i=e[0],u=e[1],c=e.index;if("^"!==n[c-1]){c>o&&r.push(n.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(n.slice(o,c-1)),r.push(i),o=c+i.length}return o<n.length&&r.push(n.slice(o)),r}function I(t,n){if(void 0===n&&(n={}),!l(t))return L;var e=new Intl.Locale(t);if(n[t=e.toString()])return n[t];var r=e.region;if(r&&M[r])return M[r];var a=e.maximize(),o=a.region||"";return T[a.language]||M[o]||L}var C="đ",L=C,T={ca:C,eu:C,ku:C,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:"đżđź"};var E=function(t){return"undefined"!=typeof process&&process.env&&process.env[t]||""},A=function(){function r(t){var n=void 0===t?{}:t,e=n.apiKey,r=void 0===e?"":e,a=n.defaultLanguage,o=void 0===a?s:a,i=n.projectID,u=void 0===i?"":i,c=n.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 n(this,void 0,void 0,(function(){return e(this,(function(n){switch(n.label){case 0:return[4,v(this,r,a,t({defaultLanguage:this.defaultLanguage},o))];case 1:return[2,n.sent()]}}))}))},r.prototype.translateReact=function(r,a,o){return n(this,void 0,void 0,(function(){return e(this,(function(n){switch(n.label){case 0:return[4,d(this,r,a,t({defaultLanguage:this.defaultLanguage},o))];case 1:return[2,n.sent()]}}))}))},r.prototype.translateBatch=function(t){return n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,c(this,t)]}))}))},r.prototype.updateProjectDictionary=function(t){return n(this,arguments,void 0,(function(t,n,r){return void 0===n&&(n=[]),void 0===r&&(r={}),e(this,(function(e){return[2,g(this,t,n,r)]}))}))},r.prototype.getProjectLanguages=function(t){return n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,y(this,t||this.projectID)]}))}))},r}();function G(t){return function(t){var n;try{var e=new Intl.Locale(t);return"rtl"===(null===(n=null==e?void 0:e.textInfo)||void 0===n?void 0:n.direction)?"rtl":"ltr"}catch(t){return"ltr"}}(t)}function R(t,n){return function(t,n){void 0===n&&(n=s);try{var e=new Intl.DisplayNames([n,s],{type:"language"});return"string"==typeof t?e.of(t)||"":Array.isArray(t)?t.map((function(t){return e.of(t)||""})):""}catch(n){return"string"==typeof t?"":Array.isArray(t)?t.map((function(){return""})):""}}(t,n)}function D(t,n){return function(t,n){void 0===n&&(n=s);try{var e=new Intl.Locale(t);t=e.toString();var r=e.language,a=e.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([n,t,s],{type:"language"}),p=new Intl.DisplayNames([t,n,s],{type:"language"}),v=f.of(t)||t,d=p.of(t)||t,g=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([n,t,s],{type:"region"}),L=new Intl.DisplayNames([t,n,s],{type:"region"}),T=C.of(u)||"",M=L.of(u)||"",E=new Intl.DisplayNames([n,t,s],{type:"script"}),A=new Intl.DisplayNames([t,n,s],{type:"script"});return{code:t,name:v,nativeName:d,maximizedCode:i,maximizedName:g,nativeMaximizedName:y,minimizedCode:l,minimizedName:m,nativeMinimizedName:h,languageCode:r,languageName:b,nativeLanguageName:N,nameWithRegionCode:w,nativeNameWithRegionCode:S,regionCode:u,regionName:T,nativeRegionName:M,scriptCode:c,scriptName:E.of(c)||"",nativeScriptName:A.of(c)||"",emoji:I(t)}}catch(n){t||(t="");var G=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==G?void 0:G[0])||t||"",languageName:r,nativeLanguageName:r,regionCode:u=G.length>2?null==G?void 0:G[2]:(null==G?void 0:G[1])||"",regionName:u,nativeRegionName:u,scriptCode:c=(null==G?void 0:G[3])||"",scriptName:c,nativeScriptName:c,nameWithRegionCode:w=r?u?"".concat(r," (").concat(u,")"):r:"",nativeNameWithRegionCode:t,emoji:I(t)}}}(t,n)}function x(t,n){return I(t,n)}function P(t){return l(t)}function j(t){return f(t)}function K(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return p.apply(void 0,t)}function O(t){return m(t)}function k(t){return h(t)}function B(t){return b(t)}function U(t){return N(t)}function F(n){return r=(e=n).value,a=e.unit,o=e.languages,i=void 0===o?[s]:o,u=e.options,c=void 0===u?{}:u,new Intl.RelativeTimeFormat(i,t({style:"long",numeric:"auto"},c)).format(r,a);var e,r,a,o,i,u,c}function z(t){return S(t)}function W(n,e,r,a){return function(n,e,r,a){if(void 0===e&&(e=s),void 0===r&&(r={}),void 0===a&&(a={}),"string"==typeof n&&(n=S(n)),"string"==typeof n)return n;if(!Array.isArray(n))throw new Error("renderContentToString: content ".concat(n," is invalid"));return n.map((function(n){var o;if("string"==typeof n)return n;if("object"==typeof n){var i=r[n.key];return n.variable?"number"===n.variable?m({value:i,languages:e,options:a[n.key]}):"currency"===n.variable?b(t(t({value:i,languages:e},a[n.key]&&{options:a[n.key]}),(null===(o=a[n.key])||void 0===o?void 0:o.currency)&&{currency:a[n.key].currency})):"datetime"===n.variable?h(t({value:i,languages:e},a[n.key]&&{options:a[n.key]})):"list"===n.variable?N(t({value:i,languages:e},a[n.key]&&{options:a[n.key]})):i:i}})).join("")}(n,e,r,a)}function H(t,n){return function(t,n){if("string"==typeof t&&(t=[t]),!n)return t[0];for(var e=function(t){var e=n.find((function(n){return n===t}));if(e)return{value:e};var r=n.find((function(n){return p(n,t)}));return r?{value:r}:void 0},r=0,a=t;r<a.length;r++){var o=e(a[r]);if("object"==typeof o)return o.value}}(t,n)}function J(t,n,e){return function(t,n,e){if(!n)return!1;if(f(n)===f(t))return!1;var r=new Intl.Locale(t),a=r.language,o=r.region,i=new Intl.Locale(n),u=i.language,c=i.region;return!(!(o&&c||!p(a,u))||e&&!e.some((function(t){return p(n,t)})))}(t,n,e)}export{A as default,H as determineLanguage,B as formatCurrency,k as formatDateTime,U as formatList,O as formatNum,F as formatRelativeTime,G as getLanguageDirection,x as getLanguageEmoji,R as getLanguageName,D as getLanguageNames,K as isSameLanguage,P as isValidLanguageCode,W as renderContentToString,J as requiresTranslation,z as splitStringToContent,j as standardizeLanguageCode};
|
1
|
+
var t=function(){return t=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var a in n=arguments[e])Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a]);return t},t.apply(this,arguments)};function n(t,n,e,r){return new(e||(e=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 n;t.done?a(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(i,u)}c((r=r.apply(t,n||[])).next())}))}function e(t,n){var e,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(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(o=0)),o;)try{if(e=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=n.call(t,o)}catch(t){u=[6,t],r=0}finally{e=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 n(this,void 0,void 0,(function(){var n,o,i,u,c,s,l,f,p;return e(this,(function(e){switch(e.label){case 0:return n=new AbortController,o=n.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 n.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=e.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,[e.sent()])]));case 3:return[4,i.json()];case 4:return[2,e.sent()]}}))}))}var s="en",l=["Cham","Jamo","Kawi","Lisu","Toto","Thai"],f=function(t){try{var n=new Intl.Locale(t),e=n.language,r=n.region,a=n.script;if(new Intl.DisplayNames([s],{type:"language"}).of(e)===e)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 v(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{var e=t.flat().map((function(t){return new Intl.Locale(t).language}));return e.every((function(t){return t===e[0]}))}catch(t){return console.error(t),!1}}function d(t,r,a,i){return n(this,void 0,void 0,(function(){var n,u,c,s,l,f;return e(this,(function(e){switch(e.label){case 0:return n=new AbortController,u=n.signal,i.timeout&&setTimeout((function(){return n.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=e.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,[e.sent()])]));case 3:return[4,c.json()];case 4:return[2,e.sent()]}}))}))}function g(t,r,o,i){return n(this,void 0,void 0,(function(){var n,u,c,s,l,f;return e(this,(function(e){switch(e.label){case 0:return n=new AbortController,u=n.signal,i.timeout&&setTimeout((function(){return n.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=e.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,[e.sent()])]));case 3:return[4,c.json()];case 4:return[2,e.sent()]}}))}))}function y(t,r,a,o){return n(this,void 0,void 0,(function(){var n,u,c,s,l;return e(this,(function(e){switch(e.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(n=e.sent()).ok?[3,3]:(u=Error.bind,s=(c="".concat(n.status,": ")).concat,[4,n.text()]);case 2:throw new(u.apply(Error,[void 0,s.apply(c,[e.sent()])]));case 3:return[4,n.json()];case 4:return[2,null==(l=e.sent())?void 0:l.languages]}}))}))}function m(t,r){return n(this,void 0,void 0,(function(){var n,a,o,i,c;return e(this,(function(e){switch(e.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(n=e.sent()).ok?[3,3]:(a=Error.bind,i=(o="".concat(n.status,": ")).concat,[4,n.text()]);case 2:throw new(a.apply(Error,[void 0,i.apply(o,[e.sent()])]));case 3:return[4,n.json()];case 4:return[2,null==(c=e.sent())?void 0:c.languages]}}))}))}function h(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.options,i=void 0===o?{}:o;return new Intl.NumberFormat(a,t({numberingSystem:"latn"},i)).format(e)}function b(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.options,i=void 0===o?{}:o;return new Intl.DateTimeFormat(a,t({calendar:"gregory",numberingSystem:"latn"},i)).format(e)}function N(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.currency,i=void 0===o?"USD":o,u=n.options,c=void 0===u?{}:u;return new Intl.NumberFormat(a,t({style:"currency",currency:i,numberingSystem:"latn"},c)).format(e)}function w(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.options,i=void 0===o?{}:o;return new Intl.ListFormat(a,t({type:"conjunction",style:"long"},i)).format(e)}var S={var:"variable",num:"number",datetime:"datetime",currency:"currency"};function C(n){if("string"!=typeof n)throw new Error("splitStringToContent: ".concat(n," is not a string!"));for(var e,r=[],a=/{([^}]+)}/g,o=0;null!==(e=a.exec(n));){var i=e[0],u=e[1],c=e.index;if("^"!==n[c-1]){c>o&&r.push(n.slice(o,c));var s=u.split(",").map((function(t){return t.trim()})),l=s[0],f=s[1]?S[s[1]]:void 0,p=t({key:l},f&&{variable:f});r.push(p),o=c+i.length}else c-1>o&&r.push(n.slice(o,c-1)),r.push(i),o=c+i.length}return o<n.length&&r.push(n.slice(o)),r}function I(t,n){if(void 0===n&&(n={}),!f(t))return T;var e=new Intl.Locale(t);if(n[t=e.toString()])return n[t];var r=e.region;if(r&&E[r])return E[r];var a=e.maximize(),o=a.region||"";return M[a.language]||E[o]||T}var L="đ",T=L,M={ca:L,eu:L,ku:L,bo:"đ",ug:"đ",gd:"đ´ó §ó ˘ó łó Łó ´ó ż",cy:"đ´ó §ó ˘ó ˇó Źó łó ż",gv:"đŽđ˛",grc:"đş"},E={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 A=function(t){return"undefined"!=typeof process&&process.env&&process.env[t]||""},G=function(){function r(t){var n=void 0===t?{}:t,e=n.apiKey,r=void 0===e?"":e,a=n.defaultLanguage,o=void 0===a?s:a,i=n.projectID,u=void 0===i?"":i,c=n.baseURL,l=void 0===c?"https://prod.gtx.dev":c;this.apiKey=r||A("GT_API_KEY"),this.projectID=u||A("GT_PROJECT_ID"),this.defaultLanguage=o.toLowerCase(),this.baseURL=l}return r.prototype.translate=function(r,a,o){return n(this,void 0,void 0,(function(){return e(this,(function(n){switch(n.label){case 0:return[4,d(this,r,a,t({defaultLanguage:this.defaultLanguage},o))];case 1:return[2,n.sent()]}}))}))},r.prototype.translateReact=function(r,a,o){return n(this,void 0,void 0,(function(){return e(this,(function(n){switch(n.label){case 0:return[4,g(this,r,a,t({defaultLanguage:this.defaultLanguage},o))];case 1:return[2,n.sent()]}}))}))},r.prototype.translateBatch=function(t){return n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,c(this,t)]}))}))},r.prototype.updateProjectDictionary=function(t){return n(this,arguments,void 0,(function(t,n,r){return void 0===n&&(n=[]),void 0===r&&(r={}),e(this,(function(e){return[2,y(this,t,n,r)]}))}))},r.prototype.getProjectLanguages=function(t){return n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,m(this,t||this.projectID)]}))}))},r}();function R(t){return function(t){var n;try{var e=new Intl.Locale(t);return"rtl"===(null===(n=null==e?void 0:e.textInfo)||void 0===n?void 0:n.direction)?"rtl":"ltr"}catch(t){return"ltr"}}(t)}function D(t,n){return function(t,n){void 0===n&&(n=s);try{var e=new Intl.DisplayNames([n,s],{type:"language"});return"string"==typeof t?e.of(t)||"":Array.isArray(t)?t.map((function(t){return e.of(t)||""})):""}catch(n){return"string"==typeof t?"":Array.isArray(t)?t.map((function(){return""})):""}}(t,n)}function K(t,n){return function(t,n){void 0===n&&(n=s);try{var e=new Intl.Locale(t);t=e.toString();var r=e.language,a=e.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([n,t,s],{type:"language"}),p=new Intl.DisplayNames([t,n,s],{type:"language"}),v=f.of(t)||t,d=p.of(t)||t,g=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([n,t,s],{type:"region"}),L=new Intl.DisplayNames([t,n,s],{type:"region"}),T=C.of(u)||"",M=L.of(u)||"",E=new Intl.DisplayNames([n,t,s],{type:"script"}),A=new Intl.DisplayNames([t,n,s],{type:"script"});return{code:t,name:v,nativeName:d,maximizedCode:i,maximizedName:g,nativeMaximizedName:y,minimizedCode:l,minimizedName:m,nativeMinimizedName:h,languageCode:r,languageName:b,nativeLanguageName:N,nameWithRegionCode:w,nativeNameWithRegionCode:S,regionCode:u,regionName:T,nativeRegionName:M,scriptCode:c,scriptName:E.of(c)||"",nativeScriptName:A.of(c)||"",emoji:I(t)}}catch(n){t||(t="");var G=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==G?void 0:G[0])||t||"",languageName:r,nativeLanguageName:r,regionCode:u=G.length>2?null==G?void 0:G[2]:(null==G?void 0:G[1])||"",regionName:u,nativeRegionName:u,scriptCode:c=(null==G?void 0:G[3])||"",scriptName:c,nativeScriptName:c,nameWithRegionCode:w=r?u?"".concat(r," (").concat(u,")"):r:"",nativeNameWithRegionCode:t,emoji:I(t)}}}(t,n)}function P(t,n){return I(t,n)}function j(t){return f(t)}function x(t){return p(t)}function O(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return v.apply(void 0,t)}function k(t){return h(t)}function B(t){return b(t)}function U(t){return N(t)}function F(t){return w(t)}function W(n){return r=(e=n).value,a=e.unit,o=e.languages,i=void 0===o?[s]:o,u=e.options,c=void 0===u?{}:u,new Intl.RelativeTimeFormat(i,t({style:"long",numeric:"auto"},c)).format(r,a);var e,r,a,o,i,u,c}function z(t){return C(t)}function H(n,e,r,a){return function(n,e,r,a){if(void 0===e&&(e=s),void 0===r&&(r={}),void 0===a&&(a={}),"string"==typeof n&&(n=C(n)),"string"==typeof n)return n;if(!Array.isArray(n))throw new Error("renderContentToString: content ".concat(n," is invalid"));return n.map((function(n){var o;if("string"==typeof n)return n;if("object"==typeof n){var i=r[n.key];return n.variable?"number"===n.variable?h({value:i,languages:e,options:a[n.key]}):"currency"===n.variable?N(t(t({value:i,languages:e},a[n.key]&&{options:a[n.key]}),(null===(o=a[n.key])||void 0===o?void 0:o.currency)&&{currency:a[n.key].currency})):"datetime"===n.variable?b(t({value:i,languages:e},a[n.key]&&{options:a[n.key]})):"list"===n.variable?w(t({value:i,languages:e},a[n.key]&&{options:a[n.key]})):i:i}})).join("")}(n,e,r,a)}function J(t,n){return function(t,n){if("string"==typeof t&&(t=[t]),!n)return t[0];for(var e=function(t){var e=n.find((function(n){return n===t}));if(e)return{value:e};var r=n.find((function(n){return v(n,t)}));return r?{value:r}:void 0},r=0,a=t;r<a.length;r++){var o=e(a[r]);if("object"==typeof o)return o.value}}(t,n)}function V(t,n,e){return function(t,n,e){if(!n)return!1;if(p(n)===p(t))return!1;var r=new Intl.Locale(t),a=r.language,o=r.region,i=new Intl.Locale(n),u=i.language,c=i.region;return!(!(o&&c||!v(a,u))||e&&!e.some((function(t){return v(n,t)})))}(t,n,e)}export{G as default,J as determineLanguage,U as formatCurrency,B as formatDateTime,F as formatList,k as formatNum,W as formatRelativeTime,R as getLanguageDirection,P as getLanguageEmoji,D as getLanguageName,K as getLanguageNames,O as isSameLanguage,j as isValidLanguageCode,H as renderContentToString,V as requiresTranslation,z as splitStringToContent,x as standardizeLanguageCode};
|
2
2
|
//# sourceMappingURL=index.esm.min.mjs.map
|