generaltranslation 6.3.0 → 6.3.2-alpha.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/CHANGELOG.md +6 -0
- package/dist/index.cjs.min.cjs +1 -1
- package/dist/index.cjs.min.cjs.map +1 -1
- package/dist/index.d.ts +47 -47
- 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 +3 -0
- 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,7 +10,7 @@ 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.
|
@@ -21,7 +21,7 @@ declare class GT {
|
|
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
|
*
|
@@ -65,11 +65,11 @@ declare class GT {
|
|
65
65
|
*/
|
66
66
|
translateIcu(source: string, locale: string, metadata?: Metadata): Promise<IcuTranslationResult | TranslationError>;
|
67
67
|
/**
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
* Retrieves the display name of locale code using Intl.DisplayNames.
|
69
|
+
*
|
70
|
+
* @param {string} locale - A BCP-47 locale code.
|
71
|
+
* @returns {string} The display name corresponding to the code.
|
72
|
+
*/
|
73
73
|
getLocaleName(locale: string): string;
|
74
74
|
/**
|
75
75
|
* Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
|
@@ -77,40 +77,40 @@ declare class GT {
|
|
77
77
|
*
|
78
78
|
* @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA').
|
79
79
|
* @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
|
80
|
-
|
80
|
+
*/
|
81
81
|
getLocaleEmoji(locale: string): string;
|
82
82
|
/**
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
83
|
+
* Generates linguistic details for a given locale code.
|
84
|
+
*
|
85
|
+
* This function returns information about the locale,
|
86
|
+
* script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
|
87
|
+
* The function provides these names in both your default language and native forms, and an associated emoji.
|
88
|
+
*
|
89
|
+
* @param {string} locale - The locale code to get properties for (e.g., "de-AT").
|
90
|
+
* @returns {LocaleProperties} - An object containing detailed information about the locale.
|
91
|
+
*
|
92
|
+
* @property {string} code - The full locale code, e.g., "de-AT".
|
93
|
+
* @property {string} name - Language name in the default display language, e.g., "Austrian German".
|
94
|
+
* @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
|
95
|
+
* @property {string} languageCode - The base language code, e.g., "de".
|
96
|
+
* @property {string} languageName - The language name in the default display language, e.g., "German".
|
97
|
+
* @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
|
98
|
+
* @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
|
99
|
+
* @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
|
100
|
+
* @property {string} regionCode - The region code from maximization, e.g., "AT".
|
101
|
+
* @property {string} regionName - The region name in the default display language, e.g., "Austria".
|
102
|
+
* @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
|
103
|
+
* @property {string} scriptCode - The script code from maximization, e.g., "Latn".
|
104
|
+
* @property {string} scriptName - The script name in the default display language, e.g., "Latin".
|
105
|
+
* @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
|
106
|
+
* @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
|
107
|
+
* @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
|
108
|
+
* @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
|
109
|
+
* @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
|
110
|
+
* @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
|
111
|
+
* @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
|
112
|
+
* @property {string} emoji - The emoji associated with the locale's region, if applicable.
|
113
|
+
*/
|
114
114
|
getLocaleProperties(locale: string): LocaleProperties;
|
115
115
|
}
|
116
116
|
/**
|
@@ -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 { GT };
|
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
|