generaltranslation 9.3.0 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/adapter/createGtApi.d.ts +102 -0
- package/dist/adapter/createGtApi.js +368 -0
- package/dist/{derive-Yxp38Tjn.cjs → derive-2CDqwrvS.cjs} +20 -1
- package/dist/derive-2CDqwrvS.cjs.map +1 -0
- package/dist/{derive-BEA36WQM.mjs → derive-CTzR56T_.mjs} +9 -2
- package/dist/derive-CTzR56T_.mjs.map +1 -0
- package/dist/id/hashSource.d.ts +2 -1
- package/dist/id/hashSource.js +3 -2
- package/dist/id/types.d.ts +2 -0
- package/dist/{id-BMOKDfiZ.mjs → id-X2zyx5Jk.mjs} +5 -3
- package/dist/id-X2zyx5Jk.mjs.map +1 -0
- package/dist/{id-BpSNpXZu.cjs → id-pdr3R1xs.cjs} +5 -3
- package/dist/{id-BpSNpXZu.cjs.map → id-pdr3R1xs.cjs.map} +1 -1
- package/dist/id.cjs +1 -1
- package/dist/id.d.cts +4 -2
- package/dist/id.d.mts +4 -2
- package/dist/id.mjs +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/internal.cjs +174 -2
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +108 -4
- package/dist/internal.d.mts +108 -4
- package/dist/internal.d.ts +3 -1
- package/dist/internal.js +2 -1
- package/dist/internal.mjs +172 -2
- package/dist/internal.mjs.map +1 -1
- package/dist/openapi.json +4929 -2181
- package/dist/{runtime-DeF1Ef5w.cjs → runtime-BGUJYxhI.cjs} +3 -2
- package/dist/runtime-BGUJYxhI.cjs.map +1 -0
- package/dist/{runtime-CqKaoInO.mjs → runtime-BiKgjDUI.mjs} +3 -2
- package/dist/runtime-BiKgjDUI.mjs.map +1 -0
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.d.cts +1 -1
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/translate/translateMany.js +1 -1
- package/dist/{types-BUNfoXph.d.mts → types-Dp1drjxq.d.mts} +7 -3
- package/dist/{types-Do446qa9.d.cts → types-bCr8pV1Z.d.cts} +7 -3
- package/dist/types-dir/api/entry.d.ts +3 -0
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +1 -0
- package/dist/utils/base64.d.ts +3 -0
- package/dist/utils/base64.js +7 -0
- package/package.json +2 -2
- package/dist/derive-BEA36WQM.mjs.map +0 -1
- package/dist/derive-Yxp38Tjn.cjs.map +0 -1
- package/dist/id-BMOKDfiZ.mjs.map +0 -1
- package/dist/runtime-CqKaoInO.mjs.map +0 -1
- package/dist/runtime-DeF1Ef5w.cjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as FileUpload, A as SubmitUserEditDiffsPayload, B as GetOrphanedFilesResult, G as BranchDataResult, H as FileDataQuery, I as MoveMapping, M as AwaitJobsResult, P as CheckJobStatusResult, Q as PublishFilesResult, R as ProcessMovesOptions, St as FileQueryResult, U as FileDataResult, W as BranchQuery, X as DownloadFileOptions, Z as PublishFileEntry, at as CreateTagOptions, bt as CheckFileTranslationsOptions, ct as DownloadFileBatchOptions, et as UploadFilesOptions, ht as FileReferenceIds, it as SetupProjectResult, j as AwaitJobsOptions, lt as DownloadFileBatchRequest, nt as SetupProjectFileReference, ot as CreateTagResult, rt as SetupProjectOptions, st as EnqueueFilesOptions, tt as UploadFilesResponse, ut as DownloadFileBatchResult, vt as EnqueueFilesResult, xt as FileQuery, z as ProcessMovesResponse } from "./types-Dp1drjxq.mjs";
|
|
2
2
|
import { GTConstructorParams, GTRuntime } from "./runtime.mjs";
|
|
3
3
|
import { n as declareVar, r as decodeVars, t as derive } from "./derive-texIAHzc.mjs";
|
|
4
4
|
import { LocaleConfig, LocaleConfigConstructorParams, determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale, standardizeLocale } from "@generaltranslation/format";
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { l as defaultTimeout } from "./unwrapApiResult-BzGfPw75.mjs";
|
|
2
|
-
import { a as gtInstanceLogger, c as translationRequestFailedError, i as fetchLogger, l as translationTimeoutError, n as validateResponse, o as noSourceLocaleProvidedError, r as fetchWithTimeout, s as noTargetLocaleProvidedError, t as GTRuntime } from "./runtime-
|
|
3
|
-
import { c as decode,
|
|
2
|
+
import { a as gtInstanceLogger, c as translationRequestFailedError, i as fetchLogger, l as translationTimeoutError, n as validateResponse, o as noSourceLocaleProvidedError, r as fetchWithTimeout, s as noTargetLocaleProvidedError, t as GTRuntime } from "./runtime-BiKgjDUI.mjs";
|
|
3
|
+
import { c as decode, f as isSupportedFileFormatTransform, n as declareVar, p as API_VERSION, r as decodeVars, t as derive, u as encode } from "./derive-CTzR56T_.mjs";
|
|
4
4
|
import { n as isBinaryFileFormat } from "./file-Dga6cyM8.mjs";
|
|
5
5
|
import { LocaleConfig, determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale, standardizeLocale } from "@generaltranslation/format";
|
|
6
6
|
//#region src/translate/utils/handleFetchError.ts
|
package/dist/internal.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_unwrapApiResult = require("./unwrapApiResult-Dv6Mfw_K.cjs");
|
|
3
|
-
const require_derive = require("./derive-
|
|
3
|
+
const require_derive = require("./derive-2CDqwrvS.cjs");
|
|
4
4
|
const require_isVariable = require("./isVariable-I3nllgeI.cjs");
|
|
5
|
+
let _generaltranslation_api = require("@generaltranslation/api");
|
|
6
|
+
let _generaltranslation_format = require("@generaltranslation/format");
|
|
5
7
|
let _generaltranslation_icu = require("@generaltranslation/icu");
|
|
6
8
|
let _generaltranslation_format_internal = require("@generaltranslation/format/internal");
|
|
7
|
-
let _generaltranslation_api = require("@generaltranslation/api");
|
|
8
9
|
//#region src/settings/plurals.ts
|
|
9
10
|
const pluralForms = [
|
|
10
11
|
"singular",
|
|
@@ -61,6 +62,174 @@ function minifyVariableType(variableType) {
|
|
|
61
62
|
return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];
|
|
62
63
|
}
|
|
63
64
|
//#endregion
|
|
65
|
+
//#region src/adapter/createGtApi.ts
|
|
66
|
+
function createGtApiAdapter(defaultConfig) {
|
|
67
|
+
let client = defaultConfig ? (0, _generaltranslation_api.createApiClient)(defaultConfig) : void 0;
|
|
68
|
+
let configuredClientConfig = defaultConfig;
|
|
69
|
+
let customMapping;
|
|
70
|
+
function getClient() {
|
|
71
|
+
if (!client) throw new Error("API client not configured — call configureApiClient first");
|
|
72
|
+
return client;
|
|
73
|
+
}
|
|
74
|
+
function getClientConfig() {
|
|
75
|
+
if (!configuredClientConfig) throw new Error("API client not configured — call configureApiClient first");
|
|
76
|
+
return configuredClientConfig;
|
|
77
|
+
}
|
|
78
|
+
function configure(config) {
|
|
79
|
+
const { customMapping: mapping, ...clientConfig } = config;
|
|
80
|
+
client = (0, _generaltranslation_api.createApiClient)(clientConfig);
|
|
81
|
+
configuredClientConfig = clientConfig;
|
|
82
|
+
customMapping = mapping;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
configure,
|
|
86
|
+
getClient,
|
|
87
|
+
getClientConfig,
|
|
88
|
+
resolveAliasLocale(locale) {
|
|
89
|
+
return (0, _generaltranslation_format.resolveAliasLocale)(locale, customMapping);
|
|
90
|
+
},
|
|
91
|
+
resolveCanonicalLocale(locale) {
|
|
92
|
+
return (0, _generaltranslation_format.resolveCanonicalLocale)(locale, customMapping);
|
|
93
|
+
},
|
|
94
|
+
async createBranch(body) {
|
|
95
|
+
return require_unwrapApiResult.unwrapApiResult(await (0, _generaltranslation_api.createBranch)({
|
|
96
|
+
body,
|
|
97
|
+
client: getClient()
|
|
98
|
+
}));
|
|
99
|
+
},
|
|
100
|
+
async queryFileData(body) {
|
|
101
|
+
const result = require_unwrapApiResult.unwrapApiResult(await (0, _generaltranslation_api.getFileInfo)({
|
|
102
|
+
body: {
|
|
103
|
+
...body,
|
|
104
|
+
translatedFiles: body.translatedFiles?.map((file) => ({
|
|
105
|
+
...file,
|
|
106
|
+
locale: (0, _generaltranslation_format.resolveCanonicalLocale)(file.locale, customMapping)
|
|
107
|
+
}))
|
|
108
|
+
},
|
|
109
|
+
client: getClient()
|
|
110
|
+
}));
|
|
111
|
+
return {
|
|
112
|
+
...result,
|
|
113
|
+
translatedFiles: result.translatedFiles.map((file) => ({
|
|
114
|
+
...file,
|
|
115
|
+
locale: (0, _generaltranslation_format.resolveAliasLocale)(file.locale, customMapping)
|
|
116
|
+
})),
|
|
117
|
+
sourceFiles: result.sourceFiles.map((file) => ({
|
|
118
|
+
...file,
|
|
119
|
+
sourceLocale: (0, _generaltranslation_format.resolveAliasLocale)(file.sourceLocale, customMapping),
|
|
120
|
+
locales: file.locales.map((locale) => (0, _generaltranslation_format.resolveAliasLocale)(locale, customMapping))
|
|
121
|
+
}))
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
async downloadFileBatch(files) {
|
|
125
|
+
const request = async (batch) => require_unwrapApiResult.unwrapApiResult(await (0, _generaltranslation_api.downloadFiles)({
|
|
126
|
+
body: batch.map((file) => ({
|
|
127
|
+
...file,
|
|
128
|
+
locale: file.locale ? (0, _generaltranslation_format.resolveCanonicalLocale)(file.locale, customMapping) : void 0
|
|
129
|
+
})),
|
|
130
|
+
client: getClient()
|
|
131
|
+
}));
|
|
132
|
+
const responses = await (0, _generaltranslation_api.processBatches)(files, async (batch) => [await request(batch)]);
|
|
133
|
+
return {
|
|
134
|
+
files: responses.flatMap((response) => response.files.map((file) => ({
|
|
135
|
+
...file,
|
|
136
|
+
...file.locale && { locale: (0, _generaltranslation_format.resolveAliasLocale)(file.locale, customMapping) },
|
|
137
|
+
data: require_derive.decodeFileContent(file.data, file.fileFormat),
|
|
138
|
+
metadata: file.metadata
|
|
139
|
+
}))),
|
|
140
|
+
count: responses.reduce((count, response) => count + response.count, 0),
|
|
141
|
+
pending: responses.flatMap((response) => response.pending ?? [])
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
async setupProject(files, options = {}) {
|
|
145
|
+
return require_unwrapApiResult.unwrapApiResult(await (0, _generaltranslation_api.generateProjectContext)({
|
|
146
|
+
body: {
|
|
147
|
+
files: files.map(({ branchId, fileId, versionId }) => ({
|
|
148
|
+
branchId,
|
|
149
|
+
fileId,
|
|
150
|
+
versionId
|
|
151
|
+
})),
|
|
152
|
+
locales: options.locales?.map((locale) => (0, _generaltranslation_format.resolveCanonicalLocale)(locale, customMapping)),
|
|
153
|
+
force: options.force
|
|
154
|
+
},
|
|
155
|
+
client: getClient()
|
|
156
|
+
}));
|
|
157
|
+
},
|
|
158
|
+
async enqueueFiles(files, options) {
|
|
159
|
+
const targetLocales = options.targetLocales.map((locale) => (0, _generaltranslation_format.resolveCanonicalLocale)(locale, customMapping));
|
|
160
|
+
const result = await (0, _generaltranslation_api.processBatches)(files, async (batch) => {
|
|
161
|
+
const response = require_unwrapApiResult.unwrapApiResult(await (0, _generaltranslation_api.enqueueFileTranslations)({
|
|
162
|
+
body: {
|
|
163
|
+
files: batch.map(({ branchId, fileId, versionId, fileName, transformFormat }) => ({
|
|
164
|
+
branchId,
|
|
165
|
+
fileId,
|
|
166
|
+
versionId,
|
|
167
|
+
fileName,
|
|
168
|
+
transformFormat
|
|
169
|
+
})),
|
|
170
|
+
targetLocales,
|
|
171
|
+
sourceLocale: options.sourceLocale ? (0, _generaltranslation_format.resolveCanonicalLocale)(options.sourceLocale, customMapping) : void 0,
|
|
172
|
+
modelProvider: options.modelProvider,
|
|
173
|
+
force: options.force
|
|
174
|
+
},
|
|
175
|
+
client: getClient()
|
|
176
|
+
}));
|
|
177
|
+
const jobData = "jobData" in response ? response.jobData : response.data;
|
|
178
|
+
return Object.entries(jobData);
|
|
179
|
+
});
|
|
180
|
+
return {
|
|
181
|
+
jobData: Object.fromEntries(result),
|
|
182
|
+
locales: targetLocales,
|
|
183
|
+
message: `Successfully enqueued ${result.length} file translation jobs in ${Math.ceil(files.length / _generaltranslation_api.DEFAULT_BATCH_SIZE)} batch(es)`
|
|
184
|
+
};
|
|
185
|
+
},
|
|
186
|
+
async uploadSourceFiles(files, options) {
|
|
187
|
+
const sourceLocale = (0, _generaltranslation_format.resolveCanonicalLocale)(options.sourceLocale, customMapping);
|
|
188
|
+
return { uploadedFiles: await (0, _generaltranslation_api.processBatches)(files, async (batch) => {
|
|
189
|
+
return require_unwrapApiResult.unwrapApiResult(await (0, _generaltranslation_api.uploadSourceFiles)({
|
|
190
|
+
body: {
|
|
191
|
+
data: batch.map(({ source }) => ({ source: {
|
|
192
|
+
...source,
|
|
193
|
+
content: require_derive.encodeFileContent(source.content, source.fileFormat),
|
|
194
|
+
locale: (0, _generaltranslation_format.resolveCanonicalLocale)(source.locale, customMapping)
|
|
195
|
+
} })),
|
|
196
|
+
sourceLocale
|
|
197
|
+
},
|
|
198
|
+
client: getClient()
|
|
199
|
+
})).uploadedFiles;
|
|
200
|
+
}) };
|
|
201
|
+
},
|
|
202
|
+
async awaitJobs(jobIds, options) {
|
|
203
|
+
return (0, _generaltranslation_api.pollJobs)(jobIds, async (pendingJobIds, signal) => require_unwrapApiResult.unwrapApiResult(await (0, _generaltranslation_api.getTranslationJobInfo)({
|
|
204
|
+
body: { jobIds: pendingJobIds },
|
|
205
|
+
client: getClient(),
|
|
206
|
+
signal
|
|
207
|
+
})), options);
|
|
208
|
+
},
|
|
209
|
+
async uploadTranslations(files, options) {
|
|
210
|
+
return { uploadedFiles: await (0, _generaltranslation_api.processBatches)(files, async (batch) => {
|
|
211
|
+
return require_unwrapApiResult.unwrapApiResult(await (0, _generaltranslation_api.uploadTranslations)({
|
|
212
|
+
body: {
|
|
213
|
+
data: batch.map(({ source, translations }) => ({
|
|
214
|
+
source: {
|
|
215
|
+
...source,
|
|
216
|
+
content: require_derive.encodeFileContent(source.content, source.fileFormat)
|
|
217
|
+
},
|
|
218
|
+
translations: translations.map((translation) => ({
|
|
219
|
+
...translation,
|
|
220
|
+
locale: (0, _generaltranslation_format.resolveCanonicalLocale)(translation.locale, customMapping),
|
|
221
|
+
content: require_derive.encodeFileContent(translation.content, translation.fileFormat)
|
|
222
|
+
}))
|
|
223
|
+
})),
|
|
224
|
+
sourceLocale: (0, _generaltranslation_format.resolveCanonicalLocale)(options.sourceLocale, customMapping)
|
|
225
|
+
},
|
|
226
|
+
client: getClient()
|
|
227
|
+
})).uploadedFiles;
|
|
228
|
+
}) };
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
64
233
|
//#region src/derive/indexVars.ts
|
|
65
234
|
/**
|
|
66
235
|
* Given an ICU string adds identifiers to each _gt_ placeholder
|
|
@@ -161,14 +330,17 @@ Object.defineProperty(exports, "API_VERSION", {
|
|
|
161
330
|
exports.VAR_IDENTIFIER = require_derive.VAR_IDENTIFIER;
|
|
162
331
|
exports.condenseVars = condenseVars;
|
|
163
332
|
exports.createDiagnosticMessage = require_unwrapApiResult.createDiagnosticMessage;
|
|
333
|
+
exports.createGtApiAdapter = createGtApiAdapter;
|
|
164
334
|
exports.declareVar = require_derive.declareVar;
|
|
165
335
|
exports.decode = require_derive.decode;
|
|
336
|
+
exports.decodeFileContent = require_derive.decodeFileContent;
|
|
166
337
|
exports.decodeVars = require_derive.decodeVars;
|
|
167
338
|
exports.defaultBaseUrl = require_unwrapApiResult.defaultBaseUrl;
|
|
168
339
|
exports.defaultCacheUrl = require_unwrapApiResult.defaultCacheUrl;
|
|
169
340
|
exports.defaultRuntimeApiUrl = require_unwrapApiResult.defaultRuntimeApiUrl;
|
|
170
341
|
exports.derive = require_derive.derive;
|
|
171
342
|
exports.encode = require_derive.encode;
|
|
343
|
+
exports.encodeFileContent = require_derive.encodeFileContent;
|
|
172
344
|
exports.extractVars = extractVars;
|
|
173
345
|
exports.formatDiagnosticErrorDetails = require_unwrapApiResult.formatDiagnosticErrorDetails;
|
|
174
346
|
exports.getPluralForm = _getPluralForm;
|
package/dist/internal.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.cjs","names":["isGTUnindexedSelectElement","VAR_IDENTIFIER","isGTUnindexedSelectElement","VAR_IDENTIFIER","TYPE","traverseIcu","isGTIndexedSelectElement"],"sources":["../src/settings/plurals.ts","../src/locales/getPluralForm.ts","../src/utils/minify.ts","../src/derive/indexVars.ts","../src/derive/extractVars.ts","../src/derive/condenseVars.ts"],"sourcesContent":["export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","import { getCachedPluralRules } from '@generaltranslation/format/internal';\n\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {PluralType[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport function _getPluralForm(\n n: number,\n forms: readonly PluralType[] = pluralForms,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = getCachedPluralRules(locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n if (forms.includes('plural')) return 'plural';\n if (forms.includes('other')) return 'other';\n return '';\n}\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n 'relative-time': 'rt',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport type { IcuMessage } from '@generaltranslation/format/types';\n\ntype Location = {\n start: number;\n end: number;\n otherStart: number;\n otherEnd: number;\n};\n\n/**\n * Given an ICU string adds identifiers to each _gt_ placeholder\n * indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'\n */\nexport function indexVars(icuString: IcuMessage): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n otherStart: child.options.other.location?.start.offset ?? 0,\n otherEnd: child.options.other.location?.end.offset ?? 0,\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false, captureLocation: true },\n });\n\n // Index each variable and collapse the other option.\n const result = [];\n let current = 0;\n for (let i = 0; i < variableLocations.length; i++) {\n const { start, end, otherStart, otherEnd } = variableLocations[i];\n // Before the variable\n result.push(icuString.slice(current, start));\n // Replace the variable with the new identifier (+1 is for the curly brace)\n result.push(icuString.slice(start, start + VAR_IDENTIFIER.length + 1));\n\n // Add the new identifier.\n result.push(String(i + 1));\n // After the variable\n result.push(icuString.slice(start + VAR_IDENTIFIER.length + 1, otherStart));\n // Before the other option\n result.push('{}');\n // The other option\n result.push(icuString.slice(otherEnd, end));\n current = end;\n }\n result.push(icuString.slice(current, icuString.length));\n\n return result.join('');\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\n/**\n * Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values\n *\n * extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }\n *\n * @param {string} icuString - The ICU string to extract variables from.\n * @returns {Record<string, string>} A mapping of the variable to the value.\n */\nexport function extractVars(icuString: string): Record<string, string> {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return {};\n }\n\n // Extract all the _gt_# variables\n let index = 1;\n const variables: Record<string, string> = {};\n function visitor(child: GTUnindexedSelectElement): void {\n variables[child.value + index] = child.options.other.value.length\n ? child.options.other.value[0]?.value\n : '';\n index += 1;\n }\n\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n return variables;\n}\n","import { printAST, TYPE, type ArgumentElement } from '@generaltranslation/icu';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTIndexedSelectElement } from './utils/types';\nimport { isGTIndexedSelectElement } from './utils/traverseHelpers';\ninterface GTIndexedArgumentElement extends ArgumentElement {\n value: `${typeof VAR_IDENTIFIER}${number}`;\n}\n\nconst CONTAINS_INDEXED_GT_REGEX = new RegExp(`${VAR_IDENTIFIER}\\\\d+`);\n\n/**\n * Given an indexed ICU string, condenses any select to an argument\n * Unindexed _gt_ source strings and indexed _gt_# translation strings\n * are mutually exclusive.\n * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'\n * @param {string} icuString - The ICU string to condense.\n * @returns {string} The condensed ICU string.\n */\nexport function condenseVars(icuString: string): string {\n // Check if the string contains an indexed _gt_ identifier.\n if (!CONTAINS_INDEXED_GT_REGEX.test(icuString)) {\n return icuString;\n }\n\n // Replace with argument\n function visitor(child: GTIndexedSelectElement): void {\n (child as unknown as GTIndexedArgumentElement).type = TYPE.argument;\n Reflect.deleteProperty(child, 'options');\n }\n\n const ast = traverseIcu({\n icuString,\n shouldVisit: isGTIndexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n // Serialize\n return printAST(ast);\n}\n"],"mappings":";;;;;;;;AAAA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAgB,qBAAqB,MAAkC;AACrE,QAAO,YAAY,SAAS,KAAqC;;;;;;;;;;;ACDnE,SAAgB,eACd,GACA,QAA+B,aAC/B,UAAoB,CAAA,KAAsB,EACzB;CAEjB,MAAM,yBAAA,GAAA,oCAAA,sBADmC,QACA,CAAC,OAAO,EAAE;CAEnD,MAAM,OAAO,KAAK,IAAI,EAAE;AAExB,KAAI,SAAS,KAAK,MAAM,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Result","decodeFileContent","DEFAULT_BATCH_SIZE","encodeFileContent","isGTUnindexedSelectElement","VAR_IDENTIFIER","isGTUnindexedSelectElement","VAR_IDENTIFIER","TYPE","traverseIcu","isGTIndexedSelectElement"],"sources":["../src/settings/plurals.ts","../src/locales/getPluralForm.ts","../src/utils/minify.ts","../src/adapter/createGtApi.ts","../src/derive/indexVars.ts","../src/derive/extractVars.ts","../src/derive/condenseVars.ts"],"sourcesContent":["export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","import { getCachedPluralRules } from '@generaltranslation/format/internal';\n\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {PluralType[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport function _getPluralForm(\n n: number,\n forms: readonly PluralType[] = pluralForms,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = getCachedPluralRules(locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n if (forms.includes('plural')) return 'plural';\n if (forms.includes('other')) return 'other';\n return '';\n}\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n 'relative-time': 'rt',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n","import {\n createApiClient,\n createBranch,\n DEFAULT_BATCH_SIZE,\n downloadFiles,\n enqueueFileTranslations,\n generateProjectContext,\n getFileInfo,\n getTranslationJobInfo,\n pollJobs,\n processBatches,\n uploadSourceFiles,\n uploadTranslations,\n type ApiClientConfig,\n type AwaitJobsOptions,\n type CreateBranchData,\n type DownloadFilesData,\n type EnqueueFileTranslationsData,\n type GenerateProjectContextData,\n type GetFileInfoData,\n type UploadSourceFilesData,\n type UploadTranslationsData,\n} from '@generaltranslation/api';\nimport {\n resolveAliasLocale,\n resolveCanonicalLocale,\n} from '@generaltranslation/format';\nimport type { CustomMapping } from '@generaltranslation/format/types';\nimport type { DownloadedFile } from '../types-dir/api/downloadFileBatch';\nimport { decodeFileContent, encodeFileContent } from '../utils/base64';\nimport { unwrapApiResult } from '../translate/utils/unwrapApiResult';\n\nexport type GtApiAdapterConfig = ApiClientConfig & {\n customMapping?: CustomMapping;\n};\n\nexport function createGtApiAdapter(defaultConfig?: ApiClientConfig) {\n let client = defaultConfig ? createApiClient(defaultConfig) : undefined;\n let configuredClientConfig = defaultConfig;\n let customMapping: CustomMapping | undefined;\n\n function getClient(): ReturnType<typeof createApiClient> {\n if (!client) {\n throw new Error(\n 'API client not configured — call configureApiClient first'\n );\n }\n return client;\n }\n\n function getClientConfig(): ApiClientConfig {\n if (!configuredClientConfig) {\n throw new Error(\n 'API client not configured — call configureApiClient first'\n );\n }\n return configuredClientConfig;\n }\n\n function configure(config: GtApiAdapterConfig): void {\n const { customMapping: mapping, ...clientConfig } = config;\n client = createApiClient(clientConfig);\n configuredClientConfig = clientConfig;\n customMapping = mapping;\n }\n\n return {\n configure,\n getClient,\n getClientConfig,\n\n resolveAliasLocale(locale: string) {\n return resolveAliasLocale(locale, customMapping);\n },\n\n resolveCanonicalLocale(locale: string) {\n return resolveCanonicalLocale(locale, customMapping);\n },\n\n async createBranch(body: CreateBranchData['body']) {\n return unwrapApiResult(await createBranch({ body, client: getClient() }));\n },\n\n async queryFileData(body: GetFileInfoData['body']) {\n const result = unwrapApiResult(\n await getFileInfo({\n body: {\n ...body,\n translatedFiles: body.translatedFiles?.map((file) => ({\n ...file,\n locale: resolveCanonicalLocale(file.locale, customMapping),\n })),\n },\n client: getClient(),\n })\n );\n return {\n ...result,\n translatedFiles: result.translatedFiles.map((file) => ({\n ...file,\n locale: resolveAliasLocale(file.locale, customMapping),\n })),\n sourceFiles: result.sourceFiles.map((file) => ({\n ...file,\n sourceLocale: resolveAliasLocale(file.sourceLocale, customMapping),\n locales: file.locales.map((locale) =>\n resolveAliasLocale(locale, customMapping)\n ),\n })),\n };\n },\n\n async downloadFileBatch(files: DownloadFilesData['body']) {\n const request = async (batch: DownloadFilesData['body']) =>\n unwrapApiResult(\n await downloadFiles({\n body: batch.map((file) => ({\n ...file,\n locale: file.locale\n ? resolveCanonicalLocale(file.locale, customMapping)\n : undefined,\n })),\n client: getClient(),\n })\n );\n const responses = await processBatches(files, async (batch) => [\n await request(batch),\n ]);\n return {\n files: responses.flatMap((response) =>\n response.files.map(\n (file): DownloadedFile => ({\n ...file,\n ...(file.locale && {\n locale: resolveAliasLocale(file.locale, customMapping),\n }),\n data: decodeFileContent(file.data, file.fileFormat),\n // OpenAPI currently types metadata as an open object; the API emits\n // JSON values here, matching DownloadedFile's public contract.\n metadata: file.metadata as DownloadedFile['metadata'],\n })\n )\n ),\n count: responses.reduce((count, response) => count + response.count, 0),\n pending: responses.flatMap((response) => response.pending ?? []),\n };\n },\n\n async setupProject(\n files: GenerateProjectContextData['body']['files'],\n options: Omit<GenerateProjectContextData['body'], 'files'> = {}\n ) {\n return unwrapApiResult(\n await generateProjectContext({\n body: {\n files: files.map(({ branchId, fileId, versionId }) => ({\n branchId,\n fileId,\n versionId,\n })),\n locales: options.locales?.map((locale) =>\n resolveCanonicalLocale(locale, customMapping)\n ),\n force: options.force,\n },\n client: getClient(),\n })\n );\n },\n\n async enqueueFiles(\n files: EnqueueFileTranslationsData['body']['files'],\n options: {\n sourceLocale?: string;\n targetLocales: string[];\n modelProvider?: string;\n force?: boolean;\n }\n ) {\n const targetLocales = options.targetLocales.map((locale) =>\n resolveCanonicalLocale(locale, customMapping)\n );\n const result = await processBatches(files, async (batch) => {\n const response = unwrapApiResult(\n await enqueueFileTranslations({\n body: {\n files: batch.map(\n ({\n branchId,\n fileId,\n versionId,\n fileName,\n transformFormat,\n }) => ({\n branchId,\n fileId,\n versionId,\n fileName,\n transformFormat,\n })\n ),\n targetLocales,\n sourceLocale: options.sourceLocale\n ? resolveCanonicalLocale(options.sourceLocale, customMapping)\n : undefined,\n // Consumers intentionally accept custom model-provider strings beyond\n // the OpenAPI enum; preserve the existing wire behavior at this boundary.\n modelProvider:\n options.modelProvider as EnqueueFileTranslationsData['body']['modelProvider'],\n force: options.force,\n },\n client: getClient(),\n })\n );\n const jobData =\n 'jobData' in response ? response.jobData : response.data;\n return Object.entries(jobData);\n });\n\n return {\n jobData: Object.fromEntries(result),\n locales: targetLocales,\n message: `Successfully enqueued ${result.length} file translation jobs in ${Math.ceil(files.length / DEFAULT_BATCH_SIZE)} batch(es)`,\n };\n },\n\n async uploadSourceFiles(\n files: Array<{\n source: UploadSourceFilesData['body']['data'][number]['source'];\n }>,\n options: { sourceLocale: string }\n ) {\n const sourceLocale = resolveCanonicalLocale(\n options.sourceLocale,\n customMapping\n );\n const result = await processBatches(files, async (batch) => {\n const response = unwrapApiResult(\n await uploadSourceFiles({\n body: {\n data: batch.map(({ source }) => ({\n source: {\n ...source,\n content: encodeFileContent(source.content, source.fileFormat),\n locale: resolveCanonicalLocale(source.locale, customMapping),\n },\n })),\n sourceLocale,\n },\n client: getClient(),\n })\n );\n return response.uploadedFiles;\n });\n\n return { uploadedFiles: result };\n },\n\n async awaitJobs(jobIds: readonly string[], options?: AwaitJobsOptions) {\n return pollJobs(\n jobIds,\n async (pendingJobIds, signal) =>\n unwrapApiResult(\n await getTranslationJobInfo({\n body: { jobIds: pendingJobIds },\n client: getClient(),\n signal,\n })\n ),\n options\n );\n },\n\n async uploadTranslations(\n files: UploadTranslationsData['body']['data'],\n options: { sourceLocale: string }\n ) {\n const result = await processBatches(files, async (batch) => {\n const response = unwrapApiResult(\n await uploadTranslations({\n body: {\n data: batch.map(({ source, translations }) => ({\n source: {\n ...source,\n content: encodeFileContent(source.content, source.fileFormat),\n },\n translations: translations.map((translation) => ({\n ...translation,\n locale: resolveCanonicalLocale(\n translation.locale,\n customMapping\n ),\n content: encodeFileContent(\n translation.content,\n translation.fileFormat\n ),\n })),\n })),\n sourceLocale: resolveCanonicalLocale(\n options.sourceLocale,\n customMapping\n ),\n },\n client: getClient(),\n })\n );\n return response.uploadedFiles;\n });\n\n return { uploadedFiles: result };\n },\n };\n}\n\nexport type GtApiAdapter = ReturnType<typeof createGtApiAdapter>;\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport type { IcuMessage } from '@generaltranslation/format/types';\n\ntype Location = {\n start: number;\n end: number;\n otherStart: number;\n otherEnd: number;\n};\n\n/**\n * Given an ICU string adds identifiers to each _gt_ placeholder\n * indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'\n */\nexport function indexVars(icuString: IcuMessage): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n otherStart: child.options.other.location?.start.offset ?? 0,\n otherEnd: child.options.other.location?.end.offset ?? 0,\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false, captureLocation: true },\n });\n\n // Index each variable and collapse the other option.\n const result = [];\n let current = 0;\n for (let i = 0; i < variableLocations.length; i++) {\n const { start, end, otherStart, otherEnd } = variableLocations[i];\n // Before the variable\n result.push(icuString.slice(current, start));\n // Replace the variable with the new identifier (+1 is for the curly brace)\n result.push(icuString.slice(start, start + VAR_IDENTIFIER.length + 1));\n\n // Add the new identifier.\n result.push(String(i + 1));\n // After the variable\n result.push(icuString.slice(start + VAR_IDENTIFIER.length + 1, otherStart));\n // Before the other option\n result.push('{}');\n // The other option\n result.push(icuString.slice(otherEnd, end));\n current = end;\n }\n result.push(icuString.slice(current, icuString.length));\n\n return result.join('');\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\n/**\n * Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values\n *\n * extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }\n *\n * @param {string} icuString - The ICU string to extract variables from.\n * @returns {Record<string, string>} A mapping of the variable to the value.\n */\nexport function extractVars(icuString: string): Record<string, string> {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return {};\n }\n\n // Extract all the _gt_# variables\n let index = 1;\n const variables: Record<string, string> = {};\n function visitor(child: GTUnindexedSelectElement): void {\n variables[child.value + index] = child.options.other.value.length\n ? child.options.other.value[0]?.value\n : '';\n index += 1;\n }\n\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n return variables;\n}\n","import { printAST, TYPE, type ArgumentElement } from '@generaltranslation/icu';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTIndexedSelectElement } from './utils/types';\nimport { isGTIndexedSelectElement } from './utils/traverseHelpers';\ninterface GTIndexedArgumentElement extends ArgumentElement {\n value: `${typeof VAR_IDENTIFIER}${number}`;\n}\n\nconst CONTAINS_INDEXED_GT_REGEX = new RegExp(`${VAR_IDENTIFIER}\\\\d+`);\n\n/**\n * Given an indexed ICU string, condenses any select to an argument\n * Unindexed _gt_ source strings and indexed _gt_# translation strings\n * are mutually exclusive.\n * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'\n * @param {string} icuString - The ICU string to condense.\n * @returns {string} The condensed ICU string.\n */\nexport function condenseVars(icuString: string): string {\n // Check if the string contains an indexed _gt_ identifier.\n if (!CONTAINS_INDEXED_GT_REGEX.test(icuString)) {\n return icuString;\n }\n\n // Replace with argument\n function visitor(child: GTIndexedSelectElement): void {\n (child as unknown as GTIndexedArgumentElement).type = TYPE.argument;\n Reflect.deleteProperty(child, 'options');\n }\n\n const ast = traverseIcu({\n icuString,\n shouldVisit: isGTIndexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n // Serialize\n return printAST(ast);\n}\n"],"mappings":";;;;;;;;;AAAA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAgB,qBAAqB,MAAkC;AACrE,QAAO,YAAY,SAAS,KAAqC;;;;;;;;;;;ACDnE,SAAgB,eACd,GACA,QAA+B,aAC/B,UAAoB,CAAA,KAAsB,EACzB;CAEjB,MAAM,yBAAA,GAAA,oCAAA,sBADmC,QACA,CAAC,OAAO,EAAE;CAEnD,MAAM,OAAO,KAAK,IAAI,EAAE;AAExB,KAAI,SAAS,KAAK,MAAM,SAAS,OAAO,CAAE,QAAO;AAEjD,KAAI,SAAS,GAAG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OAAuC;AACtD,YAAU,MAAM,QAAQ,SAAS,MAAM,QAAQ,MAAM,MAAM,SACvD,MAAM,QAAQ,MAAM,MAAM,IAAI,QAC9B;AACJ,WAAS;;AAGX,gBAAA,YAAY;EACV;EACA,aAAaC,eAAAA;EACb;EACA,SAAS,EAAE,oBAAoB,OAAO;EACvC,CAAC;AAEF,QAAO;;;;AC1BT,MAAM,4BAA4B,IAAI,OAAO,GAAGC,eAAAA,eAAe,MAAM;;;;;;;;;AAUrE,SAAgB,aAAa,WAA2B;AAEtD,KAAI,CAAC,0BAA0B,KAAK,UAAU,CAC5C,QAAO;CAIT,SAAS,QAAQ,OAAqC;AACnD,QAA8C,OAAOC,wBAAAA,KAAK;AAC3D,UAAQ,eAAe,OAAO,UAAU;;AAW1C,SAAA,GAAA,wBAAA,UARYC,eAAAA,YAAY;EACtB;EACA,aAAaC,eAAAA;EACb;EACA,SAAS,EAAE,oBAAoB,OAAO;EACvC,CAGkB,CAAC"}
|
package/dist/internal.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as Variable, Nt as RuntimeTranslateManyOptions, O as VariableTransformationSuffix, dt as DownloadedFile, g as LocaleProperties, h as JsxElement, m as JsxChildren, p as JsxChild, pt as FileFormat, w as VariableType } from "./types-bCr8pV1Z.cjs";
|
|
2
2
|
import { n as declareVar, r as decodeVars, t as derive } from "./derive-DBCCXTmL.cjs";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import * as _$_generaltranslation_api0 from "@generaltranslation/api";
|
|
4
|
+
import { API_VERSION, ApiClientConfig, AwaitJobsOptions, CreateBranchData, DownloadFilesData, EnqueueFileTranslationsData, GenerateProjectContextData, GetFileInfoData, UploadSourceFilesData, UploadTranslationsData, createApiClient } from "@generaltranslation/api";
|
|
5
|
+
import { CustomMapping, IcuMessage } from "@generaltranslation/format/types";
|
|
5
6
|
|
|
6
7
|
//#region src/settings/settingsUrls.d.ts
|
|
7
8
|
declare const defaultCacheUrl: "https://cdn.gtx.dev";
|
|
@@ -67,6 +68,8 @@ declare function minifyVariableType(variableType: VariableTransformationSuffix):
|
|
|
67
68
|
//#region src/utils/base64.d.ts
|
|
68
69
|
declare function encode(data: string): string;
|
|
69
70
|
declare function decode(base64: string): string;
|
|
71
|
+
declare function encodeFileContent(content: string, fileFormat: FileFormat): string;
|
|
72
|
+
declare function decodeFileContent(content: string, fileFormat: FileFormat): string;
|
|
70
73
|
//#endregion
|
|
71
74
|
//#region src/utils/isSupportedFileFormatTransform.d.ts
|
|
72
75
|
/**
|
|
@@ -91,6 +94,107 @@ declare function unwrapApiResult<T>(result: {
|
|
|
91
94
|
response?: Response;
|
|
92
95
|
}): Exclude<T, undefined>;
|
|
93
96
|
//#endregion
|
|
97
|
+
//#region src/adapter/createGtApi.d.ts
|
|
98
|
+
type GtApiAdapterConfig = ApiClientConfig & {
|
|
99
|
+
customMapping?: CustomMapping;
|
|
100
|
+
};
|
|
101
|
+
declare function createGtApiAdapter(defaultConfig?: ApiClientConfig): {
|
|
102
|
+
configure: (config: GtApiAdapterConfig) => void;
|
|
103
|
+
getClient: () => ReturnType<typeof createApiClient>;
|
|
104
|
+
getClientConfig: () => ApiClientConfig;
|
|
105
|
+
resolveAliasLocale(locale: string): string;
|
|
106
|
+
resolveCanonicalLocale(locale: string): string;
|
|
107
|
+
createBranch(body: CreateBranchData["body"]): Promise<{
|
|
108
|
+
branch: _$_generaltranslation_api0.Branch;
|
|
109
|
+
}>;
|
|
110
|
+
queryFileData(body: GetFileInfoData["body"]): Promise<{
|
|
111
|
+
translatedFiles: {
|
|
112
|
+
locale: string;
|
|
113
|
+
branchId: string;
|
|
114
|
+
fileId: string;
|
|
115
|
+
versionId: string;
|
|
116
|
+
fileFormat: _$_generaltranslation_api0.FileFormat;
|
|
117
|
+
dataFormat: string | null;
|
|
118
|
+
createdAt: string;
|
|
119
|
+
updatedAt: string;
|
|
120
|
+
approvedAt: string | null;
|
|
121
|
+
publishedAt: string | null;
|
|
122
|
+
completedAt: string | null;
|
|
123
|
+
}[];
|
|
124
|
+
sourceFiles: {
|
|
125
|
+
sourceLocale: string;
|
|
126
|
+
locales: string[];
|
|
127
|
+
branchId: string;
|
|
128
|
+
fileId: string;
|
|
129
|
+
versionId: string;
|
|
130
|
+
fileName: string;
|
|
131
|
+
fileFormat: _$_generaltranslation_api0.FileFormat;
|
|
132
|
+
dataFormat: string | null;
|
|
133
|
+
createdAt: string;
|
|
134
|
+
updatedAt: string;
|
|
135
|
+
publishedAt: string | null;
|
|
136
|
+
}[];
|
|
137
|
+
}>;
|
|
138
|
+
downloadFileBatch(files: DownloadFilesData["body"]): Promise<{
|
|
139
|
+
files: DownloadedFile[];
|
|
140
|
+
count: number;
|
|
141
|
+
pending: {
|
|
142
|
+
branchId: string;
|
|
143
|
+
fileId: string;
|
|
144
|
+
locale: string;
|
|
145
|
+
versionId: string;
|
|
146
|
+
}[];
|
|
147
|
+
}>;
|
|
148
|
+
setupProject(files: GenerateProjectContextData["body"]["files"], options?: Omit<GenerateProjectContextData["body"], "files">): Promise<{
|
|
149
|
+
status: "completed";
|
|
150
|
+
} | {
|
|
151
|
+
setupJobId: string;
|
|
152
|
+
status: "queued";
|
|
153
|
+
}>;
|
|
154
|
+
enqueueFiles(files: EnqueueFileTranslationsData["body"]["files"], options: {
|
|
155
|
+
sourceLocale?: string;
|
|
156
|
+
targetLocales: string[];
|
|
157
|
+
modelProvider?: string;
|
|
158
|
+
force?: boolean;
|
|
159
|
+
}): Promise<{
|
|
160
|
+
jobData: {
|
|
161
|
+
[k: string]: any;
|
|
162
|
+
};
|
|
163
|
+
locales: string[];
|
|
164
|
+
message: string;
|
|
165
|
+
}>;
|
|
166
|
+
uploadSourceFiles(files: Array<{
|
|
167
|
+
source: UploadSourceFilesData["body"]["data"][number]["source"];
|
|
168
|
+
}>, options: {
|
|
169
|
+
sourceLocale: string;
|
|
170
|
+
}): Promise<{
|
|
171
|
+
uploadedFiles: {
|
|
172
|
+
branchId?: string;
|
|
173
|
+
fileId: string;
|
|
174
|
+
versionId: string;
|
|
175
|
+
fileName: string;
|
|
176
|
+
fileFormat: _$_generaltranslation_api0.FileFormat;
|
|
177
|
+
dataFormat?: string;
|
|
178
|
+
locale?: string;
|
|
179
|
+
}[];
|
|
180
|
+
}>;
|
|
181
|
+
awaitJobs(jobIds: readonly string[], options?: AwaitJobsOptions): Promise<_$_generaltranslation_api0.AwaitJobsResult>;
|
|
182
|
+
uploadTranslations(files: UploadTranslationsData["body"]["data"], options: {
|
|
183
|
+
sourceLocale: string;
|
|
184
|
+
}): Promise<{
|
|
185
|
+
uploadedFiles: {
|
|
186
|
+
branchId?: string;
|
|
187
|
+
fileId: string;
|
|
188
|
+
versionId: string;
|
|
189
|
+
fileName: string;
|
|
190
|
+
fileFormat: _$_generaltranslation_api0.FileFormat;
|
|
191
|
+
dataFormat?: string;
|
|
192
|
+
locale?: string;
|
|
193
|
+
}[];
|
|
194
|
+
}>;
|
|
195
|
+
};
|
|
196
|
+
type GtApiAdapter = ReturnType<typeof createGtApiAdapter>;
|
|
197
|
+
//#endregion
|
|
94
198
|
//#region src/derive/indexVars.d.ts
|
|
95
199
|
/**
|
|
96
200
|
* Given an ICU string adds identifiers to each _gt_ placeholder
|
|
@@ -123,5 +227,5 @@ declare function condenseVars(icuString: string): string;
|
|
|
123
227
|
//#region src/derive/utils/constants.d.ts
|
|
124
228
|
declare const VAR_IDENTIFIER = "_gt_";
|
|
125
229
|
//#endregion
|
|
126
|
-
export { API_VERSION, type DiagnosticMessageInput, type DiagnosticSeverity, type JsxChild, type JsxChildren, type JsxElement, type LocaleProperties, type RuntimeTranslateManyOptions, VAR_IDENTIFIER, condenseVars, createDiagnosticMessage, declareVar, decode, decodeVars, defaultBaseUrl, defaultCacheUrl, defaultRuntimeApiUrl, derive, encode, extractVars, formatDiagnosticErrorDetails, _getPluralForm as getPluralForm, indexVars, isAcceptedPluralForm, isErrorResult, isSupportedFileFormatTransform, isVariable, libraryDefaultLocale, minifyVariableType, pluralForms, unwrapApiResult };
|
|
230
|
+
export { API_VERSION, type DiagnosticMessageInput, type DiagnosticSeverity, type GtApiAdapter, type GtApiAdapterConfig, type JsxChild, type JsxChildren, type JsxElement, type LocaleProperties, type RuntimeTranslateManyOptions, VAR_IDENTIFIER, condenseVars, createDiagnosticMessage, createGtApiAdapter, declareVar, decode, decodeFileContent, decodeVars, defaultBaseUrl, defaultCacheUrl, defaultRuntimeApiUrl, derive, encode, encodeFileContent, extractVars, formatDiagnosticErrorDetails, _getPluralForm as getPluralForm, indexVars, isAcceptedPluralForm, isErrorResult, isSupportedFileFormatTransform, isVariable, libraryDefaultLocale, minifyVariableType, pluralForms, unwrapApiResult };
|
|
127
231
|
//# sourceMappingURL=internal.d.cts.map
|
package/dist/internal.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as Variable, Nt as RuntimeTranslateManyOptions, O as VariableTransformationSuffix, dt as DownloadedFile, g as LocaleProperties, h as JsxElement, m as JsxChildren, p as JsxChild, pt as FileFormat, w as VariableType } from "./types-Dp1drjxq.mjs";
|
|
2
2
|
import { n as declareVar, r as decodeVars, t as derive } from "./derive-texIAHzc.mjs";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import * as _$_generaltranslation_api0 from "@generaltranslation/api";
|
|
4
|
+
import { API_VERSION, ApiClientConfig, AwaitJobsOptions, CreateBranchData, DownloadFilesData, EnqueueFileTranslationsData, GenerateProjectContextData, GetFileInfoData, UploadSourceFilesData, UploadTranslationsData, createApiClient } from "@generaltranslation/api";
|
|
5
|
+
import { CustomMapping, IcuMessage } from "@generaltranslation/format/types";
|
|
5
6
|
|
|
6
7
|
//#region src/settings/settingsUrls.d.ts
|
|
7
8
|
declare const defaultCacheUrl: "https://cdn.gtx.dev";
|
|
@@ -67,6 +68,8 @@ declare function minifyVariableType(variableType: VariableTransformationSuffix):
|
|
|
67
68
|
//#region src/utils/base64.d.ts
|
|
68
69
|
declare function encode(data: string): string;
|
|
69
70
|
declare function decode(base64: string): string;
|
|
71
|
+
declare function encodeFileContent(content: string, fileFormat: FileFormat): string;
|
|
72
|
+
declare function decodeFileContent(content: string, fileFormat: FileFormat): string;
|
|
70
73
|
//#endregion
|
|
71
74
|
//#region src/utils/isSupportedFileFormatTransform.d.ts
|
|
72
75
|
/**
|
|
@@ -91,6 +94,107 @@ declare function unwrapApiResult<T>(result: {
|
|
|
91
94
|
response?: Response;
|
|
92
95
|
}): Exclude<T, undefined>;
|
|
93
96
|
//#endregion
|
|
97
|
+
//#region src/adapter/createGtApi.d.ts
|
|
98
|
+
type GtApiAdapterConfig = ApiClientConfig & {
|
|
99
|
+
customMapping?: CustomMapping;
|
|
100
|
+
};
|
|
101
|
+
declare function createGtApiAdapter(defaultConfig?: ApiClientConfig): {
|
|
102
|
+
configure: (config: GtApiAdapterConfig) => void;
|
|
103
|
+
getClient: () => ReturnType<typeof createApiClient>;
|
|
104
|
+
getClientConfig: () => ApiClientConfig;
|
|
105
|
+
resolveAliasLocale(locale: string): string;
|
|
106
|
+
resolveCanonicalLocale(locale: string): string;
|
|
107
|
+
createBranch(body: CreateBranchData["body"]): Promise<{
|
|
108
|
+
branch: _$_generaltranslation_api0.Branch;
|
|
109
|
+
}>;
|
|
110
|
+
queryFileData(body: GetFileInfoData["body"]): Promise<{
|
|
111
|
+
translatedFiles: {
|
|
112
|
+
locale: string;
|
|
113
|
+
branchId: string;
|
|
114
|
+
fileId: string;
|
|
115
|
+
versionId: string;
|
|
116
|
+
fileFormat: _$_generaltranslation_api0.FileFormat;
|
|
117
|
+
dataFormat: string | null;
|
|
118
|
+
createdAt: string;
|
|
119
|
+
updatedAt: string;
|
|
120
|
+
approvedAt: string | null;
|
|
121
|
+
publishedAt: string | null;
|
|
122
|
+
completedAt: string | null;
|
|
123
|
+
}[];
|
|
124
|
+
sourceFiles: {
|
|
125
|
+
sourceLocale: string;
|
|
126
|
+
locales: string[];
|
|
127
|
+
branchId: string;
|
|
128
|
+
fileId: string;
|
|
129
|
+
versionId: string;
|
|
130
|
+
fileName: string;
|
|
131
|
+
fileFormat: _$_generaltranslation_api0.FileFormat;
|
|
132
|
+
dataFormat: string | null;
|
|
133
|
+
createdAt: string;
|
|
134
|
+
updatedAt: string;
|
|
135
|
+
publishedAt: string | null;
|
|
136
|
+
}[];
|
|
137
|
+
}>;
|
|
138
|
+
downloadFileBatch(files: DownloadFilesData["body"]): Promise<{
|
|
139
|
+
files: DownloadedFile[];
|
|
140
|
+
count: number;
|
|
141
|
+
pending: {
|
|
142
|
+
branchId: string;
|
|
143
|
+
fileId: string;
|
|
144
|
+
locale: string;
|
|
145
|
+
versionId: string;
|
|
146
|
+
}[];
|
|
147
|
+
}>;
|
|
148
|
+
setupProject(files: GenerateProjectContextData["body"]["files"], options?: Omit<GenerateProjectContextData["body"], "files">): Promise<{
|
|
149
|
+
status: "completed";
|
|
150
|
+
} | {
|
|
151
|
+
setupJobId: string;
|
|
152
|
+
status: "queued";
|
|
153
|
+
}>;
|
|
154
|
+
enqueueFiles(files: EnqueueFileTranslationsData["body"]["files"], options: {
|
|
155
|
+
sourceLocale?: string;
|
|
156
|
+
targetLocales: string[];
|
|
157
|
+
modelProvider?: string;
|
|
158
|
+
force?: boolean;
|
|
159
|
+
}): Promise<{
|
|
160
|
+
jobData: {
|
|
161
|
+
[k: string]: any;
|
|
162
|
+
};
|
|
163
|
+
locales: string[];
|
|
164
|
+
message: string;
|
|
165
|
+
}>;
|
|
166
|
+
uploadSourceFiles(files: Array<{
|
|
167
|
+
source: UploadSourceFilesData["body"]["data"][number]["source"];
|
|
168
|
+
}>, options: {
|
|
169
|
+
sourceLocale: string;
|
|
170
|
+
}): Promise<{
|
|
171
|
+
uploadedFiles: {
|
|
172
|
+
branchId?: string;
|
|
173
|
+
fileId: string;
|
|
174
|
+
versionId: string;
|
|
175
|
+
fileName: string;
|
|
176
|
+
fileFormat: _$_generaltranslation_api0.FileFormat;
|
|
177
|
+
dataFormat?: string;
|
|
178
|
+
locale?: string;
|
|
179
|
+
}[];
|
|
180
|
+
}>;
|
|
181
|
+
awaitJobs(jobIds: readonly string[], options?: AwaitJobsOptions): Promise<_$_generaltranslation_api0.AwaitJobsResult>;
|
|
182
|
+
uploadTranslations(files: UploadTranslationsData["body"]["data"], options: {
|
|
183
|
+
sourceLocale: string;
|
|
184
|
+
}): Promise<{
|
|
185
|
+
uploadedFiles: {
|
|
186
|
+
branchId?: string;
|
|
187
|
+
fileId: string;
|
|
188
|
+
versionId: string;
|
|
189
|
+
fileName: string;
|
|
190
|
+
fileFormat: _$_generaltranslation_api0.FileFormat;
|
|
191
|
+
dataFormat?: string;
|
|
192
|
+
locale?: string;
|
|
193
|
+
}[];
|
|
194
|
+
}>;
|
|
195
|
+
};
|
|
196
|
+
type GtApiAdapter = ReturnType<typeof createGtApiAdapter>;
|
|
197
|
+
//#endregion
|
|
94
198
|
//#region src/derive/indexVars.d.ts
|
|
95
199
|
/**
|
|
96
200
|
* Given an ICU string adds identifiers to each _gt_ placeholder
|
|
@@ -123,5 +227,5 @@ declare function condenseVars(icuString: string): string;
|
|
|
123
227
|
//#region src/derive/utils/constants.d.ts
|
|
124
228
|
declare const VAR_IDENTIFIER = "_gt_";
|
|
125
229
|
//#endregion
|
|
126
|
-
export { API_VERSION, type DiagnosticMessageInput, type DiagnosticSeverity, type JsxChild, type JsxChildren, type JsxElement, type LocaleProperties, type RuntimeTranslateManyOptions, VAR_IDENTIFIER, condenseVars, createDiagnosticMessage, declareVar, decode, decodeVars, defaultBaseUrl, defaultCacheUrl, defaultRuntimeApiUrl, derive, encode, extractVars, formatDiagnosticErrorDetails, _getPluralForm as getPluralForm, indexVars, isAcceptedPluralForm, isErrorResult, isSupportedFileFormatTransform, isVariable, libraryDefaultLocale, minifyVariableType, pluralForms, unwrapApiResult };
|
|
230
|
+
export { API_VERSION, type DiagnosticMessageInput, type DiagnosticSeverity, type GtApiAdapter, type GtApiAdapterConfig, type JsxChild, type JsxChildren, type JsxElement, type LocaleProperties, type RuntimeTranslateManyOptions, VAR_IDENTIFIER, condenseVars, createDiagnosticMessage, createGtApiAdapter, declareVar, decode, decodeFileContent, decodeVars, defaultBaseUrl, defaultCacheUrl, defaultRuntimeApiUrl, derive, encode, encodeFileContent, extractVars, formatDiagnosticErrorDetails, _getPluralForm as getPluralForm, indexVars, isAcceptedPluralForm, isErrorResult, isSupportedFileFormatTransform, isVariable, libraryDefaultLocale, minifyVariableType, pluralForms, unwrapApiResult };
|
|
127
231
|
//# sourceMappingURL=internal.d.mts.map
|
package/dist/internal.d.ts
CHANGED
|
@@ -8,10 +8,12 @@ export { _getPluralForm as getPluralForm } from './locales/getPluralForm';
|
|
|
8
8
|
export type { JsxChildren, JsxChild, JsxElement, LocaleProperties, } from './types';
|
|
9
9
|
export { isVariable } from './utils/isVariable';
|
|
10
10
|
export { minifyVariableType } from './utils/minify';
|
|
11
|
-
export { encode,
|
|
11
|
+
export { decode, decodeFileContent, encode, encodeFileContent, } from './utils/base64';
|
|
12
12
|
export { isSupportedFileFormatTransform } from './utils/isSupportedFileFormatTransform';
|
|
13
13
|
export { API_VERSION } from './translate/api';
|
|
14
14
|
export { isErrorResult, unwrapApiResult, } from './translate/utils/unwrapApiResult';
|
|
15
|
+
export { createGtApiAdapter } from './adapter/createGtApi';
|
|
16
|
+
export type { GtApiAdapter, GtApiAdapterConfig } from './adapter/createGtApi';
|
|
15
17
|
export { decodeVars } from './derive/decodeVars';
|
|
16
18
|
export { declareVar } from './derive/declareVar';
|
|
17
19
|
export { derive } from './derive/derive';
|
package/dist/internal.js
CHANGED
|
@@ -5,10 +5,11 @@ export { pluralForms, isAcceptedPluralForm } from './settings/plurals';
|
|
|
5
5
|
export { _getPluralForm as getPluralForm } from './locales/getPluralForm';
|
|
6
6
|
export { isVariable } from './utils/isVariable';
|
|
7
7
|
export { minifyVariableType } from './utils/minify';
|
|
8
|
-
export { encode,
|
|
8
|
+
export { decode, decodeFileContent, encode, encodeFileContent, } from './utils/base64';
|
|
9
9
|
export { isSupportedFileFormatTransform } from './utils/isSupportedFileFormatTransform';
|
|
10
10
|
export { API_VERSION } from './translate/api';
|
|
11
11
|
export { isErrorResult, unwrapApiResult, } from './translate/utils/unwrapApiResult';
|
|
12
|
+
export { createGtApiAdapter } from './adapter/createGtApi';
|
|
12
13
|
// derive
|
|
13
14
|
export { decodeVars } from './derive/decodeVars';
|
|
14
15
|
export { declareVar } from './derive/declareVar';
|