generaltranslation 6.2.10 → 6.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/CHANGELOG.md +10 -0
- package/dist/index.cjs.min.cjs +1 -1
- package/dist/index.cjs.min.cjs.map +1 -1
- package/dist/index.d.ts +61 -7
- package/dist/index.esm.min.mjs +1 -1
- package/dist/index.esm.min.mjs.map +1 -1
- package/dist/locales/customLocaleMapping.d.ts +3 -0
- package/dist/locales/getLocaleProperties.d.ts +23 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
import { Content, JsxChildren, JsxTranslationResult, ContentTranslationResult, TranslationError, IcuTranslationResult, Metadata } from './types';
|
2
|
+
import { LocaleProperties } from './locales/getLocaleProperties';
|
3
|
+
import { CustomMapping } from './locales/customLocaleMapping';
|
2
4
|
/**
|
3
5
|
* Type representing the constructor parameters for the GT class.
|
4
6
|
*/
|
@@ -8,6 +10,7 @@ type GTConstructorParams = {
|
|
8
10
|
sourceLocale?: string;
|
9
11
|
projectId?: string;
|
10
12
|
baseUrl?: string;
|
13
|
+
customMapping?: Record<string, LocaleProperties | string>;
|
11
14
|
};
|
12
15
|
/**
|
13
16
|
* GT is the core driver for the General Translation library.
|
@@ -18,6 +21,7 @@ declare class GT {
|
|
18
21
|
sourceLocale: string;
|
19
22
|
projectId: string;
|
20
23
|
baseUrl: string;
|
24
|
+
customMapping: Record<string, LocaleProperties | string>;
|
21
25
|
/**
|
22
26
|
* Constructs an instance of the GT class.
|
23
27
|
*
|
@@ -27,7 +31,7 @@ declare class GT {
|
|
27
31
|
* @param {string} [params.projectId=''] - The project ID for the translation service.
|
28
32
|
* @param {string} [params.baseUrl='https://api.gtx.dev'] - The base URL for the translation service.
|
29
33
|
*/
|
30
|
-
constructor({ apiKey, devApiKey, sourceLocale, projectId, baseUrl, }?: GTConstructorParams);
|
34
|
+
constructor({ apiKey, devApiKey, sourceLocale, projectId, baseUrl, customMapping, }?: GTConstructorParams);
|
31
35
|
/**
|
32
36
|
* Translates a string or an array of strings/variables into a target locale.
|
33
37
|
*
|
@@ -60,11 +64,59 @@ declare class GT {
|
|
60
64
|
* @returns {Promise<ContentTranslationResult | TranslationError>} A promise that resolves to the translated content, or an error if the translation fails.
|
61
65
|
*/
|
62
66
|
translateIcu(source: string, locale: string, metadata?: Metadata): Promise<IcuTranslationResult | TranslationError>;
|
67
|
+
/**
|
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
|
+
getLocaleName(locale: string): string;
|
74
|
+
/**
|
75
|
+
* Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
|
76
|
+
* This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
|
77
|
+
*
|
78
|
+
* @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA').
|
79
|
+
* @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
|
80
|
+
*/
|
81
|
+
getLocaleEmoji(locale: string): string;
|
82
|
+
/**
|
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
|
+
getLocaleProperties(locale: string): LocaleProperties;
|
63
115
|
}
|
64
116
|
/**
|
65
117
|
* Get the text direction for a given locale code using the Intl.Locale API.
|
66
118
|
*
|
67
|
-
* @param
|
119
|
+
* @param locale - A BCP-47 locale code.
|
68
120
|
* @returns {string} - 'rtl' if the locale is right-to-left, otherwise 'ltr'.
|
69
121
|
*/
|
70
122
|
export declare function getLocaleDirection(locale: string): 'ltr' | 'rtl';
|
@@ -73,9 +125,10 @@ export declare function getLocaleDirection(locale: string): 'ltr' | 'rtl';
|
|
73
125
|
*
|
74
126
|
* @param {string} locale - A BCP-47 locale code.
|
75
127
|
* @param {string} [defaultLocale = 'en'] - The locale for display names.
|
128
|
+
* @param {CustomMapping} [customMapping] - Optional custom mapping of locale codes to names.
|
76
129
|
* @returns {string} The display name corresponding to the code.
|
77
130
|
*/
|
78
|
-
export declare function getLocaleName(locale: string, defaultLocale?: string): string;
|
131
|
+
export declare function getLocaleName(locale: string, defaultLocale?: string, customMapping?: CustomMapping): string;
|
79
132
|
/**
|
80
133
|
* Generates linguistic details for a given locale code.
|
81
134
|
*
|
@@ -85,6 +138,7 @@ export declare function getLocaleName(locale: string, defaultLocale?: string): s
|
|
85
138
|
*
|
86
139
|
* @param {string} locale - The locale code to get properties for (e.g., "de-AT").
|
87
140
|
* @param {string} [defaultLocale=libraryDefaultLocale] - The default locale code for display names.
|
141
|
+
* @param {CustomMapping} [customMapping] - Optional custom mapping of locale codes to properties.
|
88
142
|
* @returns {LocaleProperties} - An object containing detailed information about the locale.
|
89
143
|
*
|
90
144
|
* @property {string} code - The full locale code, e.g., "de-AT".
|
@@ -109,7 +163,7 @@ export declare function getLocaleName(locale: string, defaultLocale?: string): s
|
|
109
163
|
* @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
|
110
164
|
* @property {string} emoji - The emoji associated with the locale's region, if applicable.
|
111
165
|
*/
|
112
|
-
export declare function getLocaleProperties(locale: string, defaultLocale?: string): {
|
166
|
+
export declare function getLocaleProperties(locale: string, defaultLocale?: string, customMapping?: CustomMapping): {
|
113
167
|
code: string;
|
114
168
|
name: string;
|
115
169
|
nativeName: string;
|
@@ -136,11 +190,11 @@ export declare function getLocaleProperties(locale: string, defaultLocale?: stri
|
|
136
190
|
* Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
|
137
191
|
* This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
|
138
192
|
*
|
139
|
-
* @param
|
140
|
-
* @param
|
193
|
+
* @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA').
|
194
|
+
* @param customMapping - An optional custom mapping of locale codes to emojis.
|
141
195
|
* @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
|
142
196
|
*/
|
143
|
-
export declare function getLocaleEmoji(locale: string,
|
197
|
+
export declare function getLocaleEmoji(locale: string, customMapping?: CustomMapping): string;
|
144
198
|
/**
|
145
199
|
* Checks if a given BCP 47 locale code is valid.
|
146
200
|
* @param {string} locale - The BCP 47 locale code to validate.
|
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,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function c(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,c)}u((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,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=c(0),i.throw=c(1),i.return=c(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(u){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}}"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",a=6e4,i=["Cham","Jamo","Kawi","Lisu","Toto","Thai"],c=function(e){try{var t=r.get("Locale",e),n=t.language,a=t.region,c=t.script;if(e.split("-").length!==(u=1,a&&(u+=1),c&&(u+=1),u))return!1;if(r.get("DisplayNames",[o],{type:"language"}).of(n)===n&&!function(e){return e>="qaa"&&e<="qtz"}(n))return!1;if(a)if(r.get("DisplayNames",[o],{type:"region"}).of(a)===a)return!1;if(c)if(r.get("DisplayNames",[o],{type:"script"}).of(c)===c&&!i.includes(c))return!1;return!0}catch(e){return!1}var u},u=function(e){try{return Intl.getCanonicalLocales(e)[0]}catch(t){return e}};function l(){for(var e,t,n,o,a,i,c,l,s,f,v=[],p=0;p<arguments.length;p++)v[p]=arguments[p];try{for(var d=v.flat().map(u),g=0;g<d.length;g++)for(var y=g+1;y<d.length;y++)if(e=d[g],t=d[y],n=void 0,o=void 0,a=void 0,i=void 0,c=void 0,l=void 0,s=void 0,f=void 0,n=r.get("Locale",e),o=n.language,a=n.region,i=n.script,c=r.get("Locale",t),l=c.language,s=c.region,f=c.script,o!==l||a&&s&&a!==s||i&&f&&i!==f)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 f(r,o,i,c){return t(this,void 0,void 0,(function(){var t,u,l,s,f,v,p,d;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,u=t.signal,(l=Math.min((null==c?void 0:c.timeout)||a,a))&&setTimeout((function(){return t.abort()}),l),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:i,metadata:c}),signal:u})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(f=n.sent())?void 0:f.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 f;case 4:return s.ok?[3,6]:(v=Error.bind,d=(p="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(v.apply(Error,[void 0,d.apply(p,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}function v(r,o,i,c){return t(this,void 0,void 0,(function(){var t,u,l,s,f,v,p,d;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,u=t.signal,(l=Math.min((null==c?void 0:c.timeout)||a,a))&&setTimeout((function(){return t.abort()}),l),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:i,metadata:c}),signal:u})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(f=n.sent())?void 0:f.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 f;case 4:return s.ok?[3,6]:(v=Error.bind,d=(p="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(v.apply(Error,[void 0,d.apply(p,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}function p(r,o,i,c){return t(this,void 0,void 0,(function(){var t,u,l,s,f,v,p,d;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,u=t.signal,(l=Math.min((null==c?void 0:c.timeout)||a,a))&&setTimeout((function(){return t.abort()}),l),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:i,metadata:c}),signal:u})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(f=n.sent())?void 0:f.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 f;case 4:return s.ok?[3,6]:(v=Error.bind,d=(p="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(v.apply(Error,[void 0,d.apply(p,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}function d(e,t){if(void 0===t&&(t={}),!c(e))return y;if(t[e=u(e)])return t[e];var n=r.get("Locale",e),o=n.region;if(o&&m[o])return m[o];var a=n.maximize(),i=a.region||"";return h[a.language]||m[i]||y}var g="🌍",y=g,h={ca:g,eu:g,ku:g,bo:"🌏",ug:"🌏",gd:"🏴",cy:"🏴",gv:"🇮🇲",grc:"🏺"},m={AF:"🇦🇫",AX:"🇦🇽",AL:"🇦🇱",DZ:"🇩🇿",AS:"🇦🇸",AD:"🇦🇩",AO:"🇦🇴",AI:"🇦🇮",AQ:"🇦🇶",AG:"🇦🇬",AR:"🇦🇷",AM:"🇦🇲",AW:"🇦🇼",AU:"🇦🇺",AT:"🇦🇹",AZ:"🇦🇿",BS:"🇧🇸",BH:"🇧🇭",BD:"🇧🇩",BB:"🇧🇧",BY:"🇧🇾",BE:"🇧🇪",BZ:"🇧🇿",BJ:"🇧🇯",BM:"🇧🇲",BT:"🇧🇹",BO:"🇧🇴",BQ:"🇧🇶",BA:"🇧🇦",BW:"🇧🇼",BV:"🇧🇻",BR:"🇧🇷",IO:"🇮🇴",BN:"🇧🇳",BG:"🇧🇬",BF:"🇧🇫",BI:"🇧🇮",CV:"🇨🇻",KH:"🇰🇭",CM:"🇨🇲",CA:"🇨🇦",KY:"🇰🇾",CF:"🇨🇫",TD:"🇹🇩",CL:"🇨🇱",CN:"🇨🇳",CX:"🇨🇽",CC:"🇨🇨",CO:"🇨🇴",KM:"🇰🇲",CD:"🇨🇩",CG:"🇨🇬",CK:"🇨🇰",CR:"🇨🇷",CI:"🇨🇮",HR:"🇭🇷",CU:"🇨🇺",CW:"🇨🇼",CY:"🇨🇾",CZ:"🇨🇿",DK:"🇩🇰",DJ:"🇩🇯",DM:"🇩🇲",DO:"🇩🇴",EC:"🇪🇨",EG:"🇪🇬",SV:"🇸🇻",GQ:"🇬🇶",ER:"🇪🇷",EE:"🇪🇪",SZ:"🇸🇿",ET:"🇪🇹",FK:"🇫🇰",FO:"🇫🇴",FJ:"🇫🇯",FI:"🇫🇮",FR:"🇫🇷",GF:"🇬🇫",PF:"🇵🇫",TF:"🇹🇫",GA:"🇬🇦",GM:"🇬🇲",GE:"🇬🇪",DE:"🇩🇪",GH:"🇬🇭",GI:"🇬🇮",GR:"🇬🇷",GL:"🇬🇱",GD:"🇬🇩",GP:"🇬🇵",GU:"🇬🇺",GT:"🇬🇹",GG:"🇬🇬",GN:"🇬🇳",GW:"🇬🇼",GY:"🇬🇾",HT:"🇭🇹",HM:"🇭🇲",VA:"🇻🇦",HN:"🇭🇳",HK:"🇭🇰",HU:"🇭🇺",IS:"🇮🇸",IN:"🇮🇳",ID:"🇮🇩",IR:"🇮🇷",IQ:"🇮🇶",IE:"🇮🇪",IM:"🇮🇲",IL:"🇮🇱",IT:"🇮🇹",JM:"🇯🇲",JP:"🇯🇵",JE:"🇯🇪",JO:"🇯🇴",KZ:"🇰🇿",KE:"🇰🇪",KI:"🇰🇮",KP:"🇰🇵",KR:"🇰🇷",KW:"🇰🇼",KG:"🇰🇬",LA:"🇱🇦",LV:"🇱🇻",LB:"🇱🇧",LS:"🇱🇸",LR:"🇱🇷",LY:"🇱🇾",LI:"🇱🇮",LT:"🇱🇹",LU:"🇱🇺",MO:"🇲🇴",MG:"🇲🇬",MW:"🇲🇼",MY:"🇲🇾",MV:"🇲🇻",ML:"🇲🇱",MT:"🇲🇹",MH:"🇲🇭",MQ:"🇲🇶",MR:"🇲🇷",MU:"🇲🇺",YT:"🇾🇹",MX:"🇲🇽",FM:"🇫🇲",MD:"🇲🇩",MC:"🇲🇨",MN:"🇲🇳",ME:"🇲🇪",MS:"🇲🇸",MA:"🇲🇦",MZ:"🇲🇿",MM:"🇲🇲",NA:"🇳🇦",NR:"🇳🇷",NP:"🇳🇵",NL:"🇳🇱",NC:"🇳🇨",NZ:"🇳🇿",NI:"🇳🇮",NE:"🇳🇪",NG:"🇳🇬",NU:"🇳🇺",NF:"🇳🇫",MK:"🇲🇰",MP:"🇲🇵",NO:"🇳🇴",OM:"🇴🇲",PK:"🇵🇰",PW:"🇵🇼",PS:"🇵🇸",PA:"🇵🇦",PG:"🇵🇬",PY:"🇵🇾",PE:"🇵🇪",PH:"🇵🇭",PN:"🇵🇳",PL:"🇵🇱",PT:"🇵🇹",PR:"🇵🇷",QA:"🇶🇦",RE:"🇷🇪",RO:"🇷🇴",RU:"🇷🇺",RW:"🇷🇼",BL:"🇧🇱",SH:"🇸🇭",KN:"🇰🇳",LC:"🇱🇨",MF:"🇲🇫",PM:"🇵🇲",VC:"🇻🇨",WS:"🇼🇸",SM:"🇸🇲",ST:"🇸🇹",SA:"🇸🇦",SN:"🇸🇳",RS:"🇷🇸",SC:"🇸🇨",SL:"🇸🇱",SG:"🇸🇬",SX:"🇸🇽",SK:"🇸🇰",SI:"🇸🇮",SB:"🇸🇧",SO:"🇸🇴",ZA:"🇿🇦",GS:"🇬🇸",SS:"🇸🇸",ES:"🇪🇸",LK:"🇱🇰",SD:"🇸🇩",SR:"🇸🇷",SJ:"🇸🇯",SE:"🇸🇪",CH:"🇨🇭",SY:"🇸🇾",TW:"🇹🇼",TJ:"🇹🇯",TZ:"🇹🇿",TH:"🇹🇭",TL:"🇹🇱",TG:"🇹🇬",TK:"🇹🇰",TO:"🇹🇴",TT:"🇹🇹",TN:"🇹🇳",TR:"🇹🇷",TM:"🇹🇲",TC:"🇹🇨",TV:"🇹🇻",UG:"🇺🇬",UA:"🇺🇦",AE:"🇦🇪",GB:"🇬🇧",US:"🇺🇸",UM:"🇺🇲",UY:"🇺🇾",UZ:"🇺🇿",VU:"🇻🇺",VE:"🇻🇪",VN:"🇻🇳",VG:"🇻🇬",VI:"🇻🇮",WF:"🇼🇫",EH:"🇪🇭",YE:"🇾🇪",ZM:"🇿🇲",ZW:"🇿🇼",EU:"🇪🇺"};function b(e,t){void 0===t&&(t=o);try{e=u(e);var n=r.get("Locale",e),a=n.language,i=n.region,c=n.maximize(),l=c.toString(),s=c.region||"",f=c.script||"",v=n.minimize().toString(),p=r.get("DisplayNames",[t,e,o],{type:"language"}),g=r.get("DisplayNames",[e,t,o],{type:"language"}),y=p.of(e)||e,h=g.of(e)||e,m=p.of(l)||e,b=g.of(l)||e,N=p.of(v)||e,C=g.of(v)||e,S=p.of(a)||e,T=g.of(a)||e,A=i?"".concat(S," (").concat(i,")"):S,M=i?"".concat(T," (").concat(i,")"):T,w=r.get("DisplayNames",[t,e,o],{type:"region"}),L=r.get("DisplayNames",[e,t,o],{type:"region"}),E=w.of(s)||"",K=L.of(s)||"",G=r.get("DisplayNames",[t,e,o],{type:"script"}),O=r.get("DisplayNames",[e,t,o],{type:"script"});return{code:e,name:y,nativeName:h,maximizedCode:l,maximizedName:m,nativeMaximizedName:b,minimizedCode:v,minimizedName:N,nativeMinimizedName:C,languageCode:a,languageName:S,nativeLanguageName:T,nameWithRegionCode:A,nativeNameWithRegionCode:M,regionCode:s,regionName:E,nativeRegionName:K,scriptCode:f,scriptName:G.of(f)||"",nativeScriptName:O.of(f)||"",emoji:d(e)}}catch(t){var I=e||"",P=null==I?void 0:I.split("-");return{code:I,name:I,nativeName:I,maximizedCode:I,maximizedName:I,nativeMaximizedName:I,minimizedCode:I,minimizedName:I,nativeMinimizedName:I,languageCode:a=(null==P?void 0:P[0])||I||"",languageName:a,nativeLanguageName:a,regionCode:s=P.length>2?null==P?void 0:P[2]:(null==P?void 0:P[1])||"",regionName:s,nativeRegionName:s,scriptCode:f=(null==P?void 0:P[3])||"",scriptName:f,nativeScriptName:f,nameWithRegionCode:A=a?s?"".concat(a," (").concat(s,")"):a:"",nativeNameWithRegionCode:I,emoji:d(I)}}}function N(t,n){"string"==typeof t&&(t=[t]),t=t.filter(c).map(u),n=n.filter(c).map(u);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,a=e.regionCode,i=e.scriptCode,c=0,u=[t,"".concat(n,"-").concat(a),"".concat(n,"-").concat(i),o];c<u.length;c++){var l=u[c];if(r.includes(l))return l}return null},a=b(t),i=a.languageCode,c=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}(a,["languageCode"]),u=o(e({locale:t,languageCode:i},c))||o(e({locale:i},b(i)));if(u)return{value:u}},o=0,a=t;o<a.length;o++){var i=r(a[o]);if("object"==typeof i)return i.value}}function C(t){var n=t.value,a=t.locales,i=void 0===a?[o]:a,c=t.options,u=void 0===c?{}:c;return r.get("NumberFormat",i,e({numberingSystem:"latn"},u)).format(n)}function S(t){var n=t.value,a=t.locales,i=void 0===a?[o]:a,c=t.options,u=void 0===c?{}:c;return r.get("DateTimeFormat",i,e({calendar:"gregory",numberingSystem:"latn"},u)).format(n)}function T(t){var n=t.value,a=t.locales,i=void 0===a?[o]:a,c=t.currency,u=void 0===c?"USD":c,l=t.options,s=void 0===l?{}:l;return r.get("NumberFormat",i,e({style:"currency",currency:u,numberingSystem:"latn"},s)).format(n)}function A(t){var n=t.value,a=t.locales,i=void 0===a?[o]:a,c=t.options,u=void 0===c?{}:c;return r.get("ListFormat",i,e({type:"conjunction",style:"long"},u)).format(n)}var M={var:"variable",num:"number",datetime:"datetime",currency:"currency"};function w(t){if("string"!=typeof t)throw new Error("splitStringToContent: ".concat(t," is not a string!"));for(var n,r=[],o=/{([^}]+)}/g,a=0;null!==(n=o.exec(t));){var i=n[0],c=n[1],u=n.index;if("^"!==t[u-1]){u>a&&r.push(t.slice(a,u));var l=c.split(",").map((function(e){return e.trim()})),s=l[0],f=l[1]?M[l[1]]:void 0,v=e({key:s},f&&{variable:f});r.push(v),a=u+i.length}else u-1>a&&r.push(t.slice(a,u-1)),r.push(i),a=u+i.length}return a<t.length&&r.push(t.slice(a)),r}var L=function(){function r(e){var t=void 0===e?{}:e,n=t.apiKey,r=void 0===n?"":n,o=t.devApiKey,a=void 0===o?"":o,i=t.sourceLocale,c=void 0===i?"":i,l=t.projectId,s=void 0===l?"":l,f=t.baseUrl,v=void 0===f?"https://api.gtx.dev":f;this.apiKey=r||process.env.GT_API_KEY||"",this.devApiKey=a||process.env.GT_DEV_API_KEY||"",this.projectId=s||process.env.GT_PROJECT_ID||"",this.sourceLocale=u(c)||"",this.baseUrl=v}return r.prototype.translate=function(r,o,a){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},a))];case 1:return[2,t.sent()]}}))}))},r.prototype.translateJsx=function(r,o,a){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},a))];case 1:return[2,t.sent()]}}))}))},r.prototype.translateIcu=function(r,o,a){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,p(this,r,o,e({sourceLocale:this.sourceLocale},a))];case 1:return[2,t.sent()]}}))}))},r}();function E(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 K(e,t){return void 0===t&&(t=o),function(e,t){void 0===t&&(t=o);try{return r.get("DisplayNames",[t,o],{type:"language"}).of(e)||""}catch(e){return""}}(e,t)}function G(e,t){return b(e,t)}function O(e,t){return d(e,t)}function I(e){return c(e)}function P(e){return u(e)}function x(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return l.apply(void 0,e)}function D(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return s.apply(void 0,e)}function R(e,t){return function(e,t){try{var n=r.get("Locale",u(e)),o=n.language,a=n.region,i=n.script,c=r.get("Locale",u(t)),l=c.language,s=c.region,f=c.script;return!(o!==l||a&&a!==s||i&&i!==f)}catch(e){return console.error(e),!1}}(e,t)}function k(e,t){return C({value:e,locales:null==t?void 0:t.locales,options:t})}function B(e,t){return S({value:e,locales:null==t?void 0:t.locales,options:t})}function j(e,t,n){return T({value:e,currency:t,locales:null==n?void 0:n.locales,options:n})}function U(e,t){return A({value:e,locales:null==t?void 0:t.locales,options:t})}function F(t,n,a){return function(t){var n=t.value,a=t.unit,i=t.locales,c=void 0===i?[o]:i,u=t.options,l=void 0===u?{}:u;return r.get("RelativeTimeFormat",c,e({style:"long",numeric:"auto"},l)).format(n,a)}({value:t,unit:n,locales:null==a?void 0:a.locales,options:a})}function z(e){return w(e)}function J(t,n,r,a){return function(t,n,r,a){if(void 0===n&&(n=o),void 0===r&&(r={}),void 0===a&&(a={}),"string"==typeof t&&(t=w(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 i=r[t.key];return t.variable?"number"===t.variable?C({value:i,locales:n,options:a[t.key]}):"currency"===t.variable?T(e(e({value:i,locales:n},a[t.key]&&{options:a[t.key]}),(null===(o=a[t.key])||void 0===o?void 0:o.currency)&&{currency:a[t.key].currency})):"datetime"===t.variable?S(e({value:i,locales:n},a[t.key]&&{options:a[t.key]})):"list"===t.variable?A(e({value:i,locales:n},a[t.key]&&{options:a[t.key]})):i:i}})).join("")}(t,n,r,a)}function W(e,t){return N(e,t)}function H(e,t,n){return function(e,t,n){return!(!c(e)||!c(t)||n&&n.some((function(e){return!c(e)}))||l(e,t)||n&&!n.some((function(e){return s(t,e)})))}(e,t,n)}export{L as default,W as determineLocale,j as formatCurrency,B as formatDateTime,U as formatList,k as formatNum,F as formatRelativeTime,E as getLocaleDirection,O as getLocaleEmoji,K as getLocaleName,G as getLocaleProperties,x as isSameDialect,D as isSameLanguage,R as isSupersetLocale,I as isValidLocale,J as renderContentToString,H as requiresTranslation,z as splitStringToContent,P 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(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};
|
2
2
|
//# sourceMappingURL=index.esm.min.mjs.map
|