generaltranslation 8.2.13 → 8.2.15
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 +22 -1
- 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-YBGAXkqy.cjs} +74 -1
- package/dist/base64-YBGAXkqy.cjs.map +1 -0
- package/dist/{base64-DH0STixb.mjs → base64-r7YWJYWt.mjs} +51 -2
- package/dist/base64-r7YWJYWt.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 +431 -396
- 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 +278 -363
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +8 -6
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +37 -6
- package/dist/internal.d.mts +37 -6
- package/dist/internal.d.ts +2 -0
- package/dist/internal.js +1 -0
- package/dist/internal.mjs +5 -5
- 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/diagnostics.d.ts +18 -0
- package/dist/logging/diagnostics.js +64 -0
- package/dist/logging/errors.d.ts +1 -1
- package/dist/logging/errors.js +64 -11
- package/dist/logging/logger.d.ts +0 -3
- package/dist/logging/logger.js +0 -3
- package/dist/{types-AHtYZIP-.d.mts → types-CdRgQtET.d.cts} +6 -106
- package/dist/{types-Bf8_Apq_.d.cts → types-Db2Dn3oN.d.mts} +6 -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 -13
- 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,21 +1,270 @@
|
|
|
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-YBGAXkqy.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
|
-
const
|
|
9
|
-
const translationTimeoutError = (timeout) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
const GT_SOURCE = "GT";
|
|
8
|
+
const translationTimeoutError = (timeout) => require_base64.createDiagnosticMessage({
|
|
9
|
+
source: GT_SOURCE,
|
|
10
|
+
severity: "Error",
|
|
11
|
+
whatHappened: `Translation request timed out after ${timeout}ms`,
|
|
12
|
+
fix: "Try again, or increase the request timeout if the source content is large"
|
|
13
|
+
});
|
|
14
|
+
const translationRequestFailedError = (error) => require_base64.createDiagnosticMessage({
|
|
15
|
+
source: GT_SOURCE,
|
|
16
|
+
severity: "Error",
|
|
17
|
+
whatHappened: "Translation request could not be completed",
|
|
18
|
+
fix: "Check your network connection and translation credentials, then try again",
|
|
19
|
+
details: error
|
|
20
|
+
});
|
|
21
|
+
const apiError = (status, statusText, error) => require_base64.createDiagnosticMessage({
|
|
22
|
+
source: GT_SOURCE,
|
|
23
|
+
severity: "Error",
|
|
24
|
+
whatHappened: `The translation API returned ${status} ${statusText}`,
|
|
25
|
+
fix: "Check the request configuration and try again",
|
|
26
|
+
details: error
|
|
27
|
+
});
|
|
28
|
+
require_base64.createDiagnosticMessage({
|
|
29
|
+
source: GT_SOURCE,
|
|
30
|
+
severity: "Error",
|
|
31
|
+
whatHappened: "Authentication failed",
|
|
32
|
+
fix: "Check that your API key and project ID are correct"
|
|
33
|
+
});
|
|
34
|
+
const noTargetLocaleProvidedError = (functionName) => require_base64.createDiagnosticMessage({
|
|
35
|
+
source: GT_SOURCE,
|
|
36
|
+
severity: "Error",
|
|
37
|
+
whatHappened: `Cannot call \`${functionName}\` without a specified locale`,
|
|
38
|
+
fix: `Pass a locale to \`${functionName}\` or specify targetLocale in the GT constructor`
|
|
39
|
+
});
|
|
40
|
+
const noSourceLocaleProvidedError = (functionName) => require_base64.createDiagnosticMessage({
|
|
41
|
+
source: GT_SOURCE,
|
|
42
|
+
severity: "Error",
|
|
43
|
+
whatHappened: `Cannot call \`${functionName}\` without a specified locale`,
|
|
44
|
+
fix: `Pass a locale to \`${functionName}\` or specify sourceLocale in the GT constructor`
|
|
45
|
+
});
|
|
46
|
+
const noProjectIdProvidedError = (functionName) => require_base64.createDiagnosticMessage({
|
|
47
|
+
source: GT_SOURCE,
|
|
48
|
+
severity: "Error",
|
|
49
|
+
whatHappened: `Cannot call \`${functionName}\` without a specified project ID`,
|
|
50
|
+
fix: `Pass a project ID to \`${functionName}\` or specify projectId in the GT constructor`
|
|
51
|
+
});
|
|
52
|
+
const noApiKeyProvidedError = (functionName) => require_base64.createDiagnosticMessage({
|
|
53
|
+
source: GT_SOURCE,
|
|
54
|
+
severity: "Error",
|
|
55
|
+
whatHappened: `Cannot call \`${functionName}\` without a specified API key`,
|
|
56
|
+
fix: `Pass an API key to \`${functionName}\` or specify apiKey in the GT constructor`
|
|
57
|
+
});
|
|
58
|
+
const invalidLocaleError = (locale) => require_base64.createDiagnosticMessage({
|
|
59
|
+
source: GT_SOURCE,
|
|
60
|
+
severity: "Error",
|
|
61
|
+
whatHappened: `Locale "${locale}" is not valid`,
|
|
62
|
+
fix: "Use a valid BCP 47 locale code or add a custom mapping"
|
|
63
|
+
});
|
|
64
|
+
const invalidLocalesError = (locales) => require_base64.createDiagnosticMessage({
|
|
65
|
+
source: GT_SOURCE,
|
|
66
|
+
severity: "Error",
|
|
67
|
+
whatHappened: `These locales are not valid: ${locales.join(", ")}`,
|
|
68
|
+
fix: "Use valid BCP 47 locale codes or add custom mappings"
|
|
69
|
+
});
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/logging/logger.ts
|
|
72
|
+
const LOG_LEVELS = {
|
|
73
|
+
debug: 0,
|
|
74
|
+
info: 1,
|
|
75
|
+
warn: 2,
|
|
76
|
+
error: 3,
|
|
77
|
+
off: 4
|
|
78
|
+
};
|
|
79
|
+
const LOG_COLORS = {
|
|
80
|
+
debug: "\x1B[36m",
|
|
81
|
+
info: "\x1B[32m",
|
|
82
|
+
warn: "\x1B[33m",
|
|
83
|
+
error: "\x1B[31m",
|
|
84
|
+
off: ""
|
|
85
|
+
};
|
|
86
|
+
const RESET_COLOR = "\x1B[0m";
|
|
87
|
+
/**
|
|
88
|
+
* Get the configured log level from environment variable or default to 'warn'
|
|
89
|
+
*/
|
|
90
|
+
function getConfiguredLogLevel() {
|
|
91
|
+
if (typeof process !== "undefined" && process.env?._GT_LOG_LEVEL) {
|
|
92
|
+
const envLevel = process.env._GT_LOG_LEVEL.toLowerCase();
|
|
93
|
+
if (envLevel in LOG_LEVELS) return envLevel;
|
|
94
|
+
}
|
|
95
|
+
return "warn";
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Console log handler that outputs formatted messages to console
|
|
99
|
+
*/
|
|
100
|
+
var ConsoleLogHandler = class {
|
|
101
|
+
constructor(config) {
|
|
102
|
+
this.config = config;
|
|
103
|
+
}
|
|
104
|
+
handle(entry) {
|
|
105
|
+
const parts = [];
|
|
106
|
+
if (this.config.includeTimestamp) parts.push(`[${entry.timestamp.toISOString()}]`);
|
|
107
|
+
const colorCode = LOG_COLORS[entry.level];
|
|
108
|
+
const levelText = `[${entry.level.toUpperCase()}]`;
|
|
109
|
+
parts.push(`${colorCode}${levelText}${RESET_COLOR}`);
|
|
110
|
+
if (this.config.prefix) parts.push(`[${this.config.prefix}]`);
|
|
111
|
+
if (this.config.includeContext && entry.context) parts.push(`[${entry.context}]`);
|
|
112
|
+
parts.push(entry.message);
|
|
113
|
+
if (entry.metadata && Object.keys(entry.metadata).length > 0) parts.push(`\n Metadata: ${JSON.stringify(entry.metadata, null, 2)}`);
|
|
114
|
+
const formattedMessage = parts.join(" ");
|
|
115
|
+
switch (entry.level) {
|
|
116
|
+
case "debug":
|
|
117
|
+
console.debug(formattedMessage);
|
|
118
|
+
break;
|
|
119
|
+
case "info":
|
|
120
|
+
console.info(formattedMessage);
|
|
121
|
+
break;
|
|
122
|
+
case "warn":
|
|
123
|
+
console.warn(formattedMessage);
|
|
124
|
+
break;
|
|
125
|
+
case "error":
|
|
126
|
+
console.error(formattedMessage);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Main Logger class providing structured logging capabilities.
|
|
133
|
+
*/
|
|
134
|
+
var Logger = class {
|
|
135
|
+
constructor(config = {}) {
|
|
136
|
+
this.config = {
|
|
137
|
+
level: getConfiguredLogLevel(),
|
|
138
|
+
includeTimestamp: true,
|
|
139
|
+
includeContext: true,
|
|
140
|
+
enableConsole: true,
|
|
141
|
+
handlers: [],
|
|
142
|
+
...config
|
|
143
|
+
};
|
|
144
|
+
this.handlers = [...this.config.handlers || []];
|
|
145
|
+
if (this.config.enableConsole) this.handlers.push(new ConsoleLogHandler(this.config));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Add a custom log handler
|
|
149
|
+
*/
|
|
150
|
+
addHandler(handler) {
|
|
151
|
+
this.handlers.push(handler);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Remove a log handler
|
|
155
|
+
*/
|
|
156
|
+
removeHandler(handler) {
|
|
157
|
+
const index = this.handlers.indexOf(handler);
|
|
158
|
+
if (index > -1) this.handlers.splice(index, 1);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Update logger configuration
|
|
162
|
+
*/
|
|
163
|
+
configure(config) {
|
|
164
|
+
this.config = {
|
|
165
|
+
...this.config,
|
|
166
|
+
...config
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Check if a log level should be output based on current configuration
|
|
171
|
+
*/
|
|
172
|
+
shouldLog(level) {
|
|
173
|
+
return LOG_LEVELS[level] >= LOG_LEVELS[this.config.level];
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Internal logging method that creates log entries and passes them to handlers
|
|
177
|
+
*/
|
|
178
|
+
log(level, message, context, metadata) {
|
|
179
|
+
if (!this.shouldLog(level)) return;
|
|
180
|
+
const entry = {
|
|
181
|
+
level,
|
|
182
|
+
message,
|
|
183
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
184
|
+
context,
|
|
185
|
+
metadata
|
|
186
|
+
};
|
|
187
|
+
this.handlers.forEach((handler) => {
|
|
188
|
+
try {
|
|
189
|
+
handler.handle(entry);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.error("Error in log handler:", error);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Log a debug message
|
|
197
|
+
* Used for detailed diagnostic information, typically of interest only when diagnosing problems
|
|
198
|
+
*/
|
|
199
|
+
debug(message, context, metadata) {
|
|
200
|
+
this.log("debug", message, context, metadata);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Log an info message
|
|
204
|
+
* Used for general information about application operation.
|
|
205
|
+
*/
|
|
206
|
+
info(message, context, metadata) {
|
|
207
|
+
this.log("info", message, context, metadata);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Log a warning message
|
|
211
|
+
* Used for potentially problematic situations that don't prevent operation
|
|
212
|
+
*/
|
|
213
|
+
warn(message, context, metadata) {
|
|
214
|
+
this.log("warn", message, context, metadata);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Log an error message
|
|
218
|
+
* Used for error events that might still allow the application to continue.
|
|
219
|
+
*/
|
|
220
|
+
error(message, context, metadata) {
|
|
221
|
+
this.log("error", message, context, metadata);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Create a child logger with a specific context
|
|
225
|
+
*/
|
|
226
|
+
child(context) {
|
|
227
|
+
return new ContextLogger(this, context);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Get current logger configuration
|
|
231
|
+
*/
|
|
232
|
+
getConfig() {
|
|
233
|
+
return { ...this.config };
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Context logger that automatically includes context information.
|
|
238
|
+
*/
|
|
239
|
+
var ContextLogger = class ContextLogger {
|
|
240
|
+
constructor(logger, context) {
|
|
241
|
+
this.logger = logger;
|
|
242
|
+
this.context = context;
|
|
243
|
+
}
|
|
244
|
+
debug(message, metadata) {
|
|
245
|
+
this.logger.debug(message, this.context, metadata);
|
|
246
|
+
}
|
|
247
|
+
info(message, metadata) {
|
|
248
|
+
this.logger.info(message, this.context, metadata);
|
|
249
|
+
}
|
|
250
|
+
warn(message, metadata) {
|
|
251
|
+
this.logger.warn(message, this.context, metadata);
|
|
252
|
+
}
|
|
253
|
+
error(message, metadata) {
|
|
254
|
+
this.logger.error(message, this.context, metadata);
|
|
255
|
+
}
|
|
256
|
+
child(childContext) {
|
|
257
|
+
return new ContextLogger(this.logger, `${this.context}:${childContext}`);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const defaultLogger = new Logger({
|
|
261
|
+
level: getConfiguredLogLevel(),
|
|
262
|
+
includeTimestamp: true,
|
|
263
|
+
includeContext: true,
|
|
264
|
+
prefix: "GT"
|
|
265
|
+
});
|
|
266
|
+
const fetchLogger = defaultLogger.child("fetch");
|
|
267
|
+
const gtInstanceLogger = defaultLogger.child("GT instance");
|
|
19
268
|
//#endregion
|
|
20
269
|
//#region src/translate/utils/fetchWithTimeout.ts
|
|
21
270
|
/**
|
|
@@ -31,7 +280,7 @@ const invalidLocalesError = (locales) => `${GT_ERROR_PREFIX} Invalid locales: ${
|
|
|
31
280
|
async function fetchWithTimeout(url, options, timeout) {
|
|
32
281
|
const controller = new AbortController();
|
|
33
282
|
const signal = controller.signal;
|
|
34
|
-
timeout = timeout ? timeout :
|
|
283
|
+
timeout = timeout ? timeout : require_base64.defaultTimeout;
|
|
35
284
|
const timeoutId = timeout ? setTimeout(() => controller.abort(), timeout) : null;
|
|
36
285
|
try {
|
|
37
286
|
return await fetch(url, {
|
|
@@ -66,11 +315,11 @@ async function validateResponse(response) {
|
|
|
66
315
|
function handleFetchError(error, timeout) {
|
|
67
316
|
if (error instanceof Error && error.name === "AbortError") {
|
|
68
317
|
const errorMessage = translationTimeoutError(timeout);
|
|
69
|
-
|
|
318
|
+
fetchLogger.error(errorMessage);
|
|
70
319
|
throw new Error(errorMessage);
|
|
71
320
|
}
|
|
72
321
|
const errorMessage = translationRequestFailedError(error instanceof Error ? error.message : String(error));
|
|
73
|
-
|
|
322
|
+
fetchLogger.error(errorMessage);
|
|
74
323
|
throw error;
|
|
75
324
|
}
|
|
76
325
|
//#endregion
|
|
@@ -361,61 +610,6 @@ async function _submitUserEditDiffs(payload, config, options = {}) {
|
|
|
361
610
|
return { success: true };
|
|
362
611
|
}
|
|
363
612
|
//#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
613
|
//#region src/translate/uploadSourceFiles.ts
|
|
420
614
|
/**
|
|
421
615
|
* @internal
|
|
@@ -527,7 +721,7 @@ async function _querySourceFile(query, options, config) {
|
|
|
527
721
|
*/
|
|
528
722
|
async function _getProjectData(projectId, options, config) {
|
|
529
723
|
const { baseUrl } = config;
|
|
530
|
-
const timeout = options.timeout ? options.timeout :
|
|
724
|
+
const timeout = options.timeout ? options.timeout : require_base64.defaultTimeout;
|
|
531
725
|
const url = `${baseUrl || "https://api2.gtx.dev"}/v2/project/info/${encodeURIComponent(projectId)}`;
|
|
532
726
|
let response;
|
|
533
727
|
try {
|
|
@@ -791,19 +985,19 @@ var GT = class {
|
|
|
791
985
|
if (devApiKey) this.devApiKey = devApiKey;
|
|
792
986
|
if (projectId) this.projectId = projectId;
|
|
793
987
|
if (sourceLocale) {
|
|
794
|
-
this.sourceLocale =
|
|
795
|
-
if (!
|
|
988
|
+
this.sourceLocale = (0, _generaltranslation_format.standardizeLocale)(sourceLocale);
|
|
989
|
+
if (!(0, _generaltranslation_format.isValidLocale)(this.sourceLocale, customMapping)) throw new Error(invalidLocaleError(this.sourceLocale));
|
|
796
990
|
}
|
|
797
991
|
if (targetLocale) {
|
|
798
|
-
this.targetLocale =
|
|
799
|
-
if (!
|
|
992
|
+
this.targetLocale = (0, _generaltranslation_format.standardizeLocale)(targetLocale);
|
|
993
|
+
if (!(0, _generaltranslation_format.isValidLocale)(this.targetLocale, customMapping)) throw new Error(invalidLocaleError(this.targetLocale));
|
|
800
994
|
}
|
|
801
995
|
if (locales) {
|
|
802
996
|
const result = [];
|
|
803
997
|
const invalidLocales = [];
|
|
804
998
|
locales.forEach((locale) => {
|
|
805
|
-
const standardizedLocale =
|
|
806
|
-
if (
|
|
999
|
+
const standardizedLocale = (0, _generaltranslation_format.standardizeLocale)(locale);
|
|
1000
|
+
if ((0, _generaltranslation_format.isValidLocale)(standardizedLocale)) result.push(standardizedLocale);
|
|
807
1001
|
else invalidLocales.push(locale);
|
|
808
1002
|
});
|
|
809
1003
|
if (invalidLocales.length > 0) throw new Error(invalidLocalesError(invalidLocales));
|
|
@@ -814,7 +1008,7 @@ var GT = class {
|
|
|
814
1008
|
this.customMapping = customMapping;
|
|
815
1009
|
this.reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
|
|
816
1010
|
}
|
|
817
|
-
this._localeConfig = new
|
|
1011
|
+
this._localeConfig = new _generaltranslation_format.LocaleConfig({
|
|
818
1012
|
defaultLocale: this.sourceLocale,
|
|
819
1013
|
locales: this.locales ?? [],
|
|
820
1014
|
customMapping: this.customMapping
|
|
@@ -968,12 +1162,12 @@ var GT = class {
|
|
|
968
1162
|
};
|
|
969
1163
|
if (!mergedOptions.sourceLocale) {
|
|
970
1164
|
const error = noSourceLocaleProvidedError("enqueueFiles");
|
|
971
|
-
|
|
1165
|
+
gtInstanceLogger.error(error);
|
|
972
1166
|
throw new Error(error);
|
|
973
1167
|
}
|
|
974
1168
|
if (!mergedOptions.targetLocales || mergedOptions.targetLocales.length === 0) {
|
|
975
1169
|
const error = noTargetLocaleProvidedError("enqueueFiles");
|
|
976
|
-
|
|
1170
|
+
gtInstanceLogger.error(error);
|
|
977
1171
|
throw new Error(error);
|
|
978
1172
|
}
|
|
979
1173
|
mergedOptions = {
|
|
@@ -1187,7 +1381,7 @@ var GT = class {
|
|
|
1187
1381
|
let targetLocale = options?.targetLocale || this.targetLocale;
|
|
1188
1382
|
if (!targetLocale) {
|
|
1189
1383
|
const error = noTargetLocaleProvidedError("translate");
|
|
1190
|
-
|
|
1384
|
+
gtInstanceLogger.error(error);
|
|
1191
1385
|
throw new Error(error);
|
|
1192
1386
|
}
|
|
1193
1387
|
targetLocale = this.resolveCanonicalLocale(targetLocale);
|
|
@@ -1204,7 +1398,7 @@ var GT = class {
|
|
|
1204
1398
|
let targetLocale = options?.targetLocale || this.targetLocale;
|
|
1205
1399
|
if (!targetLocale) {
|
|
1206
1400
|
const error = noTargetLocaleProvidedError("translateMany");
|
|
1207
|
-
|
|
1401
|
+
gtInstanceLogger.error(error);
|
|
1208
1402
|
throw new Error(error);
|
|
1209
1403
|
}
|
|
1210
1404
|
targetLocale = this.resolveCanonicalLocale(targetLocale);
|
|
@@ -1269,7 +1463,7 @@ var GT = class {
|
|
|
1269
1463
|
};
|
|
1270
1464
|
if (!mergedOptions.sourceLocale) {
|
|
1271
1465
|
const error = noSourceLocaleProvidedError("uploadTranslations");
|
|
1272
|
-
|
|
1466
|
+
gtInstanceLogger.error(error);
|
|
1273
1467
|
throw new Error(error);
|
|
1274
1468
|
}
|
|
1275
1469
|
const result = await _uploadTranslations(files.map((f) => ({
|
|
@@ -1568,7 +1762,7 @@ var GT = class {
|
|
|
1568
1762
|
}
|
|
1569
1763
|
customMapping = this.customRegionMapping;
|
|
1570
1764
|
}
|
|
1571
|
-
return
|
|
1765
|
+
return (0, _generaltranslation_format.getRegionProperties)(region, this.targetLocale, customMapping);
|
|
1572
1766
|
}
|
|
1573
1767
|
/**
|
|
1574
1768
|
* Determines whether a translation is required based on the source and target locales.
|
|
@@ -1588,7 +1782,7 @@ var GT = class {
|
|
|
1588
1782
|
if (!sourceLocale) throw new Error(noSourceLocaleProvidedError("requiresTranslation"));
|
|
1589
1783
|
if (!targetLocale) throw new Error(noTargetLocaleProvidedError("requiresTranslation"));
|
|
1590
1784
|
if (customMapping === this.customMapping) return this.localeConfig.requiresTranslation(targetLocale, sourceLocale, approvedLocales);
|
|
1591
|
-
return
|
|
1785
|
+
return (0, _generaltranslation_format.requiresTranslation)(sourceLocale, targetLocale, approvedLocales, customMapping);
|
|
1592
1786
|
}
|
|
1593
1787
|
/**
|
|
1594
1788
|
* Determines the best matching locale from the provided approved locales list.
|
|
@@ -1603,7 +1797,7 @@ var GT = class {
|
|
|
1603
1797
|
*/
|
|
1604
1798
|
determineLocale(locales, approvedLocales = this.locales || [], customMapping = this.customMapping) {
|
|
1605
1799
|
if (customMapping === this.customMapping) return this.localeConfig.determineLocale(locales, approvedLocales ?? []);
|
|
1606
|
-
return
|
|
1800
|
+
return (0, _generaltranslation_format.determineLocale)(locales, approvedLocales, customMapping);
|
|
1607
1801
|
}
|
|
1608
1802
|
/**
|
|
1609
1803
|
* Gets the text direction for a given locale code.
|
|
@@ -1635,7 +1829,7 @@ var GT = class {
|
|
|
1635
1829
|
isValidLocale(locale = this.targetLocale, customMapping = this.customMapping) {
|
|
1636
1830
|
if (!locale) throw new Error(noTargetLocaleProvidedError("isValidLocale"));
|
|
1637
1831
|
if (customMapping === this.customMapping) return this.localeConfig.isValidLocale(locale);
|
|
1638
|
-
return
|
|
1832
|
+
return (0, _generaltranslation_format.isValidLocale)(locale, customMapping);
|
|
1639
1833
|
}
|
|
1640
1834
|
/**
|
|
1641
1835
|
* Resolves the canonical locale for a given locale.
|
|
@@ -1646,7 +1840,7 @@ var GT = class {
|
|
|
1646
1840
|
resolveCanonicalLocale(locale = this.targetLocale, customMapping = this.customMapping) {
|
|
1647
1841
|
if (!locale) throw new Error(noTargetLocaleProvidedError("resolveCanonicalLocale"));
|
|
1648
1842
|
if (customMapping === this.customMapping) return this.localeConfig.resolveCanonicalLocale(locale);
|
|
1649
|
-
return
|
|
1843
|
+
return (0, _generaltranslation_format.resolveCanonicalLocale)(locale, customMapping);
|
|
1650
1844
|
}
|
|
1651
1845
|
/**
|
|
1652
1846
|
* Resolves the alias locale for a given locale.
|
|
@@ -1657,7 +1851,7 @@ var GT = class {
|
|
|
1657
1851
|
resolveAliasLocale(locale, customMapping = this.customMapping) {
|
|
1658
1852
|
if (!locale) throw new Error(noTargetLocaleProvidedError("resolveAliasLocale"));
|
|
1659
1853
|
if (customMapping === this.customMapping) return this.localeConfig.resolveAliasLocale(locale);
|
|
1660
|
-
return
|
|
1854
|
+
return (0, _generaltranslation_format.resolveAliasLocale)(locale, customMapping);
|
|
1661
1855
|
}
|
|
1662
1856
|
/**
|
|
1663
1857
|
* Standardizes a BCP 47 locale code to ensure correct formatting.
|
|
@@ -1721,312 +1915,153 @@ var GT = class {
|
|
|
1721
1915
|
return this.localeConfig.isSupersetLocale(superLocale, subLocale);
|
|
1722
1916
|
}
|
|
1723
1917
|
};
|
|
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
1918
|
const API_VERSION = API_VERSION$1;
|
|
2004
1919
|
//#endregion
|
|
2005
1920
|
exports.API_VERSION = API_VERSION;
|
|
2006
1921
|
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
|
-
|
|
1922
|
+
Object.defineProperty(exports, "LocaleConfig", {
|
|
1923
|
+
enumerable: true,
|
|
1924
|
+
get: function() {
|
|
1925
|
+
return _generaltranslation_format.LocaleConfig;
|
|
1926
|
+
}
|
|
1927
|
+
});
|
|
1928
|
+
Object.defineProperty(exports, "determineLocale", {
|
|
1929
|
+
enumerable: true,
|
|
1930
|
+
get: function() {
|
|
1931
|
+
return _generaltranslation_format.determineLocale;
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
Object.defineProperty(exports, "formatCurrency", {
|
|
1935
|
+
enumerable: true,
|
|
1936
|
+
get: function() {
|
|
1937
|
+
return _generaltranslation_format.formatCurrency;
|
|
1938
|
+
}
|
|
1939
|
+
});
|
|
1940
|
+
Object.defineProperty(exports, "formatCutoff", {
|
|
1941
|
+
enumerable: true,
|
|
1942
|
+
get: function() {
|
|
1943
|
+
return _generaltranslation_format.formatCutoff;
|
|
1944
|
+
}
|
|
1945
|
+
});
|
|
1946
|
+
Object.defineProperty(exports, "formatDateTime", {
|
|
1947
|
+
enumerable: true,
|
|
1948
|
+
get: function() {
|
|
1949
|
+
return _generaltranslation_format.formatDateTime;
|
|
1950
|
+
}
|
|
1951
|
+
});
|
|
1952
|
+
Object.defineProperty(exports, "formatList", {
|
|
1953
|
+
enumerable: true,
|
|
1954
|
+
get: function() {
|
|
1955
|
+
return _generaltranslation_format.formatList;
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1958
|
+
Object.defineProperty(exports, "formatListToParts", {
|
|
1959
|
+
enumerable: true,
|
|
1960
|
+
get: function() {
|
|
1961
|
+
return _generaltranslation_format.formatListToParts;
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
Object.defineProperty(exports, "formatMessage", {
|
|
1965
|
+
enumerable: true,
|
|
1966
|
+
get: function() {
|
|
1967
|
+
return _generaltranslation_format.formatMessage;
|
|
1968
|
+
}
|
|
1969
|
+
});
|
|
1970
|
+
Object.defineProperty(exports, "formatNum", {
|
|
1971
|
+
enumerable: true,
|
|
1972
|
+
get: function() {
|
|
1973
|
+
return _generaltranslation_format.formatNum;
|
|
1974
|
+
}
|
|
1975
|
+
});
|
|
1976
|
+
Object.defineProperty(exports, "formatRelativeTime", {
|
|
1977
|
+
enumerable: true,
|
|
1978
|
+
get: function() {
|
|
1979
|
+
return _generaltranslation_format.formatRelativeTime;
|
|
1980
|
+
}
|
|
1981
|
+
});
|
|
1982
|
+
Object.defineProperty(exports, "formatRelativeTimeFromDate", {
|
|
1983
|
+
enumerable: true,
|
|
1984
|
+
get: function() {
|
|
1985
|
+
return _generaltranslation_format.formatRelativeTimeFromDate;
|
|
1986
|
+
}
|
|
1987
|
+
});
|
|
1988
|
+
Object.defineProperty(exports, "getLocaleDirection", {
|
|
1989
|
+
enumerable: true,
|
|
1990
|
+
get: function() {
|
|
1991
|
+
return _generaltranslation_format.getLocaleDirection;
|
|
1992
|
+
}
|
|
1993
|
+
});
|
|
1994
|
+
Object.defineProperty(exports, "getLocaleEmoji", {
|
|
1995
|
+
enumerable: true,
|
|
1996
|
+
get: function() {
|
|
1997
|
+
return _generaltranslation_format.getLocaleEmoji;
|
|
1998
|
+
}
|
|
1999
|
+
});
|
|
2000
|
+
Object.defineProperty(exports, "getLocaleName", {
|
|
2001
|
+
enumerable: true,
|
|
2002
|
+
get: function() {
|
|
2003
|
+
return _generaltranslation_format.getLocaleName;
|
|
2004
|
+
}
|
|
2005
|
+
});
|
|
2006
|
+
Object.defineProperty(exports, "getLocaleProperties", {
|
|
2007
|
+
enumerable: true,
|
|
2008
|
+
get: function() {
|
|
2009
|
+
return _generaltranslation_format.getLocaleProperties;
|
|
2010
|
+
}
|
|
2011
|
+
});
|
|
2012
|
+
Object.defineProperty(exports, "getRegionProperties", {
|
|
2013
|
+
enumerable: true,
|
|
2014
|
+
get: function() {
|
|
2015
|
+
return _generaltranslation_format.getRegionProperties;
|
|
2016
|
+
}
|
|
2017
|
+
});
|
|
2018
|
+
Object.defineProperty(exports, "isSameDialect", {
|
|
2019
|
+
enumerable: true,
|
|
2020
|
+
get: function() {
|
|
2021
|
+
return _generaltranslation_format.isSameDialect;
|
|
2022
|
+
}
|
|
2023
|
+
});
|
|
2024
|
+
Object.defineProperty(exports, "isSameLanguage", {
|
|
2025
|
+
enumerable: true,
|
|
2026
|
+
get: function() {
|
|
2027
|
+
return _generaltranslation_format.isSameLanguage;
|
|
2028
|
+
}
|
|
2029
|
+
});
|
|
2030
|
+
Object.defineProperty(exports, "isSupersetLocale", {
|
|
2031
|
+
enumerable: true,
|
|
2032
|
+
get: function() {
|
|
2033
|
+
return _generaltranslation_format.isSupersetLocale;
|
|
2034
|
+
}
|
|
2035
|
+
});
|
|
2036
|
+
Object.defineProperty(exports, "isValidLocale", {
|
|
2037
|
+
enumerable: true,
|
|
2038
|
+
get: function() {
|
|
2039
|
+
return _generaltranslation_format.isValidLocale;
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
Object.defineProperty(exports, "requiresTranslation", {
|
|
2043
|
+
enumerable: true,
|
|
2044
|
+
get: function() {
|
|
2045
|
+
return _generaltranslation_format.requiresTranslation;
|
|
2046
|
+
}
|
|
2047
|
+
});
|
|
2048
|
+
Object.defineProperty(exports, "resolveAliasLocale", {
|
|
2049
|
+
enumerable: true,
|
|
2050
|
+
get: function() {
|
|
2051
|
+
return _generaltranslation_format.resolveAliasLocale;
|
|
2052
|
+
}
|
|
2053
|
+
});
|
|
2054
|
+
Object.defineProperty(exports, "resolveCanonicalLocale", {
|
|
2055
|
+
enumerable: true,
|
|
2056
|
+
get: function() {
|
|
2057
|
+
return _generaltranslation_format.resolveCanonicalLocale;
|
|
2058
|
+
}
|
|
2059
|
+
});
|
|
2060
|
+
Object.defineProperty(exports, "standardizeLocale", {
|
|
2061
|
+
enumerable: true,
|
|
2062
|
+
get: function() {
|
|
2063
|
+
return _generaltranslation_format.standardizeLocale;
|
|
2064
|
+
}
|
|
2065
|
+
});
|
|
2031
2066
|
|
|
2032
2067
|
//# sourceMappingURL=index.cjs.map
|