generaltranslation 3.1.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -75,11 +75,18 @@ declare class GT {
75
75
  * @param {Record<string, any>} [object] - Options, such as whether to replace the existing dictionary. Defaults to false.
76
76
  * @returns {Promise<string[]>} A promise that resolves to an array of strings indicating the languages which have been updated.
77
77
  */
78
- updateDictionary(updates: Update[], languages?: string[], options?: {
79
- replace: boolean;
80
- retranslate: boolean;
78
+ updateProjectDictionary(updates: Update[], languages?: string[], options?: {
79
+ replace?: boolean;
80
+ retranslate?: boolean;
81
+ projectID?: string;
81
82
  [key: string]: any;
82
83
  }): Promise<string[]>;
84
+ /**
85
+ * Retrieves the languages for a GT project as BCP 47 language tags.
86
+ * @param projectID - The project ID to retrieve languages for. If not provided, `this.projectID` should be set.
87
+ * @returns A promise that resolves with an array of languages.
88
+ */
89
+ getProjectLanguages(projectID?: string): Promise<string[]>;
83
90
  }
84
91
  /**
85
92
  * Get the text direction for a given language code using the Intl.Locale API.
@@ -96,6 +103,71 @@ export declare function getLanguageDirection(code: string): string;
96
103
  * @returns {string | string[]} The display name(s) corresponding to the code(s), or empty string(s) if invalid.
97
104
  */
98
105
  export declare function getLanguageName(code: string | string[], language?: string): string | string[];
106
+ /**
107
+ * Generates language details for a given locale code, providing various language-related properties.
108
+ *
109
+ * This function returns information about the language,
110
+ * script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
111
+ * The function provides these names in both your default language and native forms, and an associated emoji.
112
+ *
113
+ * @param {string} code - The locale code to get language names for (e.g., "de-AT").
114
+ * @param {string} [defaultLanguage=libraryDefaultLanguage] - The default language code for display names.
115
+ * @returns {LanguageNames} - An object containing detailed information about the language.
116
+ *
117
+ * @property {string} code - The full locale code, e.g., "de-AT".
118
+ * @property {string} name - Language name in the default display language, e.g., "Austrian German".
119
+ * @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
120
+ * @property {string} languageCode - The base language code, e.g., "de".
121
+ * @property {string} languageName - The language name in the default display language, e.g., "German".
122
+ * @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
123
+ * @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
124
+ * @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
125
+ * @property {string} regionCode - The region code from maximization, e.g., "AT".
126
+ * @property {string} regionName - The region name in the default display language, e.g., "Austria".
127
+ * @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
128
+ * @property {string} scriptCode - The script code from maximization, e.g., "Latn".
129
+ * @property {string} scriptName - The script name in the default display language, e.g., "Latin".
130
+ * @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
131
+ * @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
132
+ * @property {string} maximizedName - Maximized language name with likely script in the default language, e.g., "Austrian German (Latin)".
133
+ * @property {string} nativeMaximizedName - Maximized language name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
134
+ * @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
135
+ * @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
136
+ * @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
137
+ * @property {string} emoji - The emoji associated with the locale's region, if applicable.
138
+ */
139
+ export declare function getLanguageNames(code: string, language?: string): {
140
+ code: string;
141
+ name: string;
142
+ nativeName: string;
143
+ languageCode: string;
144
+ languageName: string;
145
+ nativeLanguageName: string;
146
+ nameWithRegionCode: string;
147
+ nativeNameWithRegionCode: string;
148
+ regionCode: string;
149
+ regionName: string;
150
+ nativeRegionName: string;
151
+ scriptCode: string;
152
+ scriptName: string;
153
+ nativeScriptName: string;
154
+ maximizedCode: string;
155
+ maximizedName: string;
156
+ nativeMaximizedName: string;
157
+ minimizedCode: string;
158
+ minimizedName: string;
159
+ nativeMinimizedName: string;
160
+ emoji: string;
161
+ };
162
+ /**
163
+ * Retrieves an emoji based on a given language code, taking into account region, language, and specific exceptions.
164
+ * This function uses the language's region (if present) to select an emoji or falls back on default emojis for certain languages.
165
+ *
166
+ * @param code - A string representing the language code (e.g., 'en', 'fr-CA').
167
+ * @param custom - An optional custom mapping of language codes to emojis.
168
+ * @returns The emoji representing the language or its region, or a default emoji if no specific match is found.
169
+ */
170
+ export declare function getLanguageEmoji(code: string, custom?: Record<string, string>): string;
99
171
  /**
100
172
  * Checks if a given BCP 47 language code is valid.
101
173
  * @param {string} code - The BCP 47 language code to validate.
@@ -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 o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},t.apply(this,arguments)};function n(t,n,e,r){return new(e||(e=Promise))((function(o,a){function i(t){try{c(r.next(t))}catch(t){a(t)}}function u(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var n;t.done?o(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,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[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]&&(a=0)),a;)try{if(e=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=n.call(t,a)}catch(t){u=[6,t],r=0}finally{e=o=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="/translate/v1/batch",o="/translate/v1/react",a="/translate/v1/content",i="/dictionaries/v1/update";function u(t,o){return n(this,void 0,void 0,(function(){var n,a,i,u,c,s,l,f,p;return e(this,(function(e){switch(e.label){case 0:return n=new AbortController,a=n.signal,(null===(p=null===(f=null===(l=o[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()}),o[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(o),signal:a})];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 c="en",s=function(t){try{return new Intl.Locale(t).toString()}catch(t){return""}};function l(){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 f(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({content: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 p(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({children: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 v(t,r,o,a){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:o,options:a})})];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(n){var e=n.value,r=n.languages,o=void 0===r?[c]:r,a=n.options,i=void 0===a?{}:a;return new Intl.NumberFormat(o,t({numberingSystem:"latn"},i)).format(e)}function d(n){var e=n.value,r=n.languages,o=void 0===r?[c]:r,a=n.options,i=void 0===a?{}:a;return new Intl.DateTimeFormat(o,t({calendar:"gregory",numberingSystem:"latn"},i)).format(e)}function g(n){var e=n.value,r=n.languages,o=void 0===r?[c]:r,a=n.currency,i=void 0===a?"USD":a,u=n.options,s=void 0===u?{}:u;return new Intl.NumberFormat(o,t({style:"currency",currency:i,numberingSystem:"latn"},s)).format(e)}function h(n){var e=n.value,r=n.languages,o=void 0===r?[c]:r,a=n.options,i=void 0===a?{}:a;return new Intl.ListFormat(o,t({type:"conjunction",style:"long"},i)).format(e)}var b={var:"variable",num:"number",datetime:"datetime",currency:"currency"};function m(n){if("string"!=typeof n)throw new Error("splitStringToContent: ".concat(n," is not a string!"));for(var e,r=[],o=/{([^}]+)}/g,a=0;null!==(e=o.exec(n));){var i=e[0],u=e[1],c=e.index;if("^"!==n[c-1]){c>a&&r.push(n.slice(a,c));var s=u.split(",").map((function(t){return t.trim()})),l=s[0],f=s[1]?b[s[1]]:void 0,p=t({key:l},f&&{variable:f});r.push(p),a=c+i.length}else c-1>a&&r.push(n.slice(a,c-1)),r.push(i),a=c+i.length}return a<n.length&&r.push(n.slice(a)),r}var w=function(t){return"undefined"!=typeof process&&process.env&&process.env[t]||""},I=function(){function r(t){var n=void 0===t?{}:t,e=n.apiKey,r=void 0===e?"":e,o=n.defaultLanguage,a=void 0===o?c:o,i=n.projectID,u=void 0===i?"":i,s=n.baseURL,l=void 0===s?"https://prod.gtx.dev":s;this.apiKey=r||w("GT_API_KEY"),this.projectID=u||w("GT_PROJECT_ID"),this.defaultLanguage=a.toLowerCase(),this.baseURL=l}return r.prototype.translate=function(r,o,a){return n(this,void 0,void 0,(function(){return e(this,(function(n){switch(n.label){case 0:return[4,f(this,r,o,t({projectID:this.projectID,defaultLanguage:this.defaultLanguage},a))];case 1:return[2,n.sent()]}}))}))},r.prototype.translateReact=function(r,o,a){return n(this,void 0,void 0,(function(){return e(this,(function(n){switch(n.label){case 0:return[4,p(this,r,o,t({projectID:this.projectID,defaultLanguage:this.defaultLanguage},a))];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,u(this,t)]}))}))},r.prototype.updateDictionary=function(t){return n(this,arguments,void 0,(function(t,n,r){return void 0===n&&(n=[]),void 0===r&&(r={replace:!1,retranslate:!1}),e(this,(function(e){return[2,v(this,t,n,r)]}))}))},r}();function k(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 j(t,n){return function(t,n){void 0===n&&(n=c);try{var e=new Intl.DisplayNames([n],{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 L(t){return function(t){try{var n=new Intl.Locale(t),e=n.language,r=n.region,o=n.script;return new Intl.DisplayNames([c],{type:"language"}).of(e)!==e&&((!r||new Intl.DisplayNames([c],{type:"region"}).of(r)!==r)&&(!o||new Intl.DisplayNames([c],{type:"script"}).of(o)!==o))}catch(t){return!1}}(t)}function S(t){return s(t)}function T(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return l.apply(void 0,t)}function x(t){return y(t)}function E(t){return d(t)}function D(t){return g(t)}function O(t){return h(t)}function C(n){return r=(e=n).value,o=e.unit,a=e.languages,i=void 0===a?[c]:a,u=e.options,s=void 0===u?{}:u,new Intl.RelativeTimeFormat(i,t({style:"long",numeric:"auto"},s)).format(r,o);var e,r,o,a,i,u,s}function A(t){return m(t)}function N(n,e,r,o){return function(n,e,r,o){if(void 0===e&&(e=c),void 0===r&&(r={}),void 0===o&&(o={}),"string"==typeof n&&(n=m(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 a;if("string"==typeof n)return n;if("object"==typeof n){var i=r[n.key];return n.variable?"number"===n.variable?y({value:i,languages:e,options:o[n.key]}):"currency"===n.variable?g(t(t({value:i,languages:e},o[n.key]&&{options:o[n.key]}),(null===(a=o[n.key])||void 0===a?void 0:a.currency)&&{currency:o[n.key].currency})):"datetime"===n.variable?d(t({value:i,languages:e},o[n.key]&&{options:o[n.key]})):"list"===n.variable?h(t({value:i,languages:e},o[n.key]&&{options:o[n.key]})):i:i}})).join("")}(n,e,r,o)}function R(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 l(n,t)}));return r?{value:r}:void 0},r=0,o=t;r<o.length;r++){var a=e(o[r]);if("object"==typeof a)return a.value}}(t,n)}function P(t,n,e){return function(t,n,e){if(!n)return!1;if(s(n)===s(t))return!1;var r=new Intl.Locale(t),o=r.language,a=r.region,i=new Intl.Locale(n),u=i.language,c=i.region;return!(!(a&&c||!l(o,u))||e&&!e.some((function(t){return l(n,t)})))}(t,n,e)}export{I as default,R as determineLanguage,D as formatCurrency,E as formatDateTime,O as formatList,x as formatNum,C as formatRelativeTime,k as getLanguageDirection,j as getLanguageName,T as isSameLanguage,L as isValidLanguageCode,N as renderContentToString,P as requiresTranslation,A as splitStringToContent,S 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=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};
2
2
  //# sourceMappingURL=index.esm.min.mjs.map