generaltranslation 8.2.13 → 8.2.14
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 +11 -0
- package/dist/{ApiError-IYfaOR30.mjs → ApiError-0DxxIHLp.mjs} +1 -1
- package/dist/{ApiError-CZ45tkW6.cjs.map → ApiError-0DxxIHLp.mjs.map} +1 -1
- package/dist/{ApiError-CZ45tkW6.cjs → ApiError-D-IBuHj6.cjs} +1 -1
- package/dist/{ApiError-IYfaOR30.mjs.map → ApiError-D-IBuHj6.cjs.map} +1 -1
- package/dist/LocaleConfig.d.ts +1 -59
- package/dist/LocaleConfig.js +1 -225
- package/dist/{base64-2fu94Klt.cjs → base64-C6BHySOc.cjs} +17 -1
- package/dist/base64-C6BHySOc.cjs.map +1 -0
- package/dist/{base64-DH0STixb.mjs → base64-CWITCfhU.mjs} +6 -2
- package/dist/base64-CWITCfhU.mjs.map +1 -0
- package/dist/core.cjs +9 -8
- package/dist/core.d.cts +1 -2
- package/dist/core.d.mts +1 -2
- package/dist/core.d.ts +1 -128
- package/dist/core.js +1 -137
- package/dist/core.mjs +2 -2
- package/dist/derive/indexVars.d.ts +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/id/types.d.ts +1 -1
- package/dist/{id-CyiXsQrY.cjs → id-C2orn1MA.cjs} +2 -2
- package/dist/{id-CyiXsQrY.cjs.map → id-C2orn1MA.cjs.map} +1 -1
- package/dist/{id-DbD7K-HL.mjs → id-DEaFhGqX.mjs} +2 -2
- package/dist/{id-DbD7K-HL.mjs.map → id-DEaFhGqX.mjs.map} +1 -1
- package/dist/id.cjs +1 -1
- package/dist/id.d.cts +1 -1
- package/dist/id.d.mts +1 -1
- package/dist/id.mjs +1 -1
- package/dist/index.cjs +368 -385
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -242
- package/dist/index.d.mts +4 -242
- package/dist/index.d.ts +5 -238
- package/dist/index.js +3 -322
- package/dist/index.mjs +215 -352
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +6 -6
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +6 -5
- package/dist/internal.d.mts +6 -5
- package/dist/internal.mjs +4 -4
- package/dist/internal.mjs.map +1 -1
- package/dist/{isVariable-B08mggBy.cjs → isVariable-Ba1gLXdB.cjs} +1 -1
- package/dist/{isVariable-B08mggBy.cjs.map → isVariable-Ba1gLXdB.cjs.map} +1 -1
- package/dist/{isVariable-CYsKFHvR.mjs → isVariable-fAKEB7gF.mjs} +1 -1
- package/dist/{isVariable-CYsKFHvR.mjs.map → isVariable-fAKEB7gF.mjs.map} +1 -1
- package/dist/locales/getPluralForm.js +2 -2
- package/dist/logging/logger.d.ts +0 -3
- package/dist/logging/logger.js +0 -3
- package/dist/{types-AHtYZIP-.d.mts → types-73XFwmhH.d.mts} +7 -106
- package/dist/{types-Bf8_Apq_.d.cts → types-YrrGRHBP.d.cts} +7 -106
- package/dist/types-dir/api/enqueueEntries.d.ts +1 -1
- package/dist/types-dir/api/enqueueFiles.d.ts +1 -1
- package/dist/types-dir/api/fetchTranslations.d.ts +1 -1
- package/dist/types-dir/api/file.d.ts +1 -1
- package/dist/types-dir/api/translate.d.ts +1 -1
- package/dist/types-dir/api/uploadFiles.d.ts +1 -1
- package/dist/types.cjs +7 -16
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +10 -12
- package/dist/types.js +1 -2
- package/dist/types.mjs +1 -15
- package/package.json +3 -2
- package/dist/IntlCache-CAW8tKhd.cjs +0 -212
- package/dist/IntlCache-CAW8tKhd.cjs.map +0 -1
- package/dist/IntlCache-WZk0rKvj.mjs +0 -195
- package/dist/IntlCache-WZk0rKvj.mjs.map +0 -1
- package/dist/base64-2fu94Klt.cjs.map +0 -1
- package/dist/base64-DH0STixb.mjs.map +0 -1
- package/dist/cache/IntlCache.d.ts +0 -26
- package/dist/cache/IntlCache.js +0 -84
- package/dist/cache/types.d.ts +0 -32
- package/dist/cache/types.js +0 -1
- package/dist/core-7RP541eY.cjs +0 -1677
- package/dist/core-7RP541eY.cjs.map +0 -1
- package/dist/core-I9pWGafA.d.mts +0 -209
- package/dist/core-TLJoDpJP.d.cts +0 -209
- package/dist/core-isLphYAZ.mjs +0 -1498
- package/dist/core-isLphYAZ.mjs.map +0 -1
- package/dist/errors/formattingErrors.d.ts +0 -1
- package/dist/errors/formattingErrors.js +0 -3
- package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +0 -59
- package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.js +0 -147
- package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +0 -4
- package/dist/formatting/custom-formats/CutoffFormat/constants.js +0 -30
- package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +0 -48
- package/dist/formatting/custom-formats/CutoffFormat/types.js +0 -2
- package/dist/formatting/format.d.ts +0 -1
- package/dist/formatting/format.js +0 -257
- package/dist/locales/customLocaleMapping.d.ts +0 -11
- package/dist/locales/customLocaleMapping.js +0 -23
- package/dist/locales/determineLocale.d.ts +0 -1
- package/dist/locales/determineLocale.js +0 -72
- package/dist/locales/getLocaleDirection.d.ts +0 -1
- package/dist/locales/getLocaleDirection.js +0 -89
- package/dist/locales/getLocaleEmoji.d.ts +0 -2
- package/dist/locales/getLocaleEmoji.js +0 -319
- package/dist/locales/getLocaleName.d.ts +0 -1
- package/dist/locales/getLocaleName.js +0 -45
- package/dist/locales/getLocaleProperties.d.ts +0 -32
- package/dist/locales/getLocaleProperties.js +0 -220
- package/dist/locales/getRegionProperties.d.ts +0 -7
- package/dist/locales/getRegionProperties.js +0 -61
- package/dist/locales/isSameDialect.d.ts +0 -1
- package/dist/locales/isSameDialect.js +0 -41
- package/dist/locales/isSameLanguage.d.ts +0 -1
- package/dist/locales/isSameLanguage.js +0 -20
- package/dist/locales/isSupersetLocale.d.ts +0 -1
- package/dist/locales/isSupersetLocale.js +0 -22
- package/dist/locales/isValidLocale.d.ts +0 -1
- package/dist/locales/isValidLocale.js +0 -75
- package/dist/locales/requiresTranslation.d.ts +0 -1
- package/dist/locales/requiresTranslation.js +0 -32
- package/dist/locales/resolveAliasLocale.d.ts +0 -8
- package/dist/locales/resolveAliasLocale.js +0 -21
- package/dist/locales/resolveCanonicalLocale.d.ts +0 -8
- package/dist/locales/resolveCanonicalLocale.js +0 -13
- package/dist/logging/warnings.d.ts +0 -2
- package/dist/logging/warnings.js +0 -2
- package/dist/types-dir/jsx/content.d.ts +0 -61
- package/dist/types-dir/jsx/content.js +0 -11
- package/dist/types-dir/jsx/variables.d.ts +0 -9
- package/dist/types-dir/jsx/variables.js +0 -1
- package/dist/types.cjs.map +0 -1
- package/dist/types.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const require_id = require("./id-CyiXsQrY.cjs");
|
|
2
|
+
const require_base64 = require("./base64-C6BHySOc.cjs");
|
|
3
|
+
const require_ApiError = require("./ApiError-D-IBuHj6.cjs");
|
|
4
|
+
const require_id = require("./id-C2orn1MA.cjs");
|
|
5
|
+
let _generaltranslation_format = require("@generaltranslation/format");
|
|
7
6
|
//#region src/logging/errors.ts
|
|
8
7
|
const GT_ERROR_PREFIX = "GT Error:";
|
|
9
8
|
const translationTimeoutError = (timeout) => `${GT_ERROR_PREFIX} Translation request timed out after ${timeout}ms.`;
|
|
@@ -17,6 +16,204 @@ const noApiKeyProvidedError = (functionName) => `${GT_ERROR_PREFIX} Cannot call
|
|
|
17
16
|
const invalidLocaleError = (locale) => `${GT_ERROR_PREFIX} Invalid locale: ${locale}.`;
|
|
18
17
|
const invalidLocalesError = (locales) => `${GT_ERROR_PREFIX} Invalid locales: ${locales.join(", ")}.`;
|
|
19
18
|
//#endregion
|
|
19
|
+
//#region src/logging/logger.ts
|
|
20
|
+
const LOG_LEVELS = {
|
|
21
|
+
debug: 0,
|
|
22
|
+
info: 1,
|
|
23
|
+
warn: 2,
|
|
24
|
+
error: 3,
|
|
25
|
+
off: 4
|
|
26
|
+
};
|
|
27
|
+
const LOG_COLORS = {
|
|
28
|
+
debug: "\x1B[36m",
|
|
29
|
+
info: "\x1B[32m",
|
|
30
|
+
warn: "\x1B[33m",
|
|
31
|
+
error: "\x1B[31m",
|
|
32
|
+
off: ""
|
|
33
|
+
};
|
|
34
|
+
const RESET_COLOR = "\x1B[0m";
|
|
35
|
+
/**
|
|
36
|
+
* Get the configured log level from environment variable or default to 'warn'
|
|
37
|
+
*/
|
|
38
|
+
function getConfiguredLogLevel() {
|
|
39
|
+
if (typeof process !== "undefined" && process.env?._GT_LOG_LEVEL) {
|
|
40
|
+
const envLevel = process.env._GT_LOG_LEVEL.toLowerCase();
|
|
41
|
+
if (envLevel in LOG_LEVELS) return envLevel;
|
|
42
|
+
}
|
|
43
|
+
return "warn";
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Console log handler that outputs formatted messages to console
|
|
47
|
+
*/
|
|
48
|
+
var ConsoleLogHandler = class {
|
|
49
|
+
constructor(config) {
|
|
50
|
+
this.config = config;
|
|
51
|
+
}
|
|
52
|
+
handle(entry) {
|
|
53
|
+
const parts = [];
|
|
54
|
+
if (this.config.includeTimestamp) parts.push(`[${entry.timestamp.toISOString()}]`);
|
|
55
|
+
const colorCode = LOG_COLORS[entry.level];
|
|
56
|
+
const levelText = `[${entry.level.toUpperCase()}]`;
|
|
57
|
+
parts.push(`${colorCode}${levelText}${RESET_COLOR}`);
|
|
58
|
+
if (this.config.prefix) parts.push(`[${this.config.prefix}]`);
|
|
59
|
+
if (this.config.includeContext && entry.context) parts.push(`[${entry.context}]`);
|
|
60
|
+
parts.push(entry.message);
|
|
61
|
+
if (entry.metadata && Object.keys(entry.metadata).length > 0) parts.push(`\n Metadata: ${JSON.stringify(entry.metadata, null, 2)}`);
|
|
62
|
+
const formattedMessage = parts.join(" ");
|
|
63
|
+
switch (entry.level) {
|
|
64
|
+
case "debug":
|
|
65
|
+
console.debug(formattedMessage);
|
|
66
|
+
break;
|
|
67
|
+
case "info":
|
|
68
|
+
console.info(formattedMessage);
|
|
69
|
+
break;
|
|
70
|
+
case "warn":
|
|
71
|
+
console.warn(formattedMessage);
|
|
72
|
+
break;
|
|
73
|
+
case "error":
|
|
74
|
+
console.error(formattedMessage);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Main Logger class providing structured logging capabilities.
|
|
81
|
+
*/
|
|
82
|
+
var Logger = class {
|
|
83
|
+
constructor(config = {}) {
|
|
84
|
+
this.config = {
|
|
85
|
+
level: getConfiguredLogLevel(),
|
|
86
|
+
includeTimestamp: true,
|
|
87
|
+
includeContext: true,
|
|
88
|
+
enableConsole: true,
|
|
89
|
+
handlers: [],
|
|
90
|
+
...config
|
|
91
|
+
};
|
|
92
|
+
this.handlers = [...this.config.handlers || []];
|
|
93
|
+
if (this.config.enableConsole) this.handlers.push(new ConsoleLogHandler(this.config));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Add a custom log handler
|
|
97
|
+
*/
|
|
98
|
+
addHandler(handler) {
|
|
99
|
+
this.handlers.push(handler);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Remove a log handler
|
|
103
|
+
*/
|
|
104
|
+
removeHandler(handler) {
|
|
105
|
+
const index = this.handlers.indexOf(handler);
|
|
106
|
+
if (index > -1) this.handlers.splice(index, 1);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Update logger configuration
|
|
110
|
+
*/
|
|
111
|
+
configure(config) {
|
|
112
|
+
this.config = {
|
|
113
|
+
...this.config,
|
|
114
|
+
...config
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if a log level should be output based on current configuration
|
|
119
|
+
*/
|
|
120
|
+
shouldLog(level) {
|
|
121
|
+
return LOG_LEVELS[level] >= LOG_LEVELS[this.config.level];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Internal logging method that creates log entries and passes them to handlers
|
|
125
|
+
*/
|
|
126
|
+
log(level, message, context, metadata) {
|
|
127
|
+
if (!this.shouldLog(level)) return;
|
|
128
|
+
const entry = {
|
|
129
|
+
level,
|
|
130
|
+
message,
|
|
131
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
132
|
+
context,
|
|
133
|
+
metadata
|
|
134
|
+
};
|
|
135
|
+
this.handlers.forEach((handler) => {
|
|
136
|
+
try {
|
|
137
|
+
handler.handle(entry);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error("Error in log handler:", error);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Log a debug message
|
|
145
|
+
* Used for detailed diagnostic information, typically of interest only when diagnosing problems
|
|
146
|
+
*/
|
|
147
|
+
debug(message, context, metadata) {
|
|
148
|
+
this.log("debug", message, context, metadata);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Log an info message
|
|
152
|
+
* Used for general information about application operation.
|
|
153
|
+
*/
|
|
154
|
+
info(message, context, metadata) {
|
|
155
|
+
this.log("info", message, context, metadata);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Log a warning message
|
|
159
|
+
* Used for potentially problematic situations that don't prevent operation
|
|
160
|
+
*/
|
|
161
|
+
warn(message, context, metadata) {
|
|
162
|
+
this.log("warn", message, context, metadata);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Log an error message
|
|
166
|
+
* Used for error events that might still allow the application to continue.
|
|
167
|
+
*/
|
|
168
|
+
error(message, context, metadata) {
|
|
169
|
+
this.log("error", message, context, metadata);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Create a child logger with a specific context
|
|
173
|
+
*/
|
|
174
|
+
child(context) {
|
|
175
|
+
return new ContextLogger(this, context);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Get current logger configuration
|
|
179
|
+
*/
|
|
180
|
+
getConfig() {
|
|
181
|
+
return { ...this.config };
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Context logger that automatically includes context information.
|
|
186
|
+
*/
|
|
187
|
+
var ContextLogger = class ContextLogger {
|
|
188
|
+
constructor(logger, context) {
|
|
189
|
+
this.logger = logger;
|
|
190
|
+
this.context = context;
|
|
191
|
+
}
|
|
192
|
+
debug(message, metadata) {
|
|
193
|
+
this.logger.debug(message, this.context, metadata);
|
|
194
|
+
}
|
|
195
|
+
info(message, metadata) {
|
|
196
|
+
this.logger.info(message, this.context, metadata);
|
|
197
|
+
}
|
|
198
|
+
warn(message, metadata) {
|
|
199
|
+
this.logger.warn(message, this.context, metadata);
|
|
200
|
+
}
|
|
201
|
+
error(message, metadata) {
|
|
202
|
+
this.logger.error(message, this.context, metadata);
|
|
203
|
+
}
|
|
204
|
+
child(childContext) {
|
|
205
|
+
return new ContextLogger(this.logger, `${this.context}:${childContext}`);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const defaultLogger = new Logger({
|
|
209
|
+
level: getConfiguredLogLevel(),
|
|
210
|
+
includeTimestamp: true,
|
|
211
|
+
includeContext: true,
|
|
212
|
+
prefix: "GT"
|
|
213
|
+
});
|
|
214
|
+
const fetchLogger = defaultLogger.child("fetch");
|
|
215
|
+
const gtInstanceLogger = defaultLogger.child("GT instance");
|
|
216
|
+
//#endregion
|
|
20
217
|
//#region src/translate/utils/fetchWithTimeout.ts
|
|
21
218
|
/**
|
|
22
219
|
* @internal
|
|
@@ -31,7 +228,7 @@ const invalidLocalesError = (locales) => `${GT_ERROR_PREFIX} Invalid locales: ${
|
|
|
31
228
|
async function fetchWithTimeout(url, options, timeout) {
|
|
32
229
|
const controller = new AbortController();
|
|
33
230
|
const signal = controller.signal;
|
|
34
|
-
timeout = timeout ? timeout :
|
|
231
|
+
timeout = timeout ? timeout : require_base64.defaultTimeout;
|
|
35
232
|
const timeoutId = timeout ? setTimeout(() => controller.abort(), timeout) : null;
|
|
36
233
|
try {
|
|
37
234
|
return await fetch(url, {
|
|
@@ -66,11 +263,11 @@ async function validateResponse(response) {
|
|
|
66
263
|
function handleFetchError(error, timeout) {
|
|
67
264
|
if (error instanceof Error && error.name === "AbortError") {
|
|
68
265
|
const errorMessage = translationTimeoutError(timeout);
|
|
69
|
-
|
|
266
|
+
fetchLogger.error(errorMessage);
|
|
70
267
|
throw new Error(errorMessage);
|
|
71
268
|
}
|
|
72
269
|
const errorMessage = translationRequestFailedError(error instanceof Error ? error.message : String(error));
|
|
73
|
-
|
|
270
|
+
fetchLogger.error(errorMessage);
|
|
74
271
|
throw error;
|
|
75
272
|
}
|
|
76
273
|
//#endregion
|
|
@@ -361,61 +558,6 @@ async function _submitUserEditDiffs(payload, config, options = {}) {
|
|
|
361
558
|
return { success: true };
|
|
362
559
|
}
|
|
363
560
|
//#endregion
|
|
364
|
-
//#region src/locales/getRegionProperties.ts
|
|
365
|
-
/**
|
|
366
|
-
* Retrieves multiple properties for a given region code, including:
|
|
367
|
-
* - `code`: the original region code
|
|
368
|
-
* - `name`: the localized display name
|
|
369
|
-
* - `emoji`: the associated flag or symbol
|
|
370
|
-
*
|
|
371
|
-
* Behavior:
|
|
372
|
-
* - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
|
|
373
|
-
* - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
|
|
374
|
-
* - Otherwise, uses `Intl.DisplayNames` to get the localized region name in the given `defaultLocale`,
|
|
375
|
-
* falling back to `libraryDefaultLocale`.
|
|
376
|
-
* - Falls back to the region code as `name` if display name resolution fails.
|
|
377
|
-
* - Falls back to `defaultEmoji` if no emoji can be computed or found in `customMapping`.
|
|
378
|
-
*
|
|
379
|
-
* @param {string} region - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
|
|
380
|
-
* @param {string} [defaultLocale=libraryDefaultLocale] - The locale to use when localizing the region name.
|
|
381
|
-
* @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
|
|
382
|
-
* @returns {{ code: string, name: string, emoji: string }} An object containing:
|
|
383
|
-
* - `code`: the input region code
|
|
384
|
-
* - `name`: the localized or custom region name
|
|
385
|
-
* - `emoji`: the matching emoji flag or symbol
|
|
386
|
-
* @internal
|
|
387
|
-
*
|
|
388
|
-
* @example
|
|
389
|
-
* _getRegionProperties('US', 'en');
|
|
390
|
-
* // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
|
|
391
|
-
*
|
|
392
|
-
* @example
|
|
393
|
-
* _getRegionProperties('US', 'fr');
|
|
394
|
-
* // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
|
|
395
|
-
*
|
|
396
|
-
* @example
|
|
397
|
-
* _getRegionProperties('US', 'en', { US: { name: 'USA', emoji: '🗽' } });
|
|
398
|
-
* // => { code: 'US', name: 'USA', emoji: '🗽' }
|
|
399
|
-
*/
|
|
400
|
-
function _getRegionProperties(region, defaultLocale = "en", customMapping) {
|
|
401
|
-
defaultLocale ||= "en";
|
|
402
|
-
try {
|
|
403
|
-
return {
|
|
404
|
-
code: region,
|
|
405
|
-
name: require_IntlCache.intlCache.get("DisplayNames", [defaultLocale, "en"], { type: "region" }).of(region) || region,
|
|
406
|
-
emoji: require_core.getRegionEmoji(region),
|
|
407
|
-
...customMapping?.[region]
|
|
408
|
-
};
|
|
409
|
-
} catch {
|
|
410
|
-
return {
|
|
411
|
-
code: region,
|
|
412
|
-
name: region,
|
|
413
|
-
emoji: require_core.defaultEmoji,
|
|
414
|
-
...customMapping?.[region]
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
//#endregion
|
|
419
561
|
//#region src/translate/uploadSourceFiles.ts
|
|
420
562
|
/**
|
|
421
563
|
* @internal
|
|
@@ -527,7 +669,7 @@ async function _querySourceFile(query, options, config) {
|
|
|
527
669
|
*/
|
|
528
670
|
async function _getProjectData(projectId, options, config) {
|
|
529
671
|
const { baseUrl } = config;
|
|
530
|
-
const timeout = options.timeout ? options.timeout :
|
|
672
|
+
const timeout = options.timeout ? options.timeout : require_base64.defaultTimeout;
|
|
531
673
|
const url = `${baseUrl || "https://api2.gtx.dev"}/v2/project/info/${encodeURIComponent(projectId)}`;
|
|
532
674
|
let response;
|
|
533
675
|
try {
|
|
@@ -791,19 +933,19 @@ var GT = class {
|
|
|
791
933
|
if (devApiKey) this.devApiKey = devApiKey;
|
|
792
934
|
if (projectId) this.projectId = projectId;
|
|
793
935
|
if (sourceLocale) {
|
|
794
|
-
this.sourceLocale =
|
|
795
|
-
if (!
|
|
936
|
+
this.sourceLocale = (0, _generaltranslation_format.standardizeLocale)(sourceLocale);
|
|
937
|
+
if (!(0, _generaltranslation_format.isValidLocale)(this.sourceLocale, customMapping)) throw new Error(invalidLocaleError(this.sourceLocale));
|
|
796
938
|
}
|
|
797
939
|
if (targetLocale) {
|
|
798
|
-
this.targetLocale =
|
|
799
|
-
if (!
|
|
940
|
+
this.targetLocale = (0, _generaltranslation_format.standardizeLocale)(targetLocale);
|
|
941
|
+
if (!(0, _generaltranslation_format.isValidLocale)(this.targetLocale, customMapping)) throw new Error(invalidLocaleError(this.targetLocale));
|
|
800
942
|
}
|
|
801
943
|
if (locales) {
|
|
802
944
|
const result = [];
|
|
803
945
|
const invalidLocales = [];
|
|
804
946
|
locales.forEach((locale) => {
|
|
805
|
-
const standardizedLocale =
|
|
806
|
-
if (
|
|
947
|
+
const standardizedLocale = (0, _generaltranslation_format.standardizeLocale)(locale);
|
|
948
|
+
if ((0, _generaltranslation_format.isValidLocale)(standardizedLocale)) result.push(standardizedLocale);
|
|
807
949
|
else invalidLocales.push(locale);
|
|
808
950
|
});
|
|
809
951
|
if (invalidLocales.length > 0) throw new Error(invalidLocalesError(invalidLocales));
|
|
@@ -814,7 +956,7 @@ var GT = class {
|
|
|
814
956
|
this.customMapping = customMapping;
|
|
815
957
|
this.reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
|
|
816
958
|
}
|
|
817
|
-
this._localeConfig = new
|
|
959
|
+
this._localeConfig = new _generaltranslation_format.LocaleConfig({
|
|
818
960
|
defaultLocale: this.sourceLocale,
|
|
819
961
|
locales: this.locales ?? [],
|
|
820
962
|
customMapping: this.customMapping
|
|
@@ -968,12 +1110,12 @@ var GT = class {
|
|
|
968
1110
|
};
|
|
969
1111
|
if (!mergedOptions.sourceLocale) {
|
|
970
1112
|
const error = noSourceLocaleProvidedError("enqueueFiles");
|
|
971
|
-
|
|
1113
|
+
gtInstanceLogger.error(error);
|
|
972
1114
|
throw new Error(error);
|
|
973
1115
|
}
|
|
974
1116
|
if (!mergedOptions.targetLocales || mergedOptions.targetLocales.length === 0) {
|
|
975
1117
|
const error = noTargetLocaleProvidedError("enqueueFiles");
|
|
976
|
-
|
|
1118
|
+
gtInstanceLogger.error(error);
|
|
977
1119
|
throw new Error(error);
|
|
978
1120
|
}
|
|
979
1121
|
mergedOptions = {
|
|
@@ -1187,7 +1329,7 @@ var GT = class {
|
|
|
1187
1329
|
let targetLocale = options?.targetLocale || this.targetLocale;
|
|
1188
1330
|
if (!targetLocale) {
|
|
1189
1331
|
const error = noTargetLocaleProvidedError("translate");
|
|
1190
|
-
|
|
1332
|
+
gtInstanceLogger.error(error);
|
|
1191
1333
|
throw new Error(error);
|
|
1192
1334
|
}
|
|
1193
1335
|
targetLocale = this.resolveCanonicalLocale(targetLocale);
|
|
@@ -1204,7 +1346,7 @@ var GT = class {
|
|
|
1204
1346
|
let targetLocale = options?.targetLocale || this.targetLocale;
|
|
1205
1347
|
if (!targetLocale) {
|
|
1206
1348
|
const error = noTargetLocaleProvidedError("translateMany");
|
|
1207
|
-
|
|
1349
|
+
gtInstanceLogger.error(error);
|
|
1208
1350
|
throw new Error(error);
|
|
1209
1351
|
}
|
|
1210
1352
|
targetLocale = this.resolveCanonicalLocale(targetLocale);
|
|
@@ -1269,7 +1411,7 @@ var GT = class {
|
|
|
1269
1411
|
};
|
|
1270
1412
|
if (!mergedOptions.sourceLocale) {
|
|
1271
1413
|
const error = noSourceLocaleProvidedError("uploadTranslations");
|
|
1272
|
-
|
|
1414
|
+
gtInstanceLogger.error(error);
|
|
1273
1415
|
throw new Error(error);
|
|
1274
1416
|
}
|
|
1275
1417
|
const result = await _uploadTranslations(files.map((f) => ({
|
|
@@ -1568,7 +1710,7 @@ var GT = class {
|
|
|
1568
1710
|
}
|
|
1569
1711
|
customMapping = this.customRegionMapping;
|
|
1570
1712
|
}
|
|
1571
|
-
return
|
|
1713
|
+
return (0, _generaltranslation_format.getRegionProperties)(region, this.targetLocale, customMapping);
|
|
1572
1714
|
}
|
|
1573
1715
|
/**
|
|
1574
1716
|
* Determines whether a translation is required based on the source and target locales.
|
|
@@ -1588,7 +1730,7 @@ var GT = class {
|
|
|
1588
1730
|
if (!sourceLocale) throw new Error(noSourceLocaleProvidedError("requiresTranslation"));
|
|
1589
1731
|
if (!targetLocale) throw new Error(noTargetLocaleProvidedError("requiresTranslation"));
|
|
1590
1732
|
if (customMapping === this.customMapping) return this.localeConfig.requiresTranslation(targetLocale, sourceLocale, approvedLocales);
|
|
1591
|
-
return
|
|
1733
|
+
return (0, _generaltranslation_format.requiresTranslation)(sourceLocale, targetLocale, approvedLocales, customMapping);
|
|
1592
1734
|
}
|
|
1593
1735
|
/**
|
|
1594
1736
|
* Determines the best matching locale from the provided approved locales list.
|
|
@@ -1603,7 +1745,7 @@ var GT = class {
|
|
|
1603
1745
|
*/
|
|
1604
1746
|
determineLocale(locales, approvedLocales = this.locales || [], customMapping = this.customMapping) {
|
|
1605
1747
|
if (customMapping === this.customMapping) return this.localeConfig.determineLocale(locales, approvedLocales ?? []);
|
|
1606
|
-
return
|
|
1748
|
+
return (0, _generaltranslation_format.determineLocale)(locales, approvedLocales, customMapping);
|
|
1607
1749
|
}
|
|
1608
1750
|
/**
|
|
1609
1751
|
* Gets the text direction for a given locale code.
|
|
@@ -1635,7 +1777,7 @@ var GT = class {
|
|
|
1635
1777
|
isValidLocale(locale = this.targetLocale, customMapping = this.customMapping) {
|
|
1636
1778
|
if (!locale) throw new Error(noTargetLocaleProvidedError("isValidLocale"));
|
|
1637
1779
|
if (customMapping === this.customMapping) return this.localeConfig.isValidLocale(locale);
|
|
1638
|
-
return
|
|
1780
|
+
return (0, _generaltranslation_format.isValidLocale)(locale, customMapping);
|
|
1639
1781
|
}
|
|
1640
1782
|
/**
|
|
1641
1783
|
* Resolves the canonical locale for a given locale.
|
|
@@ -1646,7 +1788,7 @@ var GT = class {
|
|
|
1646
1788
|
resolveCanonicalLocale(locale = this.targetLocale, customMapping = this.customMapping) {
|
|
1647
1789
|
if (!locale) throw new Error(noTargetLocaleProvidedError("resolveCanonicalLocale"));
|
|
1648
1790
|
if (customMapping === this.customMapping) return this.localeConfig.resolveCanonicalLocale(locale);
|
|
1649
|
-
return
|
|
1791
|
+
return (0, _generaltranslation_format.resolveCanonicalLocale)(locale, customMapping);
|
|
1650
1792
|
}
|
|
1651
1793
|
/**
|
|
1652
1794
|
* Resolves the alias locale for a given locale.
|
|
@@ -1657,7 +1799,7 @@ var GT = class {
|
|
|
1657
1799
|
resolveAliasLocale(locale, customMapping = this.customMapping) {
|
|
1658
1800
|
if (!locale) throw new Error(noTargetLocaleProvidedError("resolveAliasLocale"));
|
|
1659
1801
|
if (customMapping === this.customMapping) return this.localeConfig.resolveAliasLocale(locale);
|
|
1660
|
-
return
|
|
1802
|
+
return (0, _generaltranslation_format.resolveAliasLocale)(locale, customMapping);
|
|
1661
1803
|
}
|
|
1662
1804
|
/**
|
|
1663
1805
|
* Standardizes a BCP 47 locale code to ensure correct formatting.
|
|
@@ -1721,312 +1863,153 @@ var GT = class {
|
|
|
1721
1863
|
return this.localeConfig.isSupersetLocale(superLocale, subLocale);
|
|
1722
1864
|
}
|
|
1723
1865
|
};
|
|
1724
|
-
/**
|
|
1725
|
-
* Formats a number according to the specified locales and options.
|
|
1726
|
-
* @param {Object} params - The parameters for the number formatting.
|
|
1727
|
-
* @param {number} params.value - The number to format.
|
|
1728
|
-
* @param {Intl.NumberFormatOptions} [params.options] - Additional options for number formatting.
|
|
1729
|
-
* @param {string | string[]} [params.options.locales] - The locales to use for formatting.
|
|
1730
|
-
* @returns {string} The formatted number.
|
|
1731
|
-
*/
|
|
1732
|
-
function formatNum(number, options) {
|
|
1733
|
-
return require_core._formatNum({
|
|
1734
|
-
value: number,
|
|
1735
|
-
locales: options.locales,
|
|
1736
|
-
options
|
|
1737
|
-
});
|
|
1738
|
-
}
|
|
1739
|
-
/**
|
|
1740
|
-
* Formats a date according to the specified languages and options.
|
|
1741
|
-
* @param {Object} params - The parameters for the date formatting.
|
|
1742
|
-
* @param {Date} params.value - The date to format.
|
|
1743
|
-
* @param {Intl.DateTimeFormatOptions} [params.options] - Additional options for date formatting.
|
|
1744
|
-
* @param {string | string[]} [params.options.locales] - The languages to use for formatting.
|
|
1745
|
-
* @returns {string} The formatted date.
|
|
1746
|
-
*/
|
|
1747
|
-
function formatDateTime(date, options) {
|
|
1748
|
-
return require_core._formatDateTime({
|
|
1749
|
-
value: date,
|
|
1750
|
-
locales: options?.locales,
|
|
1751
|
-
options
|
|
1752
|
-
});
|
|
1753
|
-
}
|
|
1754
|
-
/**
|
|
1755
|
-
* Formats a currency value according to the specified languages, currency, and options.
|
|
1756
|
-
* @param {Object} params - The parameters for the currency formatting.
|
|
1757
|
-
* @param {number} params.value - The currency value to format.
|
|
1758
|
-
* @param {string} params.currency - The currency code (e.g., 'USD').
|
|
1759
|
-
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
|
|
1760
|
-
* @param {string | string[]} [params.options.locales] - The locale codes to use for formatting.
|
|
1761
|
-
* @returns {string} The formatted currency value.
|
|
1762
|
-
*/
|
|
1763
|
-
function formatCurrency(value, currency, options) {
|
|
1764
|
-
return require_core._formatCurrency({
|
|
1765
|
-
value,
|
|
1766
|
-
currency,
|
|
1767
|
-
locales: options.locales,
|
|
1768
|
-
options
|
|
1769
|
-
});
|
|
1770
|
-
}
|
|
1771
|
-
/**
|
|
1772
|
-
* Formats a list of items according to the specified locales and options.
|
|
1773
|
-
* @param {Object} params - The parameters for the list formatting.
|
|
1774
|
-
* @param {Array<string | number>} params.value - The list of items to format.
|
|
1775
|
-
* @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
|
|
1776
|
-
* @param {string | string[]} [params.options.locales] - The locales to use for formatting.
|
|
1777
|
-
* @returns {string} The formatted list.
|
|
1778
|
-
*/
|
|
1779
|
-
function formatList(array, options) {
|
|
1780
|
-
return require_core._formatList({
|
|
1781
|
-
value: array,
|
|
1782
|
-
locales: options.locales,
|
|
1783
|
-
options
|
|
1784
|
-
});
|
|
1785
|
-
}
|
|
1786
|
-
/**
|
|
1787
|
-
* Formats a list of items according to the specified locales and options.
|
|
1788
|
-
* @param {Array<T>} array - The list of items to format.
|
|
1789
|
-
* @param {Object} [options] - Additional options for list formatting.
|
|
1790
|
-
* @param {string | string[]} [options.locales] - The locales to use for formatting.
|
|
1791
|
-
* @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options.
|
|
1792
|
-
* @returns {Array<T | string>} The formatted list parts.
|
|
1793
|
-
*/
|
|
1794
|
-
function formatListToParts(array, options) {
|
|
1795
|
-
return require_core._formatListToParts({
|
|
1796
|
-
value: array,
|
|
1797
|
-
locales: options?.locales,
|
|
1798
|
-
options
|
|
1799
|
-
});
|
|
1800
|
-
}
|
|
1801
|
-
/**
|
|
1802
|
-
* Formats a relative time value according to the specified locales and options.
|
|
1803
|
-
* @param {Object} params - The parameters for the relative time formatting.
|
|
1804
|
-
* @param {number} params.value - The relative time value to format.
|
|
1805
|
-
* @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
|
|
1806
|
-
* @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
|
|
1807
|
-
* @param {string | string[]} [params.options.locales] - The locales to use for formatting.
|
|
1808
|
-
* @returns {string} The formatted relative time string.
|
|
1809
|
-
*/
|
|
1810
|
-
function formatRelativeTime(value, unit, options) {
|
|
1811
|
-
return require_core._formatRelativeTime({
|
|
1812
|
-
value,
|
|
1813
|
-
unit,
|
|
1814
|
-
locales: options.locales,
|
|
1815
|
-
options
|
|
1816
|
-
});
|
|
1817
|
-
}
|
|
1818
|
-
/**
|
|
1819
|
-
* Formats a relative time string from a Date, automatically selecting the best unit.
|
|
1820
|
-
* @param {Date} date - The date to format relative to now.
|
|
1821
|
-
* @param {Object} options - Formatting options.
|
|
1822
|
-
* @param {string | string[]} options.locales - The locales to use for formatting.
|
|
1823
|
-
* @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options.
|
|
1824
|
-
* @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days").
|
|
1825
|
-
*/
|
|
1826
|
-
function formatRelativeTimeFromDate(date, options) {
|
|
1827
|
-
const { locales, baseDate, ...intlOptions } = options;
|
|
1828
|
-
return require_core._formatRelativeTimeFromDate({
|
|
1829
|
-
date,
|
|
1830
|
-
baseDate: baseDate ?? /* @__PURE__ */ new Date(),
|
|
1831
|
-
locales,
|
|
1832
|
-
options: intlOptions
|
|
1833
|
-
});
|
|
1834
|
-
}
|
|
1835
|
-
/**
|
|
1836
|
-
* Retrieves the display name of locale code using Intl.DisplayNames.
|
|
1837
|
-
*
|
|
1838
|
-
* @param {string} locale - A BCP-47 locale code.
|
|
1839
|
-
* @param {string} [defaultLocale] - The default locale to use for formatting.
|
|
1840
|
-
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
|
1841
|
-
* @returns {string} The display name corresponding to the code.
|
|
1842
|
-
*/
|
|
1843
|
-
function getLocaleName(locale, defaultLocale, customMapping) {
|
|
1844
|
-
return require_core._getLocaleName(locale, defaultLocale, customMapping);
|
|
1845
|
-
}
|
|
1846
|
-
/**
|
|
1847
|
-
* Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
|
|
1848
|
-
*
|
|
1849
|
-
* This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
|
|
1850
|
-
*
|
|
1851
|
-
* @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA').
|
|
1852
|
-
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
|
1853
|
-
* @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
|
|
1854
|
-
*/
|
|
1855
|
-
function getLocaleEmoji(locale, customMapping) {
|
|
1856
|
-
return require_core._getLocaleEmoji(locale, customMapping);
|
|
1857
|
-
}
|
|
1858
|
-
/**
|
|
1859
|
-
* Generates linguistic details for a given locale code.
|
|
1860
|
-
*
|
|
1861
|
-
* This function returns information about the locale,
|
|
1862
|
-
* script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
|
|
1863
|
-
* The function provides these names in both your default language and native forms, and an associated emoji.
|
|
1864
|
-
*
|
|
1865
|
-
* @param {string} locale - The locale code to get properties for (e.g., "de-AT").
|
|
1866
|
-
* @param {string} [defaultLocale] - The default locale to use for formatting.
|
|
1867
|
-
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
|
1868
|
-
* @returns {LocaleProperties} - An object containing detailed information about the locale.
|
|
1869
|
-
*
|
|
1870
|
-
* @property {string} code - The full locale code, e.g., "de-AT".
|
|
1871
|
-
* @property {string} name - Language name in the default display language, e.g., "Austrian German".
|
|
1872
|
-
* @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
|
|
1873
|
-
* @property {string} languageCode - The base language code, e.g., "de".
|
|
1874
|
-
* @property {string} languageName - The language name in the default display language, e.g., "German".
|
|
1875
|
-
* @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
|
|
1876
|
-
* @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
|
|
1877
|
-
* @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
|
|
1878
|
-
* @property {string} regionCode - The region code from maximization, e.g., "AT".
|
|
1879
|
-
* @property {string} regionName - The region name in the default display language, e.g., "Austria".
|
|
1880
|
-
* @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
|
|
1881
|
-
* @property {string} scriptCode - The script code from maximization, e.g., "Latn".
|
|
1882
|
-
* @property {string} scriptName - The script name in the default display language, e.g., "Latin".
|
|
1883
|
-
* @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
|
|
1884
|
-
* @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
|
|
1885
|
-
* @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
|
|
1886
|
-
* @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
|
|
1887
|
-
* @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
|
|
1888
|
-
* @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
|
|
1889
|
-
* @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
|
|
1890
|
-
* @property {string} emoji - The emoji associated with the locale's region, if applicable.
|
|
1891
|
-
*/
|
|
1892
|
-
function getLocaleProperties(locale, defaultLocale, customMapping) {
|
|
1893
|
-
return require_core._getLocaleProperties(locale, defaultLocale, customMapping);
|
|
1894
|
-
}
|
|
1895
|
-
/**
|
|
1896
|
-
* Retrieves multiple properties for a given region code, including:
|
|
1897
|
-
* - `code`: the original region code
|
|
1898
|
-
* - `name`: the localized display name
|
|
1899
|
-
* - `emoji`: the associated flag or symbol
|
|
1900
|
-
*
|
|
1901
|
-
* Behavior:
|
|
1902
|
-
* - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
|
|
1903
|
-
* - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
|
|
1904
|
-
* - Otherwise, uses `Intl.DisplayNames` to get the localized region name in the given `defaultLocale`,
|
|
1905
|
-
* falling back to `libraryDefaultLocale`.
|
|
1906
|
-
* - Falls back to the region code as `name` if display name resolution fails.
|
|
1907
|
-
* - Falls back to `defaultEmoji` if no emoji mapping is found in `emojis` or `customMapping`.
|
|
1908
|
-
*
|
|
1909
|
-
* @param {string} region - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
|
|
1910
|
-
* @param {string} [defaultLocale=libraryDefaultLocale] - The locale to use when localizing the region name.
|
|
1911
|
-
* @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
|
|
1912
|
-
* @returns {{ code: string, name: string, emoji: string }} An object containing:
|
|
1913
|
-
* - `code`: the input region code
|
|
1914
|
-
* - `name`: the localized or custom region name
|
|
1915
|
-
* - `emoji`: the matching emoji flag or symbol
|
|
1916
|
-
*
|
|
1917
|
-
* @example
|
|
1918
|
-
* getRegionProperties('US', 'en');
|
|
1919
|
-
* // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
|
|
1920
|
-
*
|
|
1921
|
-
* @example
|
|
1922
|
-
* getRegionProperties('US', 'fr');
|
|
1923
|
-
* // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
|
|
1924
|
-
*
|
|
1925
|
-
* @example
|
|
1926
|
-
* getRegionProperties('US', 'en', { US: { name: 'USA', emoji: '🗽' } });
|
|
1927
|
-
* // => { code: 'US', name: 'USA', emoji: '🗽' }
|
|
1928
|
-
*/
|
|
1929
|
-
function getRegionProperties(region, defaultLocale, customMapping) {
|
|
1930
|
-
return _getRegionProperties(region, defaultLocale, customMapping);
|
|
1931
|
-
}
|
|
1932
|
-
/**
|
|
1933
|
-
* Determines whether a translation is required based on the source and target locales.
|
|
1934
|
-
*
|
|
1935
|
-
* - If the target locale is not specified, the function returns `false`, as translation is not needed.
|
|
1936
|
-
* - If the source and target locale are the same, returns `false`, indicating that no translation is necessary.
|
|
1937
|
-
* - If the `approvedLocales` array is provided, and the target locale is not within that array, the function also returns `false`.
|
|
1938
|
-
* - Otherwise, it returns `true`, meaning that a translation is required.
|
|
1939
|
-
*
|
|
1940
|
-
* @param {string} sourceLocale - The locale code for the original content (BCP 47 locale code).
|
|
1941
|
-
* @param {string} targetLocale - The locale code of the language to translate the content into (BCP 47 locale code).
|
|
1942
|
-
* @param {string[]} [approvedLocale] - An optional array of approved target locales.
|
|
1943
|
-
*
|
|
1944
|
-
* @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
|
|
1945
|
-
*/
|
|
1946
|
-
function requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping) {
|
|
1947
|
-
return require_core._requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
|
|
1948
|
-
}
|
|
1949
|
-
/**
|
|
1950
|
-
* Determines the best matching locale from the provided approved locales list.
|
|
1951
|
-
* @param {string | string[]} locales - A single locale or an array of locales sorted in preference order.
|
|
1952
|
-
* @param {string[]} [approvedLocales=this.locales] - An array of approved locales, also sorted by preference.
|
|
1953
|
-
* @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found.
|
|
1954
|
-
*/
|
|
1955
|
-
function determineLocale(locales, approvedLocales = [], customMapping = void 0) {
|
|
1956
|
-
return require_core._determineLocale(locales, approvedLocales, customMapping);
|
|
1957
|
-
}
|
|
1958
|
-
/**
|
|
1959
|
-
* Get the text direction for a given locale code using the Intl.Locale API.
|
|
1960
|
-
*
|
|
1961
|
-
* @param {string} locale - A BCP-47 locale code.
|
|
1962
|
-
* @returns {string} 'rtl' if the locale is right-to-left; otherwise 'ltr'.
|
|
1963
|
-
*/
|
|
1964
|
-
function getLocaleDirection(locale) {
|
|
1965
|
-
return require_core._getLocaleDirection(locale);
|
|
1966
|
-
}
|
|
1967
|
-
/**
|
|
1968
|
-
* Resolves the alias locale for a given locale.
|
|
1969
|
-
* @param {string} locale - The locale to resolve the alias locale for
|
|
1970
|
-
* @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the alias locale
|
|
1971
|
-
* @returns {string} The alias locale
|
|
1972
|
-
*/
|
|
1973
|
-
function resolveAliasLocale(locale, customMapping) {
|
|
1974
|
-
return require_core._resolveAliasLocale(locale, customMapping);
|
|
1975
|
-
}
|
|
1976
|
-
/**
|
|
1977
|
-
* Checks if multiple BCP 47 locale codes represent the same dialect.
|
|
1978
|
-
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
|
1979
|
-
* @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
|
|
1980
|
-
*/
|
|
1981
|
-
function isSameDialect(...locales) {
|
|
1982
|
-
return require_core._isSameDialect(...locales);
|
|
1983
|
-
}
|
|
1984
|
-
/**
|
|
1985
|
-
* Checks if multiple BCP 47 locale codes represent the same language.
|
|
1986
|
-
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
|
1987
|
-
* @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise.
|
|
1988
|
-
*/
|
|
1989
|
-
function isSameLanguage(...locales) {
|
|
1990
|
-
return require_core._isSameLanguage(...locales);
|
|
1991
|
-
}
|
|
1992
|
-
/**
|
|
1993
|
-
* Checks if a locale is a superset of another locale.
|
|
1994
|
-
* A subLocale is a subset of superLocale if it is an extension of superLocale or are otherwise identical.
|
|
1995
|
-
*
|
|
1996
|
-
* @param {string} superLocale - The locale to check if it is a superset of the other locale.
|
|
1997
|
-
* @param {string} subLocale - The locale to check if it is a subset of the other locale.
|
|
1998
|
-
* @returns {boolean} True if the first locale is a superset of the second locale, false otherwise.
|
|
1999
|
-
*/
|
|
2000
|
-
function isSupersetLocale(superLocale, subLocale) {
|
|
2001
|
-
return require_core._isSupersetLocale(superLocale, subLocale);
|
|
2002
|
-
}
|
|
2003
1866
|
const API_VERSION = API_VERSION$1;
|
|
2004
1867
|
//#endregion
|
|
2005
1868
|
exports.API_VERSION = API_VERSION;
|
|
2006
1869
|
exports.GT = GT;
|
|
2007
|
-
exports
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
exports
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
exports
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
exports
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
1870
|
+
Object.defineProperty(exports, "LocaleConfig", {
|
|
1871
|
+
enumerable: true,
|
|
1872
|
+
get: function() {
|
|
1873
|
+
return _generaltranslation_format.LocaleConfig;
|
|
1874
|
+
}
|
|
1875
|
+
});
|
|
1876
|
+
Object.defineProperty(exports, "determineLocale", {
|
|
1877
|
+
enumerable: true,
|
|
1878
|
+
get: function() {
|
|
1879
|
+
return _generaltranslation_format.determineLocale;
|
|
1880
|
+
}
|
|
1881
|
+
});
|
|
1882
|
+
Object.defineProperty(exports, "formatCurrency", {
|
|
1883
|
+
enumerable: true,
|
|
1884
|
+
get: function() {
|
|
1885
|
+
return _generaltranslation_format.formatCurrency;
|
|
1886
|
+
}
|
|
1887
|
+
});
|
|
1888
|
+
Object.defineProperty(exports, "formatCutoff", {
|
|
1889
|
+
enumerable: true,
|
|
1890
|
+
get: function() {
|
|
1891
|
+
return _generaltranslation_format.formatCutoff;
|
|
1892
|
+
}
|
|
1893
|
+
});
|
|
1894
|
+
Object.defineProperty(exports, "formatDateTime", {
|
|
1895
|
+
enumerable: true,
|
|
1896
|
+
get: function() {
|
|
1897
|
+
return _generaltranslation_format.formatDateTime;
|
|
1898
|
+
}
|
|
1899
|
+
});
|
|
1900
|
+
Object.defineProperty(exports, "formatList", {
|
|
1901
|
+
enumerable: true,
|
|
1902
|
+
get: function() {
|
|
1903
|
+
return _generaltranslation_format.formatList;
|
|
1904
|
+
}
|
|
1905
|
+
});
|
|
1906
|
+
Object.defineProperty(exports, "formatListToParts", {
|
|
1907
|
+
enumerable: true,
|
|
1908
|
+
get: function() {
|
|
1909
|
+
return _generaltranslation_format.formatListToParts;
|
|
1910
|
+
}
|
|
1911
|
+
});
|
|
1912
|
+
Object.defineProperty(exports, "formatMessage", {
|
|
1913
|
+
enumerable: true,
|
|
1914
|
+
get: function() {
|
|
1915
|
+
return _generaltranslation_format.formatMessage;
|
|
1916
|
+
}
|
|
1917
|
+
});
|
|
1918
|
+
Object.defineProperty(exports, "formatNum", {
|
|
1919
|
+
enumerable: true,
|
|
1920
|
+
get: function() {
|
|
1921
|
+
return _generaltranslation_format.formatNum;
|
|
1922
|
+
}
|
|
1923
|
+
});
|
|
1924
|
+
Object.defineProperty(exports, "formatRelativeTime", {
|
|
1925
|
+
enumerable: true,
|
|
1926
|
+
get: function() {
|
|
1927
|
+
return _generaltranslation_format.formatRelativeTime;
|
|
1928
|
+
}
|
|
1929
|
+
});
|
|
1930
|
+
Object.defineProperty(exports, "formatRelativeTimeFromDate", {
|
|
1931
|
+
enumerable: true,
|
|
1932
|
+
get: function() {
|
|
1933
|
+
return _generaltranslation_format.formatRelativeTimeFromDate;
|
|
1934
|
+
}
|
|
1935
|
+
});
|
|
1936
|
+
Object.defineProperty(exports, "getLocaleDirection", {
|
|
1937
|
+
enumerable: true,
|
|
1938
|
+
get: function() {
|
|
1939
|
+
return _generaltranslation_format.getLocaleDirection;
|
|
1940
|
+
}
|
|
1941
|
+
});
|
|
1942
|
+
Object.defineProperty(exports, "getLocaleEmoji", {
|
|
1943
|
+
enumerable: true,
|
|
1944
|
+
get: function() {
|
|
1945
|
+
return _generaltranslation_format.getLocaleEmoji;
|
|
1946
|
+
}
|
|
1947
|
+
});
|
|
1948
|
+
Object.defineProperty(exports, "getLocaleName", {
|
|
1949
|
+
enumerable: true,
|
|
1950
|
+
get: function() {
|
|
1951
|
+
return _generaltranslation_format.getLocaleName;
|
|
1952
|
+
}
|
|
1953
|
+
});
|
|
1954
|
+
Object.defineProperty(exports, "getLocaleProperties", {
|
|
1955
|
+
enumerable: true,
|
|
1956
|
+
get: function() {
|
|
1957
|
+
return _generaltranslation_format.getLocaleProperties;
|
|
1958
|
+
}
|
|
1959
|
+
});
|
|
1960
|
+
Object.defineProperty(exports, "getRegionProperties", {
|
|
1961
|
+
enumerable: true,
|
|
1962
|
+
get: function() {
|
|
1963
|
+
return _generaltranslation_format.getRegionProperties;
|
|
1964
|
+
}
|
|
1965
|
+
});
|
|
1966
|
+
Object.defineProperty(exports, "isSameDialect", {
|
|
1967
|
+
enumerable: true,
|
|
1968
|
+
get: function() {
|
|
1969
|
+
return _generaltranslation_format.isSameDialect;
|
|
1970
|
+
}
|
|
1971
|
+
});
|
|
1972
|
+
Object.defineProperty(exports, "isSameLanguage", {
|
|
1973
|
+
enumerable: true,
|
|
1974
|
+
get: function() {
|
|
1975
|
+
return _generaltranslation_format.isSameLanguage;
|
|
1976
|
+
}
|
|
1977
|
+
});
|
|
1978
|
+
Object.defineProperty(exports, "isSupersetLocale", {
|
|
1979
|
+
enumerable: true,
|
|
1980
|
+
get: function() {
|
|
1981
|
+
return _generaltranslation_format.isSupersetLocale;
|
|
1982
|
+
}
|
|
1983
|
+
});
|
|
1984
|
+
Object.defineProperty(exports, "isValidLocale", {
|
|
1985
|
+
enumerable: true,
|
|
1986
|
+
get: function() {
|
|
1987
|
+
return _generaltranslation_format.isValidLocale;
|
|
1988
|
+
}
|
|
1989
|
+
});
|
|
1990
|
+
Object.defineProperty(exports, "requiresTranslation", {
|
|
1991
|
+
enumerable: true,
|
|
1992
|
+
get: function() {
|
|
1993
|
+
return _generaltranslation_format.requiresTranslation;
|
|
1994
|
+
}
|
|
1995
|
+
});
|
|
1996
|
+
Object.defineProperty(exports, "resolveAliasLocale", {
|
|
1997
|
+
enumerable: true,
|
|
1998
|
+
get: function() {
|
|
1999
|
+
return _generaltranslation_format.resolveAliasLocale;
|
|
2000
|
+
}
|
|
2001
|
+
});
|
|
2002
|
+
Object.defineProperty(exports, "resolveCanonicalLocale", {
|
|
2003
|
+
enumerable: true,
|
|
2004
|
+
get: function() {
|
|
2005
|
+
return _generaltranslation_format.resolveCanonicalLocale;
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
Object.defineProperty(exports, "standardizeLocale", {
|
|
2009
|
+
enumerable: true,
|
|
2010
|
+
get: function() {
|
|
2011
|
+
return _generaltranslation_format.standardizeLocale;
|
|
2012
|
+
}
|
|
2013
|
+
});
|
|
2031
2014
|
|
|
2032
2015
|
//# sourceMappingURL=index.cjs.map
|