generaltranslation 6.3.1 โ 6.3.2-alpha.1
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.cjs.min.cjs +1 -1
- package/dist/index.cjs.min.cjs.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.esm.min.mjs +1 -1
- package/dist/index.esm.min.mjs.map +1 -1
- package/dist/internal.d.ts +25 -1
- package/dist/locales/customLocaleMapping.d.ts +2 -1
- package/dist/types.d.ts +2 -1
- package/package.json +12 -1
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { Content, JsxChildren, JsxTranslationResult, ContentTranslationResult, TranslationError, IcuTranslationResult, Metadata } from './types';
|
1
|
+
import { Content, JsxChildren, JsxTranslationResult, ContentTranslationResult, TranslationError, IcuTranslationResult, Metadata, CustomMapping } from './types';
|
2
2
|
import { LocaleProperties } from './locales/getLocaleProperties';
|
3
|
-
import {
|
3
|
+
import { FullCustomMapping } from './locales/customLocaleMapping';
|
4
4
|
/**
|
5
5
|
* Type representing the constructor parameters for the GT class.
|
6
6
|
*/
|
@@ -10,18 +10,18 @@ type GTConstructorParams = {
|
|
10
10
|
sourceLocale?: string;
|
11
11
|
projectId?: string;
|
12
12
|
baseUrl?: string;
|
13
|
-
customMapping?:
|
13
|
+
customMapping?: CustomMapping;
|
14
14
|
};
|
15
15
|
/**
|
16
16
|
* GT is the core driver for the General Translation library.
|
17
17
|
*/
|
18
|
-
declare class GT {
|
18
|
+
export declare class GT {
|
19
19
|
apiKey: string;
|
20
20
|
devApiKey: string;
|
21
21
|
sourceLocale: string;
|
22
22
|
projectId: string;
|
23
23
|
baseUrl: string;
|
24
|
-
customMapping:
|
24
|
+
customMapping: CustomMapping;
|
25
25
|
/**
|
26
26
|
* Constructs an instance of the GT class.
|
27
27
|
*
|
@@ -125,10 +125,10 @@ export declare function getLocaleDirection(locale: string): 'ltr' | 'rtl';
|
|
125
125
|
*
|
126
126
|
* @param {string} locale - A BCP-47 locale code.
|
127
127
|
* @param {string} [defaultLocale = 'en'] - The locale for display names.
|
128
|
-
* @param {
|
128
|
+
* @param {FullCustomMapping} [customMapping] - Optional custom mapping of locale codes to names.
|
129
129
|
* @returns {string} The display name corresponding to the code.
|
130
130
|
*/
|
131
|
-
export declare function getLocaleName(locale: string, defaultLocale?: string, customMapping?:
|
131
|
+
export declare function getLocaleName(locale: string, defaultLocale?: string, customMapping?: FullCustomMapping): string;
|
132
132
|
/**
|
133
133
|
* Generates linguistic details for a given locale code.
|
134
134
|
*
|
@@ -138,7 +138,7 @@ export declare function getLocaleName(locale: string, defaultLocale?: string, cu
|
|
138
138
|
*
|
139
139
|
* @param {string} locale - The locale code to get properties for (e.g., "de-AT").
|
140
140
|
* @param {string} [defaultLocale=libraryDefaultLocale] - The default locale code for display names.
|
141
|
-
* @param {
|
141
|
+
* @param {FullCustomMapping} [customMapping] - Optional custom mapping of locale codes to properties.
|
142
142
|
* @returns {LocaleProperties} - An object containing detailed information about the locale.
|
143
143
|
*
|
144
144
|
* @property {string} code - The full locale code, e.g., "de-AT".
|
@@ -163,7 +163,7 @@ export declare function getLocaleName(locale: string, defaultLocale?: string, cu
|
|
163
163
|
* @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "รsterreichisches Deutsch".
|
164
164
|
* @property {string} emoji - The emoji associated with the locale's region, if applicable.
|
165
165
|
*/
|
166
|
-
export declare function getLocaleProperties(locale: string, defaultLocale?: string, customMapping?:
|
166
|
+
export declare function getLocaleProperties(locale: string, defaultLocale?: string, customMapping?: FullCustomMapping): {
|
167
167
|
code: string;
|
168
168
|
name: string;
|
169
169
|
nativeName: string;
|
@@ -194,7 +194,7 @@ export declare function getLocaleProperties(locale: string, defaultLocale?: stri
|
|
194
194
|
* @param customMapping - An optional custom mapping of locale codes to emojis.
|
195
195
|
* @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
|
196
196
|
*/
|
197
|
-
export declare function getLocaleEmoji(locale: string, customMapping?:
|
197
|
+
export declare function getLocaleEmoji(locale: string, customMapping?: FullCustomMapping): string;
|
198
198
|
/**
|
199
199
|
* Checks if a given BCP 47 locale code is valid.
|
200
200
|
* @param {string} locale - The BCP 47 locale code to validate.
|
@@ -339,4 +339,4 @@ export declare function determineLocale(locales: string | string[], approvedLoca
|
|
339
339
|
* @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
|
340
340
|
*/
|
341
341
|
export declare function requiresTranslation(sourceLocale: string, targetLocale: string, approvedLocales?: string[]): boolean;
|
342
|
-
export
|
342
|
+
export {};
|
package/dist/index.esm.min.mjs
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function u(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}l((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=u(0),a.throw=u(1),a.return=u(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(l){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(i=0)),i;)try{if(n=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 i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,l])}}}"function"==typeof SuppressedError&&SuppressedError;var r=new(function(){function e(){this.cache=new Map}return e.prototype._generateKey=function(e,t,n){void 0===n&&(n={});var r=Array.isArray(t)?t.join(","):t,o=n?JSON.stringify(n,Object.keys(n).sort()):"{}";return"".concat(e,":").concat(r,":").concat(o)},e.prototype.get=function(e,t,n){void 0===n&&(n={});var r=this._generateKey(e,t,n);if(!this.cache.has(r)){var o=new Intl[e](t,n);this.cache.set(r,o)}return this.cache.get(r)},e}()),o="en",i=6e4,a=["Cham","Jamo","Kawi","Lisu","Toto","Thai"],u=function(e){try{var t=r.get("Locale",e),n=t.language,i=t.region,u=t.script;if(e.split("-").length!==(l=1,i&&(l+=1),u&&(l+=1),l))return!1;if(r.get("DisplayNames",[o],{type:"language"}).of(n)===n&&!function(e){return e>="qaa"&&e<="qtz"}(n))return!1;if(i)if(r.get("DisplayNames",[o],{type:"region"}).of(i)===i)return!1;if(u)if(r.get("DisplayNames",[o],{type:"script"}).of(u)===u&&!a.includes(u))return!1;return!0}catch(e){return!1}var l},l=function(e){try{return Intl.getCanonicalLocales(e)[0]}catch(t){return e}};function c(){for(var e,t,n,o,i,a,u,c,s,v,d=[],f=0;f<arguments.length;f++)d[f]=arguments[f];try{for(var p=d.flat().map(l),g=0;g<p.length;g++)for(var m=g+1;m<p.length;m++)if(e=p[g],t=p[m],n=void 0,o=void 0,i=void 0,a=void 0,u=void 0,c=void 0,s=void 0,v=void 0,n=r.get("Locale",e),o=n.language,i=n.region,a=n.script,u=r.get("Locale",t),c=u.language,s=u.region,v=u.script,o!==c||i&&s&&i!==s||a&&v&&a!==v)return!1;return!0}catch(e){return console.error(e),!1}}function s(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];try{var n=e.flat().map((function(e){return r.get("Locale",e).language}));return n.every((function(e){return e===n[0]}))}catch(e){return console.error(e),!1}}function v(r,o,a,u){return t(this,void 0,void 0,(function(){var t,l,c,s,v,d,f,p;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,l=t.signal,(c=Math.min((null==u?void 0:u.timeout)||i,i))&&setTimeout((function(){return t.abort()}),c),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,fetch("".concat(r.baseUrl).concat("/v1/translate/content"),{method:"POST",headers:e(e({"Content-Type":"application/json"},r.apiKey&&{"x-gt-api-key":r.apiKey}),r.devApiKey&&{"x-gt-dev-api-key":r.devApiKey}),body:JSON.stringify({source:o,targetLocale:a,metadata:u}),signal:l})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(v=n.sent())?void 0:v.name))throw new Error("Translation request timed out. This has either occured due to the translation of an unusually large request or a translation failure in the API.");throw v;case 4:return s.ok?[3,6]:(d=Error.bind,p=(f="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(d.apply(Error,[void 0,p.apply(f,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}function d(r,o,a,u){return t(this,void 0,void 0,(function(){var t,l,c,s,v,d,f,p;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,l=t.signal,(c=Math.min((null==u?void 0:u.timeout)||i,i))&&setTimeout((function(){return t.abort()}),c),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,fetch("".concat(r.baseUrl).concat("/v1/translate/react"),{method:"POST",headers:e(e({"Content-Type":"application/json"},r.apiKey&&{"x-gt-api-key":r.apiKey}),r.devApiKey&&{"x-gt-dev-api-key":r.devApiKey}),body:JSON.stringify({source:o,targetLocale:a,metadata:u}),signal:l})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(v=n.sent())?void 0:v.name))throw new Error("Translation request timed out. This has either occured due to the translation of an unusually large request or a translation failure in the API.");throw v;case 4:return s.ok?[3,6]:(d=Error.bind,p=(f="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(d.apply(Error,[void 0,p.apply(f,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}function f(r,o,a,u){return t(this,void 0,void 0,(function(){var t,l,c,s,v,d,f,p;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,l=t.signal,(c=Math.min((null==u?void 0:u.timeout)||i,i))&&setTimeout((function(){return t.abort()}),c),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,fetch("".concat(r.baseUrl).concat("/v1/translate/icu"),{method:"POST",headers:e(e({"Content-Type":"application/json"},r.apiKey&&{"x-gt-api-key":r.apiKey}),r.devApiKey&&{"x-gt-dev-api-key":r.devApiKey}),body:JSON.stringify({source:o,targetLocale:a,metadata:u}),signal:l})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(v=n.sent())?void 0:v.name))throw new Error("Translation request timed out. This has either occured due to the translation of an unusually large request or a translation failure in the API.");throw v;case 4:return s.ok?[3,6]:(d=Error.bind,p=(f="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(d.apply(Error,[void 0,p.apply(f,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}var p=function(e,t,n){if(null==e?void 0:e[t])return"string"==typeof e[t]?"name"===n?e[t]:void 0:e[t][n]};function g(e,t){try{var n=l(e),o=r.get("Locale",n),i=o.language,a=o.region;if(t)for(var u=0,c=[e,n,i];u<c.length;u++){var s=p(t,c[u],"emoji");if(s)return s}if(a&&N[a])return N[a];var v=o.maximize(),d=v.region||"";return h[v.language]||N[d]||y}catch(e){return y}}var m="๐",y=m,h={ca:m,eu:m,ku:m,bo:"๐",ug:"๐",gd:"๐ด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ",cy:"๐ด๓ ง๓ ข๓ ท๓ ฌ๓ ณ๓ ฟ",gv:"๐ฎ๐ฒ",grc:"๐บ"},N={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:"๐ช๐บ"};function b(e,t){if(t){for(var n={},r=0,o=e;r<o.length;r++){var i=t[o[r]];"string"==typeof i?n.name=i:i&&Object.assign(n,i)}return n}}function C(e,t,n){void 0===t&&(t=o),t||(t=o);try{var i=l(e),a=r.get("Locale",e),c=b([e,i,W=a.language],n),s=a.region,v=a.maximize(),d=v.toString(),f=a.region||(null==c?void 0:c.regionCode)||v.region||"",p=a.script||(null==c?void 0:c.scriptCode)||v.script||"",m=a.minimize().toString(),h=[t,e,o],N=[e,t,o],C=r.get("DisplayNames",h,{type:"language"}),S=r.get("DisplayNames",N,{type:"language"}),M=null==c?void 0:c.name,L=(null==c?void 0:c.nativeName)||(null==c?void 0:c.name),T=M||C.of(e)||e,A=L||S.of(e)||e,w=(null==c?void 0:c.maximizedName)||M||C.of(d)||e,E=(null==c?void 0:c.nativeMaximizedName)||L||S.of(d)||e,K=(null==c?void 0:c.minimizedName)||M||C.of(m)||e,O=(null==c?void 0:c.nativeMinimizedName)||L||S.of(m)||e,G=(null==c?void 0:c.languageName)||M||C.of(W)||e,x=(null==c?void 0:c.nativeLanguageName)||L||S.of(W)||e,I=s?"".concat(G," (").concat(s,")"):G,P=(s?"".concat(x," (").concat(s,")"):x)||I,R=r.get("DisplayNames",h,{type:"region"}),j=r.get("DisplayNames",N,{type:"region"}),D=(null==c?void 0:c.regionName)||(f?R.of(f):"")||"",z=(null==c?void 0:c.nativeRegionName)||(f?j.of(f):"")||"",k=r.get("DisplayNames",h,{type:"script"}),B=r.get("DisplayNames",N,{type:"script"});return{code:i,name:T,nativeName:A,maximizedCode:d,maximizedName:w,nativeMaximizedName:E,minimizedCode:m,minimizedName:K,nativeMinimizedName:O,languageCode:W,languageName:G,nativeLanguageName:x,nameWithRegionCode:I,nativeNameWithRegionCode:P,regionCode:f,regionName:D,nativeRegionName:z,scriptCode:p,scriptName:J=(null==c?void 0:c.scriptName)||(p?k.of(p):"")||"",nativeScriptName:H=(null==c?void 0:c.nativeScriptName)||(p?B.of(p):"")||"",emoji:(null==c?void 0:c.emoji)||g(i,n)}}catch(t){var U=u(e)?l(e):e,F=null==U?void 0:U.split("-"),W=(null==F?void 0:F[0])||U||"";f=F.length>2?null==F?void 0:F[2]:(null==F?void 0:F[1])||"",p=(null==F?void 0:F[3])||"";U=(null==(c=b([U,W],n))?void 0:c.code)||U;T=(null==c?void 0:c.name)||U,A=(null==c?void 0:c.nativeName)||T,d=(null==c?void 0:c.maximizedCode)||U,w=(null==c?void 0:c.maximizedName)||T,E=(null==c?void 0:c.nativeMaximizedName)||A,m=(null==c?void 0:c.minimizedCode)||U,K=(null==c?void 0:c.minimizedName)||T,O=(null==c?void 0:c.nativeMinimizedName)||A;W=(null==c?void 0:c.languageCode)||W;G=(null==c?void 0:c.languageName)||T,x=(null==c?void 0:c.nativeLanguageName)||A;f=(null==c?void 0:c.regionCode)||f;D=(null==c?void 0:c.regionName)||"",z=(null==c?void 0:c.nativeRegionName)||"";p=(null==c?void 0:c.scriptCode)||p;var J=(null==c?void 0:c.scriptName)||"",H=(null==c?void 0:c.nativeScriptName)||"";return{code:U,name:T,nativeName:A,maximizedCode:d,maximizedName:w,nativeMaximizedName:E,minimizedCode:m,minimizedName:K,nativeMinimizedName:O,languageCode:W,languageName:G,nativeLanguageName:x,nameWithRegionCode:I=(null==c?void 0:c.nameWithRegionCode)||(D?"".concat(T," (").concat(D,")"):T),nativeNameWithRegionCode:P=(null==c?void 0:c.nativeNameWithRegionCode)||(z?"".concat(A," (").concat(z,")"):A),regionCode:f,regionName:D,nativeRegionName:z,scriptCode:p,scriptName:J,nativeScriptName:H,emoji:(null==c?void 0:c.emoji)||y}}}function S(t,n){"string"==typeof t&&(t=[t]),t=t.filter(u).map(l),n=n.filter(u).map(l);for(var r=function(t){var r=n.filter((function(e){return s(t,e)})),o=function(e){for(var t=e.locale,n=e.languageCode,o=e.minimizedCode,i=e.regionCode,a=e.scriptCode,u=0,l=[t,"".concat(n,"-").concat(i),"".concat(n,"-").concat(a),o];u<l.length;u++){var c=l[u];if(r.includes(c))return c}return null},i=C(t),a=i.languageCode,u=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(i,["languageCode"]),l=o(e({locale:t,languageCode:a},u))||o(e({locale:a},C(a)));if(l)return{value:l}},o=0,i=t;o<i.length;o++){var a=r(i[o]);if("object"==typeof a)return a.value}}function M(t){var n=t.value,i=t.locales,a=void 0===i?[o]:i,u=t.options,l=void 0===u?{}:u;return r.get("NumberFormat",a,e({numberingSystem:"latn"},l)).format(n)}function L(t){var n=t.value,i=t.locales,a=void 0===i?[o]:i,u=t.options,l=void 0===u?{}:u;return r.get("DateTimeFormat",a,e({calendar:"gregory",numberingSystem:"latn"},l)).format(n)}function T(t){var n=t.value,i=t.locales,a=void 0===i?[o]:i,u=t.currency,l=void 0===u?"USD":u,c=t.options,s=void 0===c?{}:c;return r.get("NumberFormat",a,e({style:"currency",currency:l,numberingSystem:"latn"},s)).format(n)}function A(t){var n=t.value,i=t.locales,a=void 0===i?[o]:i,u=t.options,l=void 0===u?{}:u;return r.get("ListFormat",a,e({type:"conjunction",style:"long"},l)).format(n)}var w={var:"variable",num:"number",datetime:"datetime",currency:"currency"};function E(t){if("string"!=typeof t)throw new Error("splitStringToContent: ".concat(t," is not a string!"));for(var n,r=[],o=/{([^}]+)}/g,i=0;null!==(n=o.exec(t));){var a=n[0],u=n[1],l=n.index;if("^"!==t[l-1]){l>i&&r.push(t.slice(i,l));var c=u.split(",").map((function(e){return e.trim()})),s=c[0],v=c[1]?w[c[1]]:void 0,d=e({key:s},v&&{variable:v});r.push(d),i=l+a.length}else l-1>i&&r.push(t.slice(i,l-1)),r.push(a),i=l+a.length}return i<t.length&&r.push(t.slice(i)),r}function K(e,t,n){void 0===t&&(t=o),t||(t=o);try{var i=l(e);if(n)for(var a=0,u=[e,i,r.get("Locale",i).language];a<u.length;a++){var c=p(n,u[a],"name");if(c)return c}return r.get("DisplayNames",[t,i,o],{type:"language"}).of(i)||""}catch(e){return""}}var O=function(){function r(e){var t=void 0===e?{}:e,n=t.apiKey,r=void 0===n?"":n,o=t.devApiKey,i=void 0===o?"":o,a=t.sourceLocale,u=void 0===a?"":a,c=t.projectId,s=void 0===c?"":c,v=t.baseUrl,d=void 0===v?"https://api.gtx.dev":v,f=t.customMapping,p=void 0===f?{}:f;this.apiKey=r||process.env.GT_API_KEY||"",this.devApiKey=i||process.env.GT_DEV_API_KEY||"",this.projectId=s||process.env.GT_PROJECT_ID||"",this.sourceLocale=l(u)||"",this.baseUrl=d,this.customMapping=p}return r.prototype.translate=function(r,o,i){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,v(this,r,o,e({sourceLocale:this.sourceLocale},i))];case 1:return[2,t.sent()]}}))}))},r.prototype.translateJsx=function(r,o,i){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,d(this,r,o,e({sourceLocale:this.sourceLocale},i))];case 1:return[2,t.sent()]}}))}))},r.prototype.translateIcu=function(r,o,i){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,f(this,r,o,e({sourceLocale:this.sourceLocale},i))];case 1:return[2,t.sent()]}}))}))},r.prototype.getLocaleName=function(e){return K(e,this.sourceLocale,this.customMapping)},r.prototype.getLocaleEmoji=function(e){return g(e,this.customMapping)},r.prototype.getLocaleProperties=function(e){return C(e,this.sourceLocale,this.customMapping)},r}();function G(e){return function(e){var t;try{var n=r.get("Locale",e);return"rtl"===(null===(t=null==n?void 0:n.textInfo)||void 0===t?void 0:t.direction)?"rtl":"ltr"}catch(e){return"ltr"}}(e)}function x(e,t,n){return void 0===t&&(t=o),K(e,t,n)}function I(e,t,n){return C(e,t,n)}function P(e,t){return g(e,t)}function R(e){return u(e)}function j(e){return l(e)}function D(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return c.apply(void 0,e)}function z(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return s.apply(void 0,e)}function k(e,t){return function(e,t){try{var n=r.get("Locale",l(e)),o=n.language,i=n.region,a=n.script,u=r.get("Locale",l(t)),c=u.language,s=u.region,v=u.script;return!(o!==c||i&&i!==s||a&&a!==v)}catch(e){return console.error(e),!1}}(e,t)}function B(e,t){return M({value:e,locales:null==t?void 0:t.locales,options:t})}function U(e,t){return L({value:e,locales:null==t?void 0:t.locales,options:t})}function F(e,t,n){return T({value:e,currency:t,locales:null==n?void 0:n.locales,options:n})}function W(e,t){return A({value:e,locales:null==t?void 0:t.locales,options:t})}function J(t,n,i){return function(t){var n=t.value,i=t.unit,a=t.locales,u=void 0===a?[o]:a,l=t.options,c=void 0===l?{}:l;return r.get("RelativeTimeFormat",u,e({style:"long",numeric:"auto"},c)).format(n,i)}({value:t,unit:n,locales:null==i?void 0:i.locales,options:i})}function H(e){return E(e)}function V(t,n,r,i){return function(t,n,r,i){if(void 0===n&&(n=o),void 0===r&&(r={}),void 0===i&&(i={}),"string"==typeof t&&(t=E(t)),"string"==typeof t)return t;if(!Array.isArray(t))throw new Error("renderContentToString: content ".concat(t," is invalid"));return t.map((function(t){var o;if("string"==typeof t)return t;if("object"==typeof t){var a=r[t.key];return t.variable?"number"===t.variable?M({value:a,locales:n,options:i[t.key]}):"currency"===t.variable?T(e(e({value:a,locales:n},i[t.key]&&{options:i[t.key]}),(null===(o=i[t.key])||void 0===o?void 0:o.currency)&&{currency:i[t.key].currency})):"datetime"===t.variable?L(e({value:a,locales:n},i[t.key]&&{options:i[t.key]})):"list"===t.variable?A(e({value:a,locales:n},i[t.key]&&{options:i[t.key]})):a:a}})).join("")}(t,n,r,i)}function Y(e,t){return S(e,t)}function Z(e,t,n){return function(e,t,n){return!(!u(e)||!u(t)||n&&n.some((function(e){return!u(e)}))||c(e,t)||n&&!n.some((function(e){return s(t,e)})))}(e,t,n)}export{O as default,Y as determineLocale,F as formatCurrency,U as formatDateTime,W as formatList,B as formatNum,J as formatRelativeTime,G as getLocaleDirection,P as getLocaleEmoji,x as getLocaleName,I as getLocaleProperties,D as isSameDialect,z as isSameLanguage,k as isSupersetLocale,R as isValidLocale,V as renderContentToString,Z as requiresTranslation,H as splitStringToContent,j as standardizeLocale};
|
1
|
+
var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function u(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}l((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=u(0),a.throw=u(1),a.return=u(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(l){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(i=0)),i;)try{if(n=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 i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,l])}}}"function"==typeof SuppressedError&&SuppressedError;var r=new(function(){function e(){this.cache=new Map}return e.prototype._generateKey=function(e,t,n){void 0===n&&(n={});var r=Array.isArray(t)?t.join(","):t,o=n?JSON.stringify(n,Object.keys(n).sort()):"{}";return"".concat(e,":").concat(r,":").concat(o)},e.prototype.get=function(e,t,n){void 0===n&&(n={});var r=this._generateKey(e,t,n);if(!this.cache.has(r)){var o=new Intl[e](t,n);this.cache.set(r,o)}return this.cache.get(r)},e}()),o="en",i=6e4,a=["Cham","Jamo","Kawi","Lisu","Toto","Thai"],u=function(e){try{var t=r.get("Locale",e),n=t.language,i=t.region,u=t.script;if(e.split("-").length!==(l=1,i&&(l+=1),u&&(l+=1),l))return!1;if(r.get("DisplayNames",[o],{type:"language"}).of(n)===n&&!function(e){return e>="qaa"&&e<="qtz"}(n))return!1;if(i)if(r.get("DisplayNames",[o],{type:"region"}).of(i)===i)return!1;if(u)if(r.get("DisplayNames",[o],{type:"script"}).of(u)===u&&!a.includes(u))return!1;return!0}catch(e){return!1}var l},l=function(e){try{return Intl.getCanonicalLocales(e)[0]}catch(t){return e}};function c(){for(var e,t,n,o,i,a,u,c,s,v,d=[],f=0;f<arguments.length;f++)d[f]=arguments[f];try{for(var p=d.flat().map(l),g=0;g<p.length;g++)for(var m=g+1;m<p.length;m++)if(e=p[g],t=p[m],n=void 0,o=void 0,i=void 0,a=void 0,u=void 0,c=void 0,s=void 0,v=void 0,n=r.get("Locale",e),o=n.language,i=n.region,a=n.script,u=r.get("Locale",t),c=u.language,s=u.region,v=u.script,o!==c||i&&s&&i!==s||a&&v&&a!==v)return!1;return!0}catch(e){return console.error(e),!1}}function s(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];try{var n=e.flat().map((function(e){return r.get("Locale",e).language}));return n.every((function(e){return e===n[0]}))}catch(e){return console.error(e),!1}}function v(r,o,a,u){return t(this,void 0,void 0,(function(){var t,l,c,s,v,d,f,p;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,l=t.signal,(c=Math.min((null==u?void 0:u.timeout)||i,i))&&setTimeout((function(){return t.abort()}),c),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,fetch("".concat(r.baseUrl).concat("/v1/translate/content"),{method:"POST",headers:e(e({"Content-Type":"application/json"},r.apiKey&&{"x-gt-api-key":r.apiKey}),r.devApiKey&&{"x-gt-dev-api-key":r.devApiKey}),body:JSON.stringify({source:o,targetLocale:a,metadata:u}),signal:l})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(v=n.sent())?void 0:v.name))throw new Error("Translation request timed out. This has either occured due to the translation of an unusually large request or a translation failure in the API.");throw v;case 4:return s.ok?[3,6]:(d=Error.bind,p=(f="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(d.apply(Error,[void 0,p.apply(f,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}function d(r,o,a,u){return t(this,void 0,void 0,(function(){var t,l,c,s,v,d,f,p;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,l=t.signal,(c=Math.min((null==u?void 0:u.timeout)||i,i))&&setTimeout((function(){return t.abort()}),c),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,fetch("".concat(r.baseUrl).concat("/v1/translate/react"),{method:"POST",headers:e(e({"Content-Type":"application/json"},r.apiKey&&{"x-gt-api-key":r.apiKey}),r.devApiKey&&{"x-gt-dev-api-key":r.devApiKey}),body:JSON.stringify({source:o,targetLocale:a,metadata:u}),signal:l})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(v=n.sent())?void 0:v.name))throw new Error("Translation request timed out. This has either occured due to the translation of an unusually large request or a translation failure in the API.");throw v;case 4:return s.ok?[3,6]:(d=Error.bind,p=(f="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(d.apply(Error,[void 0,p.apply(f,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}function f(r,o,a,u){return t(this,void 0,void 0,(function(){var t,l,c,s,v,d,f,p;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,l=t.signal,(c=Math.min((null==u?void 0:u.timeout)||i,i))&&setTimeout((function(){return t.abort()}),c),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,fetch("".concat(r.baseUrl).concat("/v1/translate/icu"),{method:"POST",headers:e(e({"Content-Type":"application/json"},r.apiKey&&{"x-gt-api-key":r.apiKey}),r.devApiKey&&{"x-gt-dev-api-key":r.devApiKey}),body:JSON.stringify({source:o,targetLocale:a,metadata:u}),signal:l})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(v=n.sent())?void 0:v.name))throw new Error("Translation request timed out. This has either occured due to the translation of an unusually large request or a translation failure in the API.");throw v;case 4:return s.ok?[3,6]:(d=Error.bind,p=(f="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(d.apply(Error,[void 0,p.apply(f,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}var p=function(e,t,n){if(null==e?void 0:e[t])return"string"==typeof e[t]?"name"===n?e[t]:void 0:e[t][n]};function g(e,t){try{var n=l(e),o=r.get("Locale",n),i=o.language,a=o.region;if(t)for(var u=0,c=[e,n,i];u<c.length;u++){var s=p(t,c[u],"emoji");if(s)return s}if(a&&N[a])return N[a];var v=o.maximize(),d=v.region||"";return h[v.language]||N[d]||y}catch(e){return y}}var m="๐",y=m,h={ca:m,eu:m,ku:m,bo:"๐",ug:"๐",gd:"๐ด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ",cy:"๐ด๓ ง๓ ข๓ ท๓ ฌ๓ ณ๓ ฟ",gv:"๐ฎ๐ฒ",grc:"๐บ"},N={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:"๐ช๐บ"};function b(t,n){if(n){for(var r={},o=0,i=t;o<i.length;o++){var a=n[i[o]];a&&("string"==typeof a?r.name||(r.name=a):a&&(r=e(e({},a),r)))}return r}}function C(e,t,n){void 0===t&&(t=o),t||(t=o);try{var i=l(e),a=r.get("Locale",e),c=b([e,i,W=a.language],n),s=a.region,v=a.maximize(),d=v.toString(),f=a.region||(null==c?void 0:c.regionCode)||v.region||"",p=a.script||(null==c?void 0:c.scriptCode)||v.script||"",m=a.minimize().toString(),h=[t,e,o],N=[e,t,o],C=r.get("DisplayNames",h,{type:"language"}),S=r.get("DisplayNames",N,{type:"language"}),M=null==c?void 0:c.name,L=(null==c?void 0:c.nativeName)||(null==c?void 0:c.name),T=M||C.of(e)||e,A=L||S.of(e)||e,w=(null==c?void 0:c.maximizedName)||M||C.of(d)||e,E=(null==c?void 0:c.nativeMaximizedName)||L||S.of(d)||e,K=(null==c?void 0:c.minimizedName)||M||C.of(m)||e,G=(null==c?void 0:c.nativeMinimizedName)||L||S.of(m)||e,O=(null==c?void 0:c.languageName)||M||C.of(W)||e,x=(null==c?void 0:c.nativeLanguageName)||L||S.of(W)||e,I=(null==c?void 0:c.nameWithRegionCode)||s?"".concat(O," (").concat(s,")"):O,P=(null==c?void 0:c.nativeNameWithRegionCode)||(s?"".concat(x," (").concat(s,")"):x)||I,R=r.get("DisplayNames",h,{type:"region"}),j=r.get("DisplayNames",N,{type:"region"}),D=(null==c?void 0:c.regionName)||(f?R.of(f):"")||"",z=(null==c?void 0:c.nativeRegionName)||(f?j.of(f):"")||"",k=r.get("DisplayNames",h,{type:"script"}),B=r.get("DisplayNames",N,{type:"script"});return{code:i,name:T,nativeName:A,maximizedCode:d,maximizedName:w,nativeMaximizedName:E,minimizedCode:m,minimizedName:K,nativeMinimizedName:G,languageCode:W,languageName:O,nativeLanguageName:x,nameWithRegionCode:I,nativeNameWithRegionCode:P,regionCode:f,regionName:D,nativeRegionName:z,scriptCode:p,scriptName:J=(null==c?void 0:c.scriptName)||(p?k.of(p):"")||"",nativeScriptName:H=(null==c?void 0:c.nativeScriptName)||(p?B.of(p):"")||"",emoji:(null==c?void 0:c.emoji)||g(i,n)}}catch(t){var U=u(e)?l(e):e,F=null==U?void 0:U.split("-"),W=(null==F?void 0:F[0])||U||"";f=F.length>2?null==F?void 0:F[2]:(null==F?void 0:F[1])||"",p=(null==F?void 0:F[3])||"";U=(null==(c=b([U,W],n))?void 0:c.code)||U;T=(null==c?void 0:c.name)||U,A=(null==c?void 0:c.nativeName)||T,d=(null==c?void 0:c.maximizedCode)||U,w=(null==c?void 0:c.maximizedName)||T,E=(null==c?void 0:c.nativeMaximizedName)||A,m=(null==c?void 0:c.minimizedCode)||U,K=(null==c?void 0:c.minimizedName)||T,G=(null==c?void 0:c.nativeMinimizedName)||A;W=(null==c?void 0:c.languageCode)||W;O=(null==c?void 0:c.languageName)||T,x=(null==c?void 0:c.nativeLanguageName)||A;f=(null==c?void 0:c.regionCode)||f;D=(null==c?void 0:c.regionName)||"",z=(null==c?void 0:c.nativeRegionName)||"";p=(null==c?void 0:c.scriptCode)||p;var J=(null==c?void 0:c.scriptName)||"",H=(null==c?void 0:c.nativeScriptName)||"";return{code:U,name:T,nativeName:A,maximizedCode:d,maximizedName:w,nativeMaximizedName:E,minimizedCode:m,minimizedName:K,nativeMinimizedName:G,languageCode:W,languageName:O,nativeLanguageName:x,nameWithRegionCode:I=(null==c?void 0:c.nameWithRegionCode)||(D?"".concat(T," (").concat(D,")"):T),nativeNameWithRegionCode:P=(null==c?void 0:c.nativeNameWithRegionCode)||(z?"".concat(A," (").concat(z,")"):A),regionCode:f,regionName:D,nativeRegionName:z,scriptCode:p,scriptName:J,nativeScriptName:H,emoji:(null==c?void 0:c.emoji)||y}}}function S(t,n){"string"==typeof t&&(t=[t]),t=t.filter(u).map(l),n=n.filter(u).map(l);for(var r=function(t){var r=n.filter((function(e){return s(t,e)})),o=function(e){for(var t=e.locale,n=e.languageCode,o=e.minimizedCode,i=e.regionCode,a=e.scriptCode,u=0,l=[t,"".concat(n,"-").concat(i),"".concat(n,"-").concat(a),o];u<l.length;u++){var c=l[u];if(r.includes(c))return c}return null},i=C(t),a=i.languageCode,u=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(i,["languageCode"]),l=o(e({locale:t,languageCode:a},u))||o(e({locale:a},C(a)));if(l)return{value:l}},o=0,i=t;o<i.length;o++){var a=r(i[o]);if("object"==typeof a)return a.value}}function M(t){var n=t.value,i=t.locales,a=void 0===i?[o]:i,u=t.options,l=void 0===u?{}:u;return r.get("NumberFormat",a,e({numberingSystem:"latn"},l)).format(n)}function L(t){var n=t.value,i=t.locales,a=void 0===i?[o]:i,u=t.options,l=void 0===u?{}:u;return r.get("DateTimeFormat",a,e({calendar:"gregory",numberingSystem:"latn"},l)).format(n)}function T(t){var n=t.value,i=t.locales,a=void 0===i?[o]:i,u=t.currency,l=void 0===u?"USD":u,c=t.options,s=void 0===c?{}:c;return r.get("NumberFormat",a,e({style:"currency",currency:l,numberingSystem:"latn"},s)).format(n)}function A(t){var n=t.value,i=t.locales,a=void 0===i?[o]:i,u=t.options,l=void 0===u?{}:u;return r.get("ListFormat",a,e({type:"conjunction",style:"long"},l)).format(n)}var w={var:"variable",num:"number",datetime:"datetime",currency:"currency"};function E(t){if("string"!=typeof t)throw new Error("splitStringToContent: ".concat(t," is not a string!"));for(var n,r=[],o=/{([^}]+)}/g,i=0;null!==(n=o.exec(t));){var a=n[0],u=n[1],l=n.index;if("^"!==t[l-1]){l>i&&r.push(t.slice(i,l));var c=u.split(",").map((function(e){return e.trim()})),s=c[0],v=c[1]?w[c[1]]:void 0,d=e({key:s},v&&{variable:v});r.push(d),i=l+a.length}else l-1>i&&r.push(t.slice(i,l-1)),r.push(a),i=l+a.length}return i<t.length&&r.push(t.slice(i)),r}function K(e,t,n){void 0===t&&(t=o),t||(t=o);try{var i=l(e);if(n)for(var a=0,u=[e,i,r.get("Locale",i).language];a<u.length;a++){var c=p(n,u[a],"name");if(c)return c}return r.get("DisplayNames",[t,i,o],{type:"language"}).of(i)||""}catch(e){return""}}var G=function(){function r(e){var t=void 0===e?{}:e,n=t.apiKey,r=void 0===n?"":n,o=t.devApiKey,i=void 0===o?"":o,a=t.sourceLocale,u=void 0===a?"":a,c=t.projectId,s=void 0===c?"":c,v=t.baseUrl,d=void 0===v?"https://api.gtx.dev":v,f=t.customMapping,p=void 0===f?{}:f,g="undefined"!=typeof process;this.apiKey=r||g&&process.env.GT_API_KEY||"",this.devApiKey=i||g&&process.env.GT_DEV_API_KEY||"",this.projectId=s||g&&process.env.GT_PROJECT_ID||"",this.sourceLocale=l(u)||"",this.baseUrl=d,this.customMapping=p}return r.prototype.translate=function(r,o,i){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,v(this,r,o,e({sourceLocale:this.sourceLocale},i))];case 1:return[2,t.sent()]}}))}))},r.prototype.translateJsx=function(r,o,i){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,d(this,r,o,e({sourceLocale:this.sourceLocale},i))];case 1:return[2,t.sent()]}}))}))},r.prototype.translateIcu=function(r,o,i){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,f(this,r,o,e({sourceLocale:this.sourceLocale},i))];case 1:return[2,t.sent()]}}))}))},r.prototype.getLocaleName=function(e){return K(e,this.sourceLocale,this.customMapping)},r.prototype.getLocaleEmoji=function(e){return g(e,this.customMapping)},r.prototype.getLocaleProperties=function(e){return C(e,this.sourceLocale,this.customMapping)},r}();function O(e){return function(e){var t;try{var n=r.get("Locale",e);return"rtl"===(null===(t=null==n?void 0:n.textInfo)||void 0===t?void 0:t.direction)?"rtl":"ltr"}catch(e){return"ltr"}}(e)}function x(e,t,n){return void 0===t&&(t=o),K(e,t,n)}function I(e,t,n){return C(e,t,n)}function P(e,t){return g(e,t)}function R(e){return u(e)}function j(e){return l(e)}function D(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return c.apply(void 0,e)}function z(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return s.apply(void 0,e)}function k(e,t){return function(e,t){try{var n=r.get("Locale",l(e)),o=n.language,i=n.region,a=n.script,u=r.get("Locale",l(t)),c=u.language,s=u.region,v=u.script;return!(o!==c||i&&i!==s||a&&a!==v)}catch(e){return console.error(e),!1}}(e,t)}function B(e,t){return M({value:e,locales:null==t?void 0:t.locales,options:t})}function U(e,t){return L({value:e,locales:null==t?void 0:t.locales,options:t})}function F(e,t,n){return T({value:e,currency:t,locales:null==n?void 0:n.locales,options:n})}function W(e,t){return A({value:e,locales:null==t?void 0:t.locales,options:t})}function J(t,n,i){return function(t){var n=t.value,i=t.unit,a=t.locales,u=void 0===a?[o]:a,l=t.options,c=void 0===l?{}:l;return r.get("RelativeTimeFormat",u,e({style:"long",numeric:"auto"},c)).format(n,i)}({value:t,unit:n,locales:null==i?void 0:i.locales,options:i})}function H(e){return E(e)}function V(t,n,r,i){return function(t,n,r,i){if(void 0===n&&(n=o),void 0===r&&(r={}),void 0===i&&(i={}),"string"==typeof t&&(t=E(t)),"string"==typeof t)return t;if(!Array.isArray(t))throw new Error("renderContentToString: content ".concat(t," is invalid"));return t.map((function(t){var o;if("string"==typeof t)return t;if("object"==typeof t){var a=r[t.key];return t.variable?"number"===t.variable?M({value:a,locales:n,options:i[t.key]}):"currency"===t.variable?T(e(e({value:a,locales:n},i[t.key]&&{options:i[t.key]}),(null===(o=i[t.key])||void 0===o?void 0:o.currency)&&{currency:i[t.key].currency})):"datetime"===t.variable?L(e({value:a,locales:n},i[t.key]&&{options:i[t.key]})):"list"===t.variable?A(e({value:a,locales:n},i[t.key]&&{options:i[t.key]})):a:a}})).join("")}(t,n,r,i)}function Y(e,t){return S(e,t)}function Z(e,t,n){return function(e,t,n){return!(!u(e)||!u(t)||n&&n.some((function(e){return!u(e)}))||c(e,t)||n&&!n.some((function(e){return s(t,e)})))}(e,t,n)}export{G as GT,Y as determineLocale,F as formatCurrency,U as formatDateTime,W as formatList,B as formatNum,J as formatRelativeTime,O as getLocaleDirection,P as getLocaleEmoji,x as getLocaleName,I as getLocaleProperties,D as isSameDialect,z as isSameLanguage,k as isSupersetLocale,R as isValidLocale,V as renderContentToString,Z as requiresTranslation,H as splitStringToContent,j as standardizeLocale};
|
2
2
|
//# sourceMappingURL=index.esm.min.mjs.map
|