generaltranslation 9.3.1 → 9.4.1
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 +30 -0
- package/dist/adapter/createGtApi.d.ts +102 -0
- package/dist/adapter/createGtApi.js +373 -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 +62 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.js +85 -32
- package/dist/index.mjs +62 -30
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +178 -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 +176 -2
- package/dist/internal.mjs.map +1 -1
- package/dist/openapi.json +4775 -1992
- package/dist/{runtime-CqKaoInO.mjs → runtime-Bcp4F2ME.mjs} +33 -14
- package/dist/runtime-Bcp4F2ME.mjs.map +1 -0
- package/dist/{runtime-DeF1Ef5w.cjs → runtime-C25lwh9m.cjs} +32 -13
- package/dist/runtime-C25lwh9m.cjs.map +1 -0
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.d.cts +9 -1
- package/dist/runtime.d.mts +9 -1
- package/dist/runtime.d.ts +8 -0
- package/dist/runtime.js +44 -14
- 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 +3 -3
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# generaltranslation
|
|
2
2
|
|
|
3
|
+
## 9.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2288](https://github.com/generaltranslation/gt/pull/2288) [`90109bf`](https://github.com/generaltranslation/gt/commit/90109bf9ec4900819023176320629a5069fd7b51) Thanks [@eoinest](https://github.com/eoinest)! - Preserve configured locale identities across negotiation, routing, hooks, cookies, translation loaders, and caches, including when GT services are enabled. For example, configuring `en-gb` keeps that spelling in application-facing values while GT service requests and formatting use `en-GB`.
|
|
8
|
+
|
|
9
|
+
Locale negotiation accepts equivalent spellings and returns a configured identity, preserving exact matches between distinct aliases for the same language. This also applies to request-header negotiation: an `Accept-Language` preference of `fr` can resolve to a configured `brand-french` alias. Preserve support for legacy tags such as `sh` and `cnr`, and retain existing custom mappings when validating partial `setConfig()` updates.
|
|
10
|
+
|
|
11
|
+
Translation loaders and local filenames must use the configured identity: a loader for configured `en-gb` receives `en-gb`, not `en-GB`. Configure canonical spelling instead if the application requires it. Custom mapping `code` values must use canonical spelling, for example `'en-gb': { code: 'en-GB' }`. Canonicalize locales at GT service boundaries, including nested source-file locales in translation uploads and requests through the shared CLI/Sanity adapter. Require canonical locale codes or explicit custom mappings for CLI commands that use GT translation services. For example, using `en-us` with the API requires `customMapping: { "en-us": { "code": "en-US" } }`; otherwise the command exits with guidance before running the translation workflow. Local-only commands and dry runs retain their existing validation. Restore configured identities in service metadata; without a corresponding requested identity, use the first matching configured locale.
|
|
12
|
+
|
|
13
|
+
Align server/browser locale values and expose the configured locale list through `useLocales()`. In Next.js, preserve configured identities in localized paths, route overrides, and locale availability. Resolve unsupported locale preferences before deciding whether to prefix the default locale, and cache locale resolution during middleware initialization.
|
|
14
|
+
|
|
15
|
+
For Next.js App Router, read locale and region from server-provided conditions. Setters write request cookies and retain pending values for the refresh callback; hooks keep reading the current server conditions until a new snapshot arrives, including when a locale switch is rejected. Use `router.refresh()` on Next.js 16.1 and newer and a document reload on older versions to avoid stale layout/provider snapshots after middleware redirects. Detect this capability at build time, retain the existing document reload when returning to the default locale, and leave other React integrations' cookie-backed behavior unchanged. This adds no request-time cookie reads and does not change App Router's existing `enableI18n` behavior.
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`90109bf`](https://github.com/generaltranslation/gt/commit/90109bf9ec4900819023176320629a5069fd7b51)]:
|
|
18
|
+
- @generaltranslation/format@0.1.9
|
|
19
|
+
|
|
20
|
+
## 9.4.0
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- [#2215](https://github.com/generaltranslation/gt/pull/2215) [`5f5843b`](https://github.com/generaltranslation/gt/commit/5f5843b94066d9ee9c0703722105a189d2a4e3d5) Thanks [@chenxin-yan](https://github.com/chenxin-yan)! - Consolidate base64, file-content, locale-mapping, and job-polling seams in `generaltranslation/internal`, remove the generated API package's workspace dependency surface, and reuse the core helpers in the CLI and Sanity integration. `encodeBase64`, `decodeBase64`, `encodeFileContent`, and `decodeFileContent` are removed from `@generaltranslation/api` (and therefore `generaltranslation/api`); import the `generaltranslation/internal` equivalents instead.
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- [#2299](https://github.com/generaltranslation/gt/pull/2299) [`50098c6`](https://github.com/generaltranslation/gt/commit/50098c68e33b13585dde418e227cfca1cef3bf7e) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Accept whole markdown and MDX documents on the runtime translate endpoint via the new `fileFormat` entry metadata (`MD` or `MDX`).
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [[`50098c6`](https://github.com/generaltranslation/gt/commit/50098c68e33b13585dde418e227cfca1cef3bf7e), [`01658bd`](https://github.com/generaltranslation/gt/commit/01658bd018a337a9f2fb8f058195c7ea3d6f534e), [`5f5843b`](https://github.com/generaltranslation/gt/commit/5f5843b94066d9ee9c0703722105a189d2a4e3d5)]:
|
|
31
|
+
- @generaltranslation/api@0.3.0
|
|
32
|
+
|
|
3
33
|
## 9.3.1
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createApiClient, type ApiClientConfig, type AwaitJobsOptions, type CreateBranchData, type DownloadFilesData, type EnqueueFileTranslationsData, type GenerateProjectContextData, type GetFileInfoData, type UploadSourceFilesData, type UploadTranslationsData } from '@generaltranslation/api';
|
|
2
|
+
import type { CustomMapping } from '@generaltranslation/format/types';
|
|
3
|
+
import type { DownloadedFile } from '../types-dir/api/downloadFileBatch';
|
|
4
|
+
export type GtApiAdapterConfig = ApiClientConfig & {
|
|
5
|
+
customMapping?: CustomMapping;
|
|
6
|
+
};
|
|
7
|
+
export declare function createGtApiAdapter(defaultConfig?: ApiClientConfig): {
|
|
8
|
+
configure: (config: GtApiAdapterConfig) => void;
|
|
9
|
+
getClient: () => ReturnType<typeof createApiClient>;
|
|
10
|
+
getClientConfig: () => ApiClientConfig;
|
|
11
|
+
resolveAliasLocale(locale: string): string;
|
|
12
|
+
resolveCanonicalLocale(locale: string): string;
|
|
13
|
+
createBranch(body: CreateBranchData["body"]): Promise<{
|
|
14
|
+
branch: import("@generaltranslation/api").Branch;
|
|
15
|
+
}>;
|
|
16
|
+
queryFileData(body: GetFileInfoData["body"]): Promise<{
|
|
17
|
+
translatedFiles: {
|
|
18
|
+
locale: string;
|
|
19
|
+
branchId: string;
|
|
20
|
+
fileId: string;
|
|
21
|
+
versionId: string;
|
|
22
|
+
fileFormat: import("@generaltranslation/api").FileFormat;
|
|
23
|
+
dataFormat: string | null;
|
|
24
|
+
createdAt: string;
|
|
25
|
+
updatedAt: string;
|
|
26
|
+
approvedAt: string | null;
|
|
27
|
+
publishedAt: string | null;
|
|
28
|
+
completedAt: string | null;
|
|
29
|
+
}[];
|
|
30
|
+
sourceFiles: {
|
|
31
|
+
sourceLocale: string;
|
|
32
|
+
locales: string[];
|
|
33
|
+
branchId: string;
|
|
34
|
+
fileId: string;
|
|
35
|
+
versionId: string;
|
|
36
|
+
fileName: string;
|
|
37
|
+
fileFormat: import("@generaltranslation/api").FileFormat;
|
|
38
|
+
dataFormat: string | null;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
publishedAt: string | null;
|
|
42
|
+
}[];
|
|
43
|
+
}>;
|
|
44
|
+
downloadFileBatch(files: DownloadFilesData["body"]): Promise<{
|
|
45
|
+
files: DownloadedFile[];
|
|
46
|
+
count: number;
|
|
47
|
+
pending: {
|
|
48
|
+
branchId: string;
|
|
49
|
+
fileId: string;
|
|
50
|
+
locale: string;
|
|
51
|
+
versionId: string;
|
|
52
|
+
}[];
|
|
53
|
+
}>;
|
|
54
|
+
setupProject(files: GenerateProjectContextData["body"]["files"], options?: Omit<GenerateProjectContextData["body"], "files">): Promise<{
|
|
55
|
+
status: "completed";
|
|
56
|
+
} | {
|
|
57
|
+
setupJobId: string;
|
|
58
|
+
status: "queued";
|
|
59
|
+
}>;
|
|
60
|
+
enqueueFiles(files: EnqueueFileTranslationsData["body"]["files"], options: {
|
|
61
|
+
sourceLocale?: string;
|
|
62
|
+
targetLocales: string[];
|
|
63
|
+
modelProvider?: string;
|
|
64
|
+
force?: boolean;
|
|
65
|
+
}): Promise<{
|
|
66
|
+
jobData: {
|
|
67
|
+
[k: string]: any;
|
|
68
|
+
};
|
|
69
|
+
locales: string[];
|
|
70
|
+
message: string;
|
|
71
|
+
}>;
|
|
72
|
+
uploadSourceFiles(files: Array<{
|
|
73
|
+
source: UploadSourceFilesData["body"]["data"][number]["source"];
|
|
74
|
+
}>, options: {
|
|
75
|
+
sourceLocale: string;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
uploadedFiles: {
|
|
78
|
+
branchId?: string;
|
|
79
|
+
fileId: string;
|
|
80
|
+
versionId: string;
|
|
81
|
+
fileName: string;
|
|
82
|
+
fileFormat: import("@generaltranslation/api").FileFormat;
|
|
83
|
+
dataFormat?: string;
|
|
84
|
+
locale?: string;
|
|
85
|
+
}[];
|
|
86
|
+
}>;
|
|
87
|
+
awaitJobs(jobIds: readonly string[], options?: AwaitJobsOptions): Promise<import("@generaltranslation/api").AwaitJobsResult>;
|
|
88
|
+
uploadTranslations(files: UploadTranslationsData["body"]["data"], options: {
|
|
89
|
+
sourceLocale: string;
|
|
90
|
+
}): Promise<{
|
|
91
|
+
uploadedFiles: {
|
|
92
|
+
branchId?: string;
|
|
93
|
+
fileId: string;
|
|
94
|
+
versionId: string;
|
|
95
|
+
fileName: string;
|
|
96
|
+
fileFormat: import("@generaltranslation/api").FileFormat;
|
|
97
|
+
dataFormat?: string;
|
|
98
|
+
locale?: string;
|
|
99
|
+
}[];
|
|
100
|
+
}>;
|
|
101
|
+
};
|
|
102
|
+
export type GtApiAdapter = ReturnType<typeof createGtApiAdapter>;
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
49
|
+
var t = {};
|
|
50
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
51
|
+
t[p] = s[p];
|
|
52
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
53
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
54
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
55
|
+
t[p[i]] = s[p[i]];
|
|
56
|
+
}
|
|
57
|
+
return t;
|
|
58
|
+
};
|
|
59
|
+
import { createApiClient, createBranch, DEFAULT_BATCH_SIZE, downloadFiles, enqueueFileTranslations, generateProjectContext, getFileInfo, getTranslationJobInfo, pollJobs, processBatches, uploadSourceFiles, uploadTranslations, } from '@generaltranslation/api';
|
|
60
|
+
import { resolveAliasLocale, resolveCanonicalLocale, standardizeLocale, } from '@generaltranslation/format';
|
|
61
|
+
import { decodeFileContent, encodeFileContent } from '../utils/base64';
|
|
62
|
+
import { unwrapApiResult } from '../translate/utils/unwrapApiResult';
|
|
63
|
+
export function createGtApiAdapter(defaultConfig) {
|
|
64
|
+
var client = defaultConfig ? createApiClient(defaultConfig) : undefined;
|
|
65
|
+
var configuredClientConfig = defaultConfig;
|
|
66
|
+
var customMapping;
|
|
67
|
+
// Mapping resolves aliases; standardization also canonicalizes configured
|
|
68
|
+
// spellings such as en-us before they cross the service boundary.
|
|
69
|
+
function resolveServiceLocale(locale) {
|
|
70
|
+
return standardizeLocale(resolveCanonicalLocale(locale, customMapping));
|
|
71
|
+
}
|
|
72
|
+
function getClient() {
|
|
73
|
+
if (!client) {
|
|
74
|
+
throw new Error('API client not configured — call configureApiClient first');
|
|
75
|
+
}
|
|
76
|
+
return client;
|
|
77
|
+
}
|
|
78
|
+
function getClientConfig() {
|
|
79
|
+
if (!configuredClientConfig) {
|
|
80
|
+
throw new Error('API client not configured — call configureApiClient first');
|
|
81
|
+
}
|
|
82
|
+
return configuredClientConfig;
|
|
83
|
+
}
|
|
84
|
+
function configure(config) {
|
|
85
|
+
var mapping = config.customMapping, clientConfig = __rest(config, ["customMapping"]);
|
|
86
|
+
client = createApiClient(clientConfig);
|
|
87
|
+
configuredClientConfig = clientConfig;
|
|
88
|
+
customMapping = mapping;
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
configure: configure,
|
|
92
|
+
getClient: getClient,
|
|
93
|
+
getClientConfig: getClientConfig,
|
|
94
|
+
resolveAliasLocale: function (locale) {
|
|
95
|
+
return resolveAliasLocale(locale, customMapping);
|
|
96
|
+
},
|
|
97
|
+
resolveCanonicalLocale: function (locale) {
|
|
98
|
+
return resolveServiceLocale(locale);
|
|
99
|
+
},
|
|
100
|
+
createBranch: function (body) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
var _a;
|
|
103
|
+
return __generator(this, function (_b) {
|
|
104
|
+
switch (_b.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
_a = unwrapApiResult;
|
|
107
|
+
return [4 /*yield*/, createBranch({ body: body, client: getClient() })];
|
|
108
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
queryFileData: function (body) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
+
var result, _a;
|
|
116
|
+
var _b;
|
|
117
|
+
return __generator(this, function (_c) {
|
|
118
|
+
switch (_c.label) {
|
|
119
|
+
case 0:
|
|
120
|
+
_a = unwrapApiResult;
|
|
121
|
+
return [4 /*yield*/, getFileInfo({
|
|
122
|
+
body: __assign(__assign({}, body), { translatedFiles: (_b = body.translatedFiles) === null || _b === void 0 ? void 0 : _b.map(function (file) { return (__assign(__assign({}, file), { locale: resolveServiceLocale(file.locale) })); }) }),
|
|
123
|
+
client: getClient(),
|
|
124
|
+
})];
|
|
125
|
+
case 1:
|
|
126
|
+
result = _a.apply(void 0, [_c.sent()]);
|
|
127
|
+
return [2 /*return*/, __assign(__assign({}, result), { translatedFiles: result.translatedFiles.map(function (file) { return (__assign(__assign({}, file), { locale: resolveAliasLocale(file.locale, customMapping) })); }), sourceFiles: result.sourceFiles.map(function (file) { return (__assign(__assign({}, file), { sourceLocale: resolveAliasLocale(file.sourceLocale, customMapping), locales: file.locales.map(function (locale) {
|
|
128
|
+
return resolveAliasLocale(locale, customMapping);
|
|
129
|
+
}) })); }) })];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
downloadFileBatch: function (files) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
var request, responses;
|
|
137
|
+
var _this = this;
|
|
138
|
+
return __generator(this, function (_a) {
|
|
139
|
+
switch (_a.label) {
|
|
140
|
+
case 0:
|
|
141
|
+
request = function (batch) { return __awaiter(_this, void 0, void 0, function () {
|
|
142
|
+
var _a;
|
|
143
|
+
return __generator(this, function (_b) {
|
|
144
|
+
switch (_b.label) {
|
|
145
|
+
case 0:
|
|
146
|
+
_a = unwrapApiResult;
|
|
147
|
+
return [4 /*yield*/, downloadFiles({
|
|
148
|
+
body: batch.map(function (file) { return (__assign(__assign({}, file), { locale: file.locale
|
|
149
|
+
? resolveServiceLocale(file.locale)
|
|
150
|
+
: undefined })); }),
|
|
151
|
+
client: getClient(),
|
|
152
|
+
})];
|
|
153
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}); };
|
|
157
|
+
return [4 /*yield*/, processBatches(files, function (batch) { return __awaiter(_this, void 0, void 0, function () {
|
|
158
|
+
return __generator(this, function (_a) {
|
|
159
|
+
switch (_a.label) {
|
|
160
|
+
case 0: return [4 /*yield*/, request(batch)];
|
|
161
|
+
case 1: return [2 /*return*/, [
|
|
162
|
+
_a.sent()
|
|
163
|
+
]];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}); })];
|
|
167
|
+
case 1:
|
|
168
|
+
responses = _a.sent();
|
|
169
|
+
return [2 /*return*/, {
|
|
170
|
+
files: responses.flatMap(function (response) {
|
|
171
|
+
return response.files.map(function (file) { return (__assign(__assign(__assign({}, file), (file.locale && {
|
|
172
|
+
locale: resolveAliasLocale(file.locale, customMapping),
|
|
173
|
+
})), { data: decodeFileContent(file.data, file.fileFormat),
|
|
174
|
+
// OpenAPI currently types metadata as an open object; the API emits
|
|
175
|
+
// JSON values here, matching DownloadedFile's public contract.
|
|
176
|
+
metadata: file.metadata })); });
|
|
177
|
+
}),
|
|
178
|
+
count: responses.reduce(function (count, response) { return count + response.count; }, 0),
|
|
179
|
+
pending: responses.flatMap(function (response) { var _a; return (_a = response.pending) !== null && _a !== void 0 ? _a : []; }),
|
|
180
|
+
}];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
setupProject: function (files_1) {
|
|
186
|
+
return __awaiter(this, arguments, void 0, function (files, options) {
|
|
187
|
+
var _a;
|
|
188
|
+
var _b;
|
|
189
|
+
if (options === void 0) { options = {}; }
|
|
190
|
+
return __generator(this, function (_c) {
|
|
191
|
+
switch (_c.label) {
|
|
192
|
+
case 0:
|
|
193
|
+
_a = unwrapApiResult;
|
|
194
|
+
return [4 /*yield*/, generateProjectContext({
|
|
195
|
+
body: {
|
|
196
|
+
files: files.map(function (_a) {
|
|
197
|
+
var branchId = _a.branchId, fileId = _a.fileId, versionId = _a.versionId;
|
|
198
|
+
return ({
|
|
199
|
+
branchId: branchId,
|
|
200
|
+
fileId: fileId,
|
|
201
|
+
versionId: versionId,
|
|
202
|
+
});
|
|
203
|
+
}),
|
|
204
|
+
locales: (_b = options.locales) === null || _b === void 0 ? void 0 : _b.map(function (locale) {
|
|
205
|
+
return resolveServiceLocale(locale);
|
|
206
|
+
}),
|
|
207
|
+
force: options.force,
|
|
208
|
+
},
|
|
209
|
+
client: getClient(),
|
|
210
|
+
})];
|
|
211
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_c.sent()])];
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
enqueueFiles: function (files, options) {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
218
|
+
var targetLocales, result;
|
|
219
|
+
var _this = this;
|
|
220
|
+
return __generator(this, function (_a) {
|
|
221
|
+
switch (_a.label) {
|
|
222
|
+
case 0:
|
|
223
|
+
targetLocales = options.targetLocales.map(function (locale) {
|
|
224
|
+
return resolveServiceLocale(locale);
|
|
225
|
+
});
|
|
226
|
+
return [4 /*yield*/, processBatches(files, function (batch) { return __awaiter(_this, void 0, void 0, function () {
|
|
227
|
+
var response, _a, jobData;
|
|
228
|
+
return __generator(this, function (_b) {
|
|
229
|
+
switch (_b.label) {
|
|
230
|
+
case 0:
|
|
231
|
+
_a = unwrapApiResult;
|
|
232
|
+
return [4 /*yield*/, enqueueFileTranslations({
|
|
233
|
+
body: {
|
|
234
|
+
files: batch.map(function (_a) {
|
|
235
|
+
var branchId = _a.branchId, fileId = _a.fileId, versionId = _a.versionId, fileName = _a.fileName, transformFormat = _a.transformFormat;
|
|
236
|
+
return ({
|
|
237
|
+
branchId: branchId,
|
|
238
|
+
fileId: fileId,
|
|
239
|
+
versionId: versionId,
|
|
240
|
+
fileName: fileName,
|
|
241
|
+
transformFormat: transformFormat,
|
|
242
|
+
});
|
|
243
|
+
}),
|
|
244
|
+
targetLocales: targetLocales,
|
|
245
|
+
sourceLocale: options.sourceLocale
|
|
246
|
+
? resolveServiceLocale(options.sourceLocale)
|
|
247
|
+
: undefined,
|
|
248
|
+
// Consumers intentionally accept custom model-provider strings beyond
|
|
249
|
+
// the OpenAPI enum; preserve the existing wire behavior at this boundary.
|
|
250
|
+
modelProvider: options.modelProvider,
|
|
251
|
+
force: options.force,
|
|
252
|
+
},
|
|
253
|
+
client: getClient(),
|
|
254
|
+
})];
|
|
255
|
+
case 1:
|
|
256
|
+
response = _a.apply(void 0, [_b.sent()]);
|
|
257
|
+
jobData = 'jobData' in response ? response.jobData : response.data;
|
|
258
|
+
return [2 /*return*/, Object.entries(jobData)];
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}); })];
|
|
262
|
+
case 1:
|
|
263
|
+
result = _a.sent();
|
|
264
|
+
return [2 /*return*/, {
|
|
265
|
+
jobData: Object.fromEntries(result),
|
|
266
|
+
locales: targetLocales,
|
|
267
|
+
message: "Successfully enqueued ".concat(result.length, " file translation jobs in ").concat(Math.ceil(files.length / DEFAULT_BATCH_SIZE), " batch(es)"),
|
|
268
|
+
}];
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
uploadSourceFiles: function (files, options) {
|
|
274
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
275
|
+
var sourceLocale, result;
|
|
276
|
+
var _this = this;
|
|
277
|
+
return __generator(this, function (_a) {
|
|
278
|
+
switch (_a.label) {
|
|
279
|
+
case 0:
|
|
280
|
+
sourceLocale = resolveServiceLocale(options.sourceLocale);
|
|
281
|
+
return [4 /*yield*/, processBatches(files, function (batch) { return __awaiter(_this, void 0, void 0, function () {
|
|
282
|
+
var response, _a;
|
|
283
|
+
return __generator(this, function (_b) {
|
|
284
|
+
switch (_b.label) {
|
|
285
|
+
case 0:
|
|
286
|
+
_a = unwrapApiResult;
|
|
287
|
+
return [4 /*yield*/, uploadSourceFiles({
|
|
288
|
+
body: {
|
|
289
|
+
data: batch.map(function (_a) {
|
|
290
|
+
var source = _a.source;
|
|
291
|
+
return ({
|
|
292
|
+
source: __assign(__assign({}, source), { content: encodeFileContent(source.content, source.fileFormat), locale: resolveServiceLocale(source.locale) }),
|
|
293
|
+
});
|
|
294
|
+
}),
|
|
295
|
+
sourceLocale: sourceLocale,
|
|
296
|
+
},
|
|
297
|
+
client: getClient(),
|
|
298
|
+
})];
|
|
299
|
+
case 1:
|
|
300
|
+
response = _a.apply(void 0, [_b.sent()]);
|
|
301
|
+
return [2 /*return*/, response.uploadedFiles];
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
}); })];
|
|
305
|
+
case 1:
|
|
306
|
+
result = _a.sent();
|
|
307
|
+
return [2 /*return*/, { uploadedFiles: result }];
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
},
|
|
312
|
+
awaitJobs: function (jobIds, options) {
|
|
313
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
314
|
+
var _this = this;
|
|
315
|
+
return __generator(this, function (_a) {
|
|
316
|
+
return [2 /*return*/, pollJobs(jobIds, function (pendingJobIds, signal) { return __awaiter(_this, void 0, void 0, function () {
|
|
317
|
+
var _a;
|
|
318
|
+
return __generator(this, function (_b) {
|
|
319
|
+
switch (_b.label) {
|
|
320
|
+
case 0:
|
|
321
|
+
_a = unwrapApiResult;
|
|
322
|
+
return [4 /*yield*/, getTranslationJobInfo({
|
|
323
|
+
body: { jobIds: pendingJobIds },
|
|
324
|
+
client: getClient(),
|
|
325
|
+
signal: signal,
|
|
326
|
+
})];
|
|
327
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}); }, options)];
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
},
|
|
334
|
+
uploadTranslations: function (files, options) {
|
|
335
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
336
|
+
var result;
|
|
337
|
+
var _this = this;
|
|
338
|
+
return __generator(this, function (_a) {
|
|
339
|
+
switch (_a.label) {
|
|
340
|
+
case 0: return [4 /*yield*/, processBatches(files, function (batch) { return __awaiter(_this, void 0, void 0, function () {
|
|
341
|
+
var response, _a;
|
|
342
|
+
return __generator(this, function (_b) {
|
|
343
|
+
switch (_b.label) {
|
|
344
|
+
case 0:
|
|
345
|
+
_a = unwrapApiResult;
|
|
346
|
+
return [4 /*yield*/, uploadTranslations({
|
|
347
|
+
body: {
|
|
348
|
+
data: batch.map(function (_a) {
|
|
349
|
+
var source = _a.source, translations = _a.translations;
|
|
350
|
+
return ({
|
|
351
|
+
source: __assign(__assign({}, source), { content: encodeFileContent(source.content, source.fileFormat), locale: resolveServiceLocale(source.locale) }),
|
|
352
|
+
translations: translations.map(function (translation) { return (__assign(__assign({}, translation), { locale: resolveServiceLocale(translation.locale), content: encodeFileContent(translation.content, translation.fileFormat) })); }),
|
|
353
|
+
});
|
|
354
|
+
}),
|
|
355
|
+
sourceLocale: resolveServiceLocale(options.sourceLocale),
|
|
356
|
+
},
|
|
357
|
+
client: getClient(),
|
|
358
|
+
})];
|
|
359
|
+
case 1:
|
|
360
|
+
response = _a.apply(void 0, [_b.sent()]);
|
|
361
|
+
return [2 /*return*/, response.uploadedFiles];
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}); })];
|
|
365
|
+
case 1:
|
|
366
|
+
result = _a.sent();
|
|
367
|
+
return [2 /*return*/, { uploadedFiles: result }];
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_file = require("./file-B37WkCqM.cjs");
|
|
1
2
|
let _generaltranslation_icu = require("@generaltranslation/icu");
|
|
2
3
|
//#region src/utils/isSupportedFileFormatTransform.ts
|
|
3
4
|
const SUPPORTED_TRANSFORMATIONS = {
|
|
@@ -45,6 +46,12 @@ function decode(base64) {
|
|
|
45
46
|
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
46
47
|
return new TextDecoder().decode(bytes);
|
|
47
48
|
}
|
|
49
|
+
function encodeFileContent(content, fileFormat) {
|
|
50
|
+
return require_file.isBinaryFileFormat(fileFormat) ? content : encode(content);
|
|
51
|
+
}
|
|
52
|
+
function decodeFileContent(content, fileFormat) {
|
|
53
|
+
return require_file.isBinaryFileFormat(fileFormat) ? content : decode(content);
|
|
54
|
+
}
|
|
48
55
|
//#endregion
|
|
49
56
|
//#region src/derive/utils/traverseIcu.ts
|
|
50
57
|
/**
|
|
@@ -238,6 +245,12 @@ Object.defineProperty(exports, "decode", {
|
|
|
238
245
|
return decode;
|
|
239
246
|
}
|
|
240
247
|
});
|
|
248
|
+
Object.defineProperty(exports, "decodeFileContent", {
|
|
249
|
+
enumerable: true,
|
|
250
|
+
get: function() {
|
|
251
|
+
return decodeFileContent;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
241
254
|
Object.defineProperty(exports, "decodeVars", {
|
|
242
255
|
enumerable: true,
|
|
243
256
|
get: function() {
|
|
@@ -256,6 +269,12 @@ Object.defineProperty(exports, "encode", {
|
|
|
256
269
|
return encode;
|
|
257
270
|
}
|
|
258
271
|
});
|
|
272
|
+
Object.defineProperty(exports, "encodeFileContent", {
|
|
273
|
+
enumerable: true,
|
|
274
|
+
get: function() {
|
|
275
|
+
return encodeFileContent;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
259
278
|
Object.defineProperty(exports, "isGTIndexedSelectElement", {
|
|
260
279
|
enumerable: true,
|
|
261
280
|
get: function() {
|
|
@@ -281,4 +300,4 @@ Object.defineProperty(exports, "traverseIcu", {
|
|
|
281
300
|
}
|
|
282
301
|
});
|
|
283
302
|
|
|
284
|
-
//# sourceMappingURL=derive-
|
|
303
|
+
//# sourceMappingURL=derive-2CDqwrvS.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive-2CDqwrvS.cjs","names":["isBinaryFileFormat","TYPE","TYPE"],"sources":["../src/utils/isSupportedFileFormatTransform.ts","../src/utils/base64.ts","../src/derive/utils/traverseIcu.ts","../src/derive/utils/constants.ts","../src/derive/utils/regex.ts","../src/derive/utils/traverseHelpers.ts","../src/derive/decodeVars.ts","../src/derive/utils/sanitizeVar.ts","../src/derive/declareVar.ts","../src/derive/derive.ts"],"sourcesContent":["import type { FileFormat } from '../types-dir/api/file';\n\nconst SUPPORTED_TRANSFORMATIONS = {\n GTJSON: ['GTJSON'],\n JSON: ['JSON'],\n PO: ['PO'],\n // POT templates can produce translated PO catalog files.\n POT: ['POT', 'PO'],\n YAML: ['YAML'],\n MDX: ['MDX'],\n MD: ['MD'],\n TS: ['TS'],\n JS: ['JS'],\n HTML: ['HTML'],\n TXT: ['TXT'],\n TWILIO_CONTENT_JSON: ['TWILIO_CONTENT_JSON'],\n LOTTIE: ['LOTTIE'],\n SVG: ['SVG'],\n DOT_STRINGS: ['DOT_STRINGS'],\n DOT_STRINGSDICT: ['DOT_STRINGSDICT'],\n ANDROID_STRINGS: ['ANDROID_STRINGS'],\n XCSTRINGS: ['XCSTRINGS'],\n} as const satisfies Record<FileFormat, FileFormat[]>;\n\n/**\n * This function checks if a file format transformation is supported during translation\n * @param from - The source file format.\n * @param to - The target file format.\n * @returns True if the transformation is supported, false otherwise\n */\nexport function isSupportedFileFormatTransform(\n from: FileFormat,\n to: FileFormat\n): boolean {\n const toFormats: FileFormat[] | undefined = SUPPORTED_TRANSFORMATIONS[from];\n return toFormats?.includes(to) ?? false;\n}\n","import { isBinaryFileFormat, type FileFormat } from '../types-dir/api/file';\n\n// Encode a string to base64\nexport function encode(data: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(data, 'utf8').toString('base64');\n }\n // Browser path.\n const bytes = new TextEncoder().encode(data);\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n\n// Decode a base64 string to a string\nexport function decode(base64: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(base64, 'base64').toString('utf8');\n }\n // Browser path.\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n\nexport function encodeFileContent(\n content: string,\n fileFormat: FileFormat\n): string {\n return isBinaryFileFormat(fileFormat) ? content : encode(content);\n}\n\nexport function decodeFileContent(\n content: string,\n fileFormat: FileFormat\n): string {\n return isBinaryFileFormat(fileFormat) ? content : decode(content);\n}\n","import {\n parse,\n TYPE,\n type MessageFormatElement,\n type ParserOptions,\n} from '@generaltranslation/icu';\n\ntype TraverseIcuOptions = ParserOptions & {\n recurseIntoVisited?: boolean;\n};\n\n/**\n * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T\n * @param icu - The ICU string to traverse\n * @param shouldVisit - A function that returns true if the element should be visited\n * @param visitor - A function that is called for each element that matches the type T\n * @returns The modified AST of the ICU string.\n *\n * @note This function is a heavy operation, use sparingly\n */\nexport function traverseIcu<T extends MessageFormatElement>({\n icuString,\n shouldVisit,\n visitor,\n options: { recurseIntoVisited = true, ...otherOptions },\n}: {\n icuString: string;\n shouldVisit: (element: MessageFormatElement) => element is T;\n visitor: (element: T) => void;\n options: TraverseIcuOptions;\n}): MessageFormatElement[] {\n const ast = parse(icuString, otherOptions);\n handleChildren(ast);\n return ast;\n\n function handleChildren(children: MessageFormatElement[]): void {\n children.map(handleChild);\n }\n\n function handleChild(child: MessageFormatElement) {\n // handle select var\n let visited = false;\n if (shouldVisit(child)) {\n visitor(child);\n visited = true;\n }\n // recurse on children\n if (!visited || recurseIntoVisited) {\n if (child.type === TYPE.select || child.type === TYPE.plural) {\n Object.values(child.options)\n .map((option) => option.value)\n .map(handleChildren);\n } else if (child.type === TYPE.tag) {\n handleChildren(child.children);\n }\n }\n }\n}\n","export const VAR_IDENTIFIER = '_gt_';\nexport const VAR_NAME_IDENTIFIER = '_gt_var_name';\n","import { VAR_IDENTIFIER } from './constants';\n\n// Regex for _gt_# select\nexport const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(\n `^${VAR_IDENTIFIER}\\\\d+$`\n);\n\nexport const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);\n","import {\n GT_INDEXED_IDENTIFIER_REGEX,\n GT_UNINDEXED_IDENTIFIER_REGEX,\n} from './regex';\nimport { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';\nimport { TYPE, type MessageFormatElement } from '@generaltranslation/icu';\n\n// Visit any _gt_# select\nexport function isGTIndexedSelectElement(\n child: MessageFormatElement\n): child is GTIndexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n\n// Visit any _gt_ select\nexport function isGTUnindexedSelectElement(\n child: MessageFormatElement\n): child is GTUnindexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n","import { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\n\ntype Location = {\n start: number;\n end: number;\n value: string;\n};\n\n/**\n * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()\n * @example\n * const encodedIcu = \"Hi\" + declareVar(\"Brian\") + \", my name is {name}\"\n * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'\n * decodeVars(encodedIcu)\n * // 'Hi Brian, my name is {name}'\n */\nexport function decodeVars(icuString: string): 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 value:\n child.options.other.value.length > 0\n ? child.options.other.value[0].value\n : '',\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: {\n recurseIntoVisited: false,\n captureLocation: true,\n },\n });\n\n // Construct output string\n let previousIndex = 0;\n const outputList = [];\n for (let i = 0; i < variableLocations.length; i++) {\n outputList.push(icuString.slice(previousIndex, variableLocations[i].start));\n outputList.push(variableLocations[i].value);\n previousIndex = variableLocations[i].end;\n }\n if (previousIndex < icuString.length) {\n outputList.push(icuString.slice(previousIndex));\n }\n const outputString = outputList.join('');\n\n return outputString;\n}\n","/**\n * Sanitizes string by escaping ICU syntax\n *\n * Sanitize arbitrary string so it does not break the following ICU message syntax:\n * {_gt_, select, other {string_here}}\n *\n * Escapes ICU special characters by:\n * 1. Doubling all single quotes (U+0027 ')\n * 2. Adding a single quote before the first special character ({}<>)\n * 3. Adding a single quote after the last special character ({}<>)\n */\nexport function sanitizeVar(string: string): string {\n // First, double all single quotes (both ASCII and Unicode).\n let result = string.replace(/'/g, \"''\");\n\n // Find first and last positions of special characters\n const specialChars = /[{}<>]/;\n const firstSpecialIndex = result.search(specialChars);\n\n if (firstSpecialIndex === -1) {\n // No special characters; return with just doubled quotes.\n return result;\n }\n\n // Find last special character position\n let lastSpecialIndex = -1;\n for (let i = result.length - 1; i >= 0; i--) {\n if (specialChars.test(result[i])) {\n lastSpecialIndex = i;\n break;\n }\n }\n\n // Insert quotes around the special character region.\n result =\n result.slice(0, firstSpecialIndex) +\n \"'\" +\n result.slice(firstSpecialIndex, lastSpecialIndex + 1) +\n \"'\" +\n result.slice(lastSpecialIndex + 1);\n\n return result;\n}\n","import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';\nimport { sanitizeVar } from './utils/sanitizeVar';\n\n/**\n * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).\n *\n * @example\n * function nonDerivableFunction() {\n * return Math.random();\n * }\n *\n * function derivableFunction() {\n * if (condition) {\n * return declareVar(nonDerivableFunction())\n * }\n * return 'John Doe';\n * }\n *\n * const gt = useGT();\n * gt(`My name is ${derive(derivableFunction())}`);\n *\n * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.\n * @param {Object} [options] - The options for the sanitization.\n * @param {string} [options.$name] - The name of the variable.\n * @returns {string} The sanitized value.\n */\nexport function declareVar(\n variable: string | number | boolean | null | undefined,\n options?: { $name?: string }\n): string {\n // Variable section.\n const sanitizedVariable = sanitizeVar(String(variable ?? ''));\n const variableSection = ` other {${sanitizedVariable}}`;\n\n // Name section.\n let nameSection = '';\n if (options?.$name) {\n const sanitizedName = sanitizeVar(options.$name);\n nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizedName}}`;\n }\n\n // interpolate\n return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;\n}\n","/**\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` when a translation string or context needs content that is\n * computed from source code, but should still be discovered during extraction\n * instead of treated as a runtime interpolation variable. The CLI attempts to\n * resolve the derivable expression into every possible static value and\n * includes those values in the source content that gets translated.\n *\n * `derive()` returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing `derive()` calls to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${derive(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport function derive<T extends string | boolean | number | null | undefined>(\n content: T\n): T {\n return content;\n}\n"],"mappings":"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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { n as isBinaryFileFormat } from "./file-Dga6cyM8.mjs";
|
|
1
2
|
import { API_VERSION } from "@generaltranslation/api";
|
|
2
3
|
import { TYPE, parse } from "@generaltranslation/icu";
|
|
3
4
|
//#region src/utils/isSupportedFileFormatTransform.ts
|
|
@@ -46,6 +47,12 @@ function decode(base64) {
|
|
|
46
47
|
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
47
48
|
return new TextDecoder().decode(bytes);
|
|
48
49
|
}
|
|
50
|
+
function encodeFileContent(content, fileFormat) {
|
|
51
|
+
return isBinaryFileFormat(fileFormat) ? content : encode(content);
|
|
52
|
+
}
|
|
53
|
+
function decodeFileContent(content, fileFormat) {
|
|
54
|
+
return isBinaryFileFormat(fileFormat) ? content : decode(content);
|
|
55
|
+
}
|
|
49
56
|
//#endregion
|
|
50
57
|
//#region src/derive/utils/traverseIcu.ts
|
|
51
58
|
/**
|
|
@@ -221,6 +228,6 @@ function derive(content) {
|
|
|
221
228
|
return content;
|
|
222
229
|
}
|
|
223
230
|
//#endregion
|
|
224
|
-
export { isGTUnindexedSelectElement as a, decode as c,
|
|
231
|
+
export { isGTUnindexedSelectElement as a, decode as c, encodeFileContent as d, isSupportedFileFormatTransform as f, isGTIndexedSelectElement as i, decodeFileContent as l, declareVar as n, VAR_IDENTIFIER as o, API_VERSION as p, decodeVars as r, traverseIcu as s, derive as t, encode as u };
|
|
225
232
|
|
|
226
|
-
//# sourceMappingURL=derive-
|
|
233
|
+
//# sourceMappingURL=derive-CTzR56T_.mjs.map
|