lingo.dev 0.113.4 → 0.113.6
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/build/cli.cjs +1155 -259
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +1047 -151
- package/build/cli.mjs.map +1 -1
- package/package.json +4 -3
package/build/cli.cjs
CHANGED
|
@@ -2151,7 +2151,13 @@ function _isMetadataKey(key) {
|
|
|
2151
2151
|
}
|
|
2152
2152
|
|
|
2153
2153
|
// src/cli/loaders/android.ts
|
|
2154
|
+
var _module = require('module');
|
|
2154
2155
|
var _xml2js = require('xml2js');
|
|
2156
|
+
var require2 = _module.createRequire.call(void 0, import.meta.url);
|
|
2157
|
+
var sax = require2("sax");
|
|
2158
|
+
var defaultAndroidResourcesXml = `<?xml version="1.0" encoding="utf-8"?>
|
|
2159
|
+
<resources>
|
|
2160
|
+
</resources>`;
|
|
2155
2161
|
function createAndroidLoader() {
|
|
2156
2162
|
return createLoader({
|
|
2157
2163
|
async pull(locale, input2) {
|
|
@@ -2159,173 +2165,1053 @@ function createAndroidLoader() {
|
|
|
2159
2165
|
if (!input2) {
|
|
2160
2166
|
return {};
|
|
2161
2167
|
}
|
|
2162
|
-
const
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2168
|
+
const document = await parseAndroidDocument(input2);
|
|
2169
|
+
return buildPullResult(document);
|
|
2170
|
+
} catch (error) {
|
|
2171
|
+
console.error("Error parsing Android resource file:", error);
|
|
2172
|
+
throw new CLIError({
|
|
2173
|
+
message: "Failed to parse Android resource file",
|
|
2174
|
+
docUrl: "androidResouceError"
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
},
|
|
2178
|
+
async push(locale, payload, originalInput, originalLocale, pullInput, pullOutput) {
|
|
2179
|
+
try {
|
|
2180
|
+
const selectedBase = selectBaseXml(
|
|
2181
|
+
locale,
|
|
2182
|
+
originalLocale,
|
|
2183
|
+
pullInput,
|
|
2184
|
+
originalInput
|
|
2185
|
+
);
|
|
2186
|
+
const existingDocument = await parseAndroidDocument(selectedBase);
|
|
2187
|
+
const sourceDocument = await parseAndroidDocument(originalInput);
|
|
2188
|
+
const translatedDocument = buildTranslatedDocument(
|
|
2189
|
+
payload,
|
|
2190
|
+
existingDocument,
|
|
2191
|
+
sourceDocument
|
|
2192
|
+
);
|
|
2193
|
+
const referenceXml = selectedBase || originalInput || defaultAndroidResourcesXml;
|
|
2194
|
+
const declaration = resolveXmlDeclaration(referenceXml);
|
|
2195
|
+
return buildAndroidXml(translatedDocument, declaration);
|
|
2196
|
+
} catch (error) {
|
|
2197
|
+
console.error("Error generating Android resource file:", error);
|
|
2198
|
+
throw new CLIError({
|
|
2199
|
+
message: "Failed to generate Android resource file",
|
|
2200
|
+
docUrl: "androidResouceError"
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
function resolveXmlDeclaration(xml) {
|
|
2207
|
+
if (!xml) {
|
|
2208
|
+
const xmldec = {
|
|
2209
|
+
version: "1.0",
|
|
2210
|
+
encoding: "utf-8"
|
|
2211
|
+
};
|
|
2212
|
+
return {
|
|
2213
|
+
xmldec,
|
|
2214
|
+
headless: false
|
|
2215
|
+
};
|
|
2216
|
+
}
|
|
2217
|
+
const match2 = xml.match(
|
|
2218
|
+
/<\?xml\s+version="([^"]+)"(?:\s+encoding="([^"]+)")?\s*\?>/
|
|
2219
|
+
);
|
|
2220
|
+
if (match2) {
|
|
2221
|
+
const version = match2[1] && match2[1].trim().length > 0 ? match2[1] : "1.0";
|
|
2222
|
+
const encoding = match2[2] && match2[2].trim().length > 0 ? match2[2] : void 0;
|
|
2223
|
+
const xmldec = encoding ? { version, encoding } : { version };
|
|
2224
|
+
return {
|
|
2225
|
+
xmldec,
|
|
2226
|
+
headless: false
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
return { headless: true };
|
|
2230
|
+
}
|
|
2231
|
+
async function parseAndroidDocument(input2) {
|
|
2232
|
+
const xmlToParse = input2 && input2.trim().length > 0 ? input2 : defaultAndroidResourcesXml;
|
|
2233
|
+
const parsed = await _xml2js.parseStringPromise.call(void 0, xmlToParse, {
|
|
2234
|
+
explicitArray: true,
|
|
2235
|
+
explicitChildren: true,
|
|
2236
|
+
preserveChildrenOrder: true,
|
|
2237
|
+
charsAsChildren: true,
|
|
2238
|
+
includeWhiteChars: true,
|
|
2239
|
+
mergeAttrs: false,
|
|
2240
|
+
normalize: false,
|
|
2241
|
+
normalizeTags: false,
|
|
2242
|
+
trim: false,
|
|
2243
|
+
attrkey: "$",
|
|
2244
|
+
charkey: "_",
|
|
2245
|
+
childkey: "$$"
|
|
2246
|
+
});
|
|
2247
|
+
if (!parsed || !parsed.resources) {
|
|
2248
|
+
return {
|
|
2249
|
+
resources: { $$: [] },
|
|
2250
|
+
resourceNodes: []
|
|
2251
|
+
};
|
|
2252
|
+
}
|
|
2253
|
+
const resourcesNode = parsed.resources;
|
|
2254
|
+
resourcesNode["#name"] = _nullishCoalesce(resourcesNode["#name"], () => ( "resources"));
|
|
2255
|
+
resourcesNode.$$ = _nullishCoalesce(resourcesNode.$$, () => ( []));
|
|
2256
|
+
const metadata = extractResourceMetadata(xmlToParse);
|
|
2257
|
+
const resourceNodes = [];
|
|
2258
|
+
let metaIndex = 0;
|
|
2259
|
+
for (const child of resourcesNode.$$) {
|
|
2260
|
+
const elementName = _optionalChain([child, 'optionalAccess', _111 => _111["#name"]]);
|
|
2261
|
+
if (!isResourceElementName(elementName)) {
|
|
2262
|
+
continue;
|
|
2263
|
+
}
|
|
2264
|
+
const meta = metadata[metaIndex++];
|
|
2265
|
+
if (!meta || meta.type !== elementName) {
|
|
2266
|
+
continue;
|
|
2267
|
+
}
|
|
2268
|
+
const name = _nullishCoalesce(_optionalChain([child, 'optionalAccess', _112 => _112.$, 'optionalAccess', _113 => _113.name]), () => ( meta.name));
|
|
2269
|
+
if (!name) {
|
|
2270
|
+
continue;
|
|
2271
|
+
}
|
|
2272
|
+
const translatable = (_nullishCoalesce(_optionalChain([child, 'optionalAccess', _114 => _114.$, 'optionalAccess', _115 => _115.translatable]), () => ( ""))).toLowerCase() !== "false";
|
|
2273
|
+
switch (meta.type) {
|
|
2274
|
+
case "string": {
|
|
2275
|
+
resourceNodes.push({
|
|
2276
|
+
type: "string",
|
|
2277
|
+
name,
|
|
2278
|
+
translatable,
|
|
2279
|
+
node: child,
|
|
2280
|
+
meta: cloneTextMeta(meta.meta)
|
|
2281
|
+
});
|
|
2282
|
+
break;
|
|
2283
|
+
}
|
|
2284
|
+
case "string-array": {
|
|
2285
|
+
const itemNodes = _nullishCoalesce(_optionalChain([child, 'optionalAccess', _116 => _116.item]), () => ( []));
|
|
2286
|
+
const items = [];
|
|
2287
|
+
const templateItems = meta.items;
|
|
2288
|
+
for (let i = 0; i < Math.max(itemNodes.length, templateItems.length); i++) {
|
|
2289
|
+
const nodeItem = itemNodes[i];
|
|
2290
|
+
const templateItem = _nullishCoalesce(templateItems[i], () => ( templateItems[templateItems.length - 1]));
|
|
2291
|
+
if (!nodeItem) {
|
|
2170
2292
|
continue;
|
|
2171
2293
|
}
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2294
|
+
items.push({
|
|
2295
|
+
node: nodeItem,
|
|
2296
|
+
meta: cloneTextMeta(templateItem.meta)
|
|
2297
|
+
});
|
|
2176
2298
|
}
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
attrkey: "$",
|
|
2184
|
-
charkey: "_"
|
|
2299
|
+
resourceNodes.push({
|
|
2300
|
+
type: "string-array",
|
|
2301
|
+
name,
|
|
2302
|
+
translatable,
|
|
2303
|
+
node: child,
|
|
2304
|
+
items
|
|
2185
2305
|
});
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
itemValue === "" || /^\s+$/.test(itemValue) ? itemValue : itemValue.trim()
|
|
2208
|
-
);
|
|
2209
|
-
});
|
|
2210
|
-
}
|
|
2211
|
-
result[name] = items;
|
|
2306
|
+
break;
|
|
2307
|
+
}
|
|
2308
|
+
case "plurals": {
|
|
2309
|
+
const itemNodes = _nullishCoalesce(_optionalChain([child, 'optionalAccess', _117 => _117.item]), () => ( []));
|
|
2310
|
+
const templateItems = meta.items;
|
|
2311
|
+
const items = [];
|
|
2312
|
+
for (const templateItem of templateItems) {
|
|
2313
|
+
const quantity = templateItem.quantity;
|
|
2314
|
+
if (!quantity) {
|
|
2315
|
+
continue;
|
|
2316
|
+
}
|
|
2317
|
+
const nodeItem = itemNodes.find(
|
|
2318
|
+
(item) => _optionalChain([item, 'optionalAccess', _118 => _118.$, 'optionalAccess', _119 => _119.quantity]) === quantity
|
|
2319
|
+
);
|
|
2320
|
+
if (!nodeItem) {
|
|
2321
|
+
continue;
|
|
2322
|
+
}
|
|
2323
|
+
items.push({
|
|
2324
|
+
node: nodeItem,
|
|
2325
|
+
quantity,
|
|
2326
|
+
meta: cloneTextMeta(templateItem.meta)
|
|
2212
2327
|
});
|
|
2213
2328
|
}
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2329
|
+
resourceNodes.push({
|
|
2330
|
+
type: "plurals",
|
|
2331
|
+
name,
|
|
2332
|
+
translatable,
|
|
2333
|
+
node: child,
|
|
2334
|
+
items
|
|
2335
|
+
});
|
|
2336
|
+
break;
|
|
2337
|
+
}
|
|
2338
|
+
case "bool": {
|
|
2339
|
+
resourceNodes.push({
|
|
2340
|
+
type: "bool",
|
|
2341
|
+
name,
|
|
2342
|
+
translatable,
|
|
2343
|
+
node: child,
|
|
2344
|
+
meta: cloneTextMeta(meta.meta)
|
|
2345
|
+
});
|
|
2346
|
+
break;
|
|
2347
|
+
}
|
|
2348
|
+
case "integer": {
|
|
2349
|
+
resourceNodes.push({
|
|
2350
|
+
type: "integer",
|
|
2351
|
+
name,
|
|
2352
|
+
translatable,
|
|
2353
|
+
node: child,
|
|
2354
|
+
meta: cloneTextMeta(meta.meta)
|
|
2355
|
+
});
|
|
2356
|
+
break;
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
return { resources: resourcesNode, resourceNodes };
|
|
2361
|
+
}
|
|
2362
|
+
function buildPullResult(document) {
|
|
2363
|
+
const result = {};
|
|
2364
|
+
for (const resource of document.resourceNodes) {
|
|
2365
|
+
if (!resource.translatable) {
|
|
2366
|
+
continue;
|
|
2367
|
+
}
|
|
2368
|
+
switch (resource.type) {
|
|
2369
|
+
case "string": {
|
|
2370
|
+
result[resource.name] = decodeAndroidText(
|
|
2371
|
+
segmentsToString(resource.meta.segments)
|
|
2372
|
+
);
|
|
2373
|
+
break;
|
|
2374
|
+
}
|
|
2375
|
+
case "string-array": {
|
|
2376
|
+
result[resource.name] = resource.items.map(
|
|
2377
|
+
(item) => decodeAndroidText(segmentsToString(item.meta.segments))
|
|
2378
|
+
);
|
|
2379
|
+
break;
|
|
2380
|
+
}
|
|
2381
|
+
case "plurals": {
|
|
2382
|
+
const pluralMap = {};
|
|
2383
|
+
for (const item of resource.items) {
|
|
2384
|
+
pluralMap[item.quantity] = decodeAndroidText(
|
|
2385
|
+
segmentsToString(item.meta.segments)
|
|
2386
|
+
);
|
|
2236
2387
|
}
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2388
|
+
result[resource.name] = pluralMap;
|
|
2389
|
+
break;
|
|
2390
|
+
}
|
|
2391
|
+
case "bool": {
|
|
2392
|
+
const value = segmentsToString(resource.meta.segments).trim();
|
|
2393
|
+
result[resource.name] = value === "true";
|
|
2394
|
+
break;
|
|
2395
|
+
}
|
|
2396
|
+
case "integer": {
|
|
2397
|
+
const value = parseInt(
|
|
2398
|
+
segmentsToString(resource.meta.segments).trim(),
|
|
2399
|
+
10
|
|
2400
|
+
);
|
|
2401
|
+
result[resource.name] = Number.isNaN(value) ? 0 : value;
|
|
2402
|
+
break;
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
return result;
|
|
2407
|
+
}
|
|
2408
|
+
function buildTranslatedDocument(payload, existingDocument, sourceDocument) {
|
|
2409
|
+
const templateDocument = sourceDocument;
|
|
2410
|
+
const finalDocument = cloneDocumentStructure(templateDocument);
|
|
2411
|
+
const templateMap = createResourceMap(templateDocument);
|
|
2412
|
+
const existingMap = createResourceMap(existingDocument);
|
|
2413
|
+
const payloadEntries = _nullishCoalesce(payload, () => ( {}));
|
|
2414
|
+
const finalMap = createResourceMap(finalDocument);
|
|
2415
|
+
for (const resource of finalDocument.resourceNodes) {
|
|
2416
|
+
if (!resource.translatable) {
|
|
2417
|
+
continue;
|
|
2418
|
+
}
|
|
2419
|
+
const templateResource = templateMap.get(resource.name);
|
|
2420
|
+
let translationValue;
|
|
2421
|
+
if (Object.prototype.hasOwnProperty.call(payloadEntries, resource.name) && payloadEntries[resource.name] !== void 0 && payloadEntries[resource.name] !== null) {
|
|
2422
|
+
translationValue = payloadEntries[resource.name];
|
|
2423
|
+
} else if (existingMap.has(resource.name)) {
|
|
2424
|
+
translationValue = extractValueFromResource(
|
|
2425
|
+
existingMap.get(resource.name)
|
|
2426
|
+
);
|
|
2427
|
+
} else {
|
|
2428
|
+
translationValue = extractValueFromResource(_nullishCoalesce(templateResource, () => ( resource)));
|
|
2429
|
+
}
|
|
2430
|
+
updateResourceNode(resource, translationValue, templateResource);
|
|
2431
|
+
}
|
|
2432
|
+
for (const resource of existingDocument.resourceNodes) {
|
|
2433
|
+
if (finalMap.has(resource.name)) {
|
|
2434
|
+
continue;
|
|
2435
|
+
}
|
|
2436
|
+
const cloned = cloneResourceNode(resource);
|
|
2437
|
+
appendResourceNode(finalDocument, cloned);
|
|
2438
|
+
finalMap.set(cloned.name, cloned);
|
|
2439
|
+
}
|
|
2440
|
+
for (const [name, value] of Object.entries(payloadEntries)) {
|
|
2441
|
+
if (finalMap.has(name)) {
|
|
2442
|
+
continue;
|
|
2443
|
+
}
|
|
2444
|
+
try {
|
|
2445
|
+
const inferred = createResourceNodeFromValue(name, value);
|
|
2446
|
+
appendResourceNode(finalDocument, inferred);
|
|
2447
|
+
finalMap.set(name, inferred);
|
|
2448
|
+
} catch (error) {
|
|
2449
|
+
if (error instanceof CLIError) {
|
|
2450
|
+
throw error;
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
return finalDocument;
|
|
2455
|
+
}
|
|
2456
|
+
function buildAndroidXml(document, declaration) {
|
|
2457
|
+
const xmlBody = serializeElement(document.resources);
|
|
2458
|
+
if (declaration.headless) {
|
|
2459
|
+
return xmlBody;
|
|
2460
|
+
}
|
|
2461
|
+
if (declaration.xmldec) {
|
|
2462
|
+
const { version, encoding } = declaration.xmldec;
|
|
2463
|
+
const encodingPart = encoding ? ` encoding="${encoding}"` : "";
|
|
2464
|
+
return `<?xml version="${version}"${encodingPart}?>
|
|
2465
|
+
${xmlBody}`;
|
|
2466
|
+
}
|
|
2467
|
+
return `<?xml version="1.0" encoding="utf-8"?>
|
|
2468
|
+
${xmlBody}`;
|
|
2469
|
+
}
|
|
2470
|
+
function selectBaseXml(locale, originalLocale, pullInput, originalInput) {
|
|
2471
|
+
if (locale === originalLocale) {
|
|
2472
|
+
return _nullishCoalesce(pullInput, () => ( originalInput));
|
|
2473
|
+
}
|
|
2474
|
+
return _nullishCoalesce(pullInput, () => ( originalInput));
|
|
2475
|
+
}
|
|
2476
|
+
function updateResourceNode(target, rawValue, template) {
|
|
2477
|
+
switch (target.type) {
|
|
2478
|
+
case "string": {
|
|
2479
|
+
const value = asString(rawValue, target.name);
|
|
2480
|
+
const templateMeta = template && template.type === "string" ? template.meta : target.meta;
|
|
2481
|
+
const useCdata = templateMeta.hasCdata;
|
|
2482
|
+
setTextualNodeContent(target.node, value, useCdata);
|
|
2483
|
+
target.meta = makeTextMeta([
|
|
2484
|
+
{ kind: useCdata ? "cdata" : "text", value }
|
|
2485
|
+
]);
|
|
2486
|
+
break;
|
|
2487
|
+
}
|
|
2488
|
+
case "string-array": {
|
|
2489
|
+
const values = asStringArray(rawValue, target.name);
|
|
2490
|
+
const templateItems = template && template.type === "string-array" ? template.items : target.items;
|
|
2491
|
+
const maxLength = Math.max(target.items.length, templateItems.length);
|
|
2492
|
+
for (let index = 0; index < maxLength; index++) {
|
|
2493
|
+
const targetItem = target.items[index];
|
|
2494
|
+
const templateItem = _nullishCoalesce(_nullishCoalesce(templateItems[index], () => ( templateItems[templateItems.length - 1])), () => ( target.items[index]));
|
|
2495
|
+
if (!targetItem || !templateItem) {
|
|
2496
|
+
continue;
|
|
2245
2497
|
}
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2498
|
+
const translation = index < values.length ? values[index] : segmentsToString(templateItem.meta.segments);
|
|
2499
|
+
const useCdata = templateItem.meta.hasCdata;
|
|
2500
|
+
setTextualNodeContent(targetItem.node, translation, useCdata);
|
|
2501
|
+
targetItem.meta = makeTextMeta([
|
|
2502
|
+
{ kind: useCdata ? "cdata" : "text", value: translation }
|
|
2503
|
+
]);
|
|
2504
|
+
}
|
|
2505
|
+
break;
|
|
2506
|
+
}
|
|
2507
|
+
case "plurals": {
|
|
2508
|
+
const pluralValues = asPluralMap(rawValue, target.name);
|
|
2509
|
+
const templateItems = template && template.type === "plurals" ? template.items : target.items;
|
|
2510
|
+
const templateMap = new Map(
|
|
2511
|
+
templateItems.map((item) => [item.quantity, item])
|
|
2512
|
+
);
|
|
2513
|
+
for (const item of target.items) {
|
|
2514
|
+
const templateItem = _nullishCoalesce(templateMap.get(item.quantity), () => ( templateMap.values().next().value));
|
|
2515
|
+
const fallback = templateItem ? segmentsToString(templateItem.meta.segments) : segmentsToString(item.meta.segments);
|
|
2516
|
+
const translation = typeof pluralValues[item.quantity] === "string" ? pluralValues[item.quantity] : fallback;
|
|
2517
|
+
const useCdata = templateItem ? templateItem.meta.hasCdata : item.meta.hasCdata;
|
|
2518
|
+
setTextualNodeContent(item.node, translation, useCdata);
|
|
2519
|
+
item.meta = makeTextMeta([
|
|
2520
|
+
{ kind: useCdata ? "cdata" : "text", value: translation }
|
|
2521
|
+
]);
|
|
2522
|
+
}
|
|
2523
|
+
break;
|
|
2524
|
+
}
|
|
2525
|
+
case "bool": {
|
|
2526
|
+
const boolValue = asBoolean(rawValue, target.name);
|
|
2527
|
+
const strValue = boolValue ? "true" : "false";
|
|
2528
|
+
setTextualNodeContent(target.node, strValue, false);
|
|
2529
|
+
target.meta = makeTextMeta([{ kind: "text", value: strValue }]);
|
|
2530
|
+
break;
|
|
2531
|
+
}
|
|
2532
|
+
case "integer": {
|
|
2533
|
+
const intValue = asInteger(rawValue, target.name);
|
|
2534
|
+
const strValue = intValue.toString();
|
|
2535
|
+
setTextualNodeContent(target.node, strValue, false);
|
|
2536
|
+
target.meta = makeTextMeta([{ kind: "text", value: strValue }]);
|
|
2537
|
+
break;
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
function appendResourceNode(document, resourceNode) {
|
|
2542
|
+
document.resources.$$ = _nullishCoalesce(document.resources.$$, () => ( []));
|
|
2543
|
+
const children = document.resources.$$;
|
|
2544
|
+
if (children.length === 0 || children[children.length - 1]["#name"] !== "__text__" && children[children.length - 1]["#name"] !== "__comment__") {
|
|
2545
|
+
children.push({ "#name": "__text__", _: "\n " });
|
|
2546
|
+
}
|
|
2547
|
+
children.push(resourceNode.node);
|
|
2548
|
+
children.push({ "#name": "__text__", _: "\n" });
|
|
2549
|
+
document.resourceNodes.push(resourceNode);
|
|
2550
|
+
}
|
|
2551
|
+
function setTextualNodeContent(node, value, useCdata) {
|
|
2552
|
+
const escapedValue = useCdata ? value : escapeAndroidString(value);
|
|
2553
|
+
node._ = escapedValue;
|
|
2554
|
+
node.$$ = _nullishCoalesce(node.$$, () => ( []));
|
|
2555
|
+
let textNode = node.$$.find(
|
|
2556
|
+
(child) => child["#name"] === "__text__" || child["#name"] === "__cdata"
|
|
2557
|
+
);
|
|
2558
|
+
if (!textNode) {
|
|
2559
|
+
textNode = {};
|
|
2560
|
+
node.$$.push(textNode);
|
|
2561
|
+
}
|
|
2562
|
+
textNode["#name"] = useCdata ? "__cdata" : "__text__";
|
|
2563
|
+
textNode._ = useCdata ? value : escapedValue;
|
|
2564
|
+
}
|
|
2565
|
+
function buildResourceNameMap(document) {
|
|
2566
|
+
const map = /* @__PURE__ */ new Map();
|
|
2567
|
+
for (const node of document.resourceNodes) {
|
|
2568
|
+
if (!map.has(node.name)) {
|
|
2569
|
+
map.set(node.name, node);
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
return map;
|
|
2573
|
+
}
|
|
2574
|
+
function createResourceMap(document) {
|
|
2575
|
+
return buildResourceNameMap(document);
|
|
2576
|
+
}
|
|
2577
|
+
function cloneResourceNode(resource) {
|
|
2578
|
+
switch (resource.type) {
|
|
2579
|
+
case "string": {
|
|
2580
|
+
const nodeClone = deepClone(resource.node);
|
|
2581
|
+
return {
|
|
2582
|
+
type: "string",
|
|
2583
|
+
name: resource.name,
|
|
2584
|
+
translatable: resource.translatable,
|
|
2585
|
+
node: nodeClone,
|
|
2586
|
+
meta: cloneTextMeta(resource.meta)
|
|
2587
|
+
};
|
|
2588
|
+
}
|
|
2589
|
+
case "string-array": {
|
|
2590
|
+
const nodeClone = deepClone(resource.node);
|
|
2591
|
+
const itemNodes = _nullishCoalesce(nodeClone.item, () => ( []));
|
|
2592
|
+
const items = itemNodes.map((itemNode, index) => {
|
|
2593
|
+
const templateMeta = _nullishCoalesce(_nullishCoalesce(_optionalChain([resource, 'access', _120 => _120.items, 'access', _121 => _121[index], 'optionalAccess', _122 => _122.meta]), () => ( _optionalChain([resource, 'access', _123 => _123.items, 'access', _124 => _124[resource.items.length - 1], 'optionalAccess', _125 => _125.meta]))), () => ( makeTextMeta([])));
|
|
2594
|
+
return {
|
|
2595
|
+
node: itemNode,
|
|
2596
|
+
meta: cloneTextMeta(templateMeta)
|
|
2597
|
+
};
|
|
2598
|
+
});
|
|
2599
|
+
return {
|
|
2600
|
+
type: "string-array",
|
|
2601
|
+
name: resource.name,
|
|
2602
|
+
translatable: resource.translatable,
|
|
2603
|
+
node: nodeClone,
|
|
2604
|
+
items
|
|
2605
|
+
};
|
|
2606
|
+
}
|
|
2607
|
+
case "plurals": {
|
|
2608
|
+
const nodeClone = deepClone(resource.node);
|
|
2609
|
+
const itemNodes = _nullishCoalesce(nodeClone.item, () => ( []));
|
|
2610
|
+
const items = [];
|
|
2611
|
+
for (const templateItem of resource.items) {
|
|
2612
|
+
const cloneNode = itemNodes.find(
|
|
2613
|
+
(item) => _optionalChain([item, 'optionalAccess', _126 => _126.$, 'optionalAccess', _127 => _127.quantity]) === templateItem.quantity
|
|
2614
|
+
);
|
|
2615
|
+
if (!cloneNode) {
|
|
2616
|
+
continue;
|
|
2254
2617
|
}
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2618
|
+
items.push({
|
|
2619
|
+
node: cloneNode,
|
|
2620
|
+
quantity: templateItem.quantity,
|
|
2621
|
+
meta: cloneTextMeta(templateItem.meta)
|
|
2622
|
+
});
|
|
2623
|
+
}
|
|
2624
|
+
return {
|
|
2625
|
+
type: "plurals",
|
|
2626
|
+
name: resource.name,
|
|
2627
|
+
translatable: resource.translatable,
|
|
2628
|
+
node: nodeClone,
|
|
2629
|
+
items
|
|
2630
|
+
};
|
|
2631
|
+
}
|
|
2632
|
+
case "bool": {
|
|
2633
|
+
const nodeClone = deepClone(resource.node);
|
|
2634
|
+
return {
|
|
2635
|
+
type: "bool",
|
|
2636
|
+
name: resource.name,
|
|
2637
|
+
translatable: resource.translatable,
|
|
2638
|
+
node: nodeClone,
|
|
2639
|
+
meta: cloneTextMeta(resource.meta)
|
|
2640
|
+
};
|
|
2641
|
+
}
|
|
2642
|
+
case "integer": {
|
|
2643
|
+
const nodeClone = deepClone(resource.node);
|
|
2644
|
+
return {
|
|
2645
|
+
type: "integer",
|
|
2646
|
+
name: resource.name,
|
|
2647
|
+
translatable: resource.translatable,
|
|
2648
|
+
node: nodeClone,
|
|
2649
|
+
meta: cloneTextMeta(resource.meta)
|
|
2650
|
+
};
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
function cloneTextMeta(meta) {
|
|
2655
|
+
return {
|
|
2656
|
+
hasCdata: meta.hasCdata,
|
|
2657
|
+
segments: meta.segments.map((segment) => ({ ...segment }))
|
|
2658
|
+
};
|
|
2659
|
+
}
|
|
2660
|
+
function asString(value, name) {
|
|
2661
|
+
if (typeof value === "string") {
|
|
2662
|
+
return value;
|
|
2663
|
+
}
|
|
2664
|
+
throw new CLIError({
|
|
2665
|
+
message: `Expected string value for resource "${name}"`,
|
|
2666
|
+
docUrl: "androidResouceError"
|
|
2667
|
+
});
|
|
2668
|
+
}
|
|
2669
|
+
function asStringArray(value, name) {
|
|
2670
|
+
if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
|
|
2671
|
+
return value;
|
|
2672
|
+
}
|
|
2673
|
+
throw new CLIError({
|
|
2674
|
+
message: `Expected array of strings for resource "${name}"`,
|
|
2675
|
+
docUrl: "androidResouceError"
|
|
2676
|
+
});
|
|
2677
|
+
}
|
|
2678
|
+
function asPluralMap(value, name) {
|
|
2679
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
2680
|
+
const result = {};
|
|
2681
|
+
for (const [quantity, pluralValue] of Object.entries(value)) {
|
|
2682
|
+
if (typeof pluralValue !== "string") {
|
|
2258
2683
|
throw new CLIError({
|
|
2259
|
-
message: "
|
|
2684
|
+
message: `Expected plural item "${quantity}" of "${name}" to be a string`,
|
|
2260
2685
|
docUrl: "androidResouceError"
|
|
2261
2686
|
});
|
|
2262
2687
|
}
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2688
|
+
result[quantity] = pluralValue;
|
|
2689
|
+
}
|
|
2690
|
+
return result;
|
|
2691
|
+
}
|
|
2692
|
+
throw new CLIError({
|
|
2693
|
+
message: `Expected object value for plurals resource "${name}"`,
|
|
2694
|
+
docUrl: "androidResouceError"
|
|
2695
|
+
});
|
|
2696
|
+
}
|
|
2697
|
+
function asBoolean(value, name) {
|
|
2698
|
+
if (typeof value === "boolean") {
|
|
2699
|
+
return value;
|
|
2700
|
+
}
|
|
2701
|
+
if (typeof value === "string") {
|
|
2702
|
+
if (value === "true" || value === "false") {
|
|
2703
|
+
return value === "true";
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
throw new CLIError({
|
|
2707
|
+
message: `Expected boolean value for resource "${name}"`,
|
|
2708
|
+
docUrl: "androidResouceError"
|
|
2709
|
+
});
|
|
2710
|
+
}
|
|
2711
|
+
function asInteger(value, name) {
|
|
2712
|
+
if (typeof value === "number" && Number.isInteger(value)) {
|
|
2713
|
+
return value;
|
|
2714
|
+
}
|
|
2715
|
+
throw new CLIError({
|
|
2716
|
+
message: `Expected number value for resource "${name}"`,
|
|
2717
|
+
docUrl: "androidResouceError"
|
|
2718
|
+
});
|
|
2719
|
+
}
|
|
2720
|
+
function escapeAndroidString(value) {
|
|
2721
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/(?<!\\)'/g, "\\'");
|
|
2722
|
+
}
|
|
2723
|
+
function segmentsToString(segments) {
|
|
2724
|
+
return segments.map((segment) => segment.value).join("");
|
|
2725
|
+
}
|
|
2726
|
+
function makeTextMeta(segments) {
|
|
2727
|
+
return {
|
|
2728
|
+
segments,
|
|
2729
|
+
hasCdata: segments.some((segment) => segment.kind === "cdata")
|
|
2730
|
+
};
|
|
2731
|
+
}
|
|
2732
|
+
function createResourceNodeFromValue(name, value) {
|
|
2733
|
+
const inferredType = inferTypeFromValue(value);
|
|
2734
|
+
switch (inferredType) {
|
|
2735
|
+
case "string": {
|
|
2736
|
+
const stringValue = asString(value, name);
|
|
2737
|
+
const escaped = escapeAndroidString(stringValue);
|
|
2738
|
+
const node = {
|
|
2739
|
+
"#name": "string",
|
|
2740
|
+
$: { name },
|
|
2741
|
+
_: escaped,
|
|
2742
|
+
$$: [{ "#name": "__text__", _: escaped }]
|
|
2743
|
+
};
|
|
2744
|
+
return {
|
|
2745
|
+
type: "string",
|
|
2746
|
+
name,
|
|
2747
|
+
translatable: true,
|
|
2748
|
+
node,
|
|
2749
|
+
meta: makeTextMeta([{ kind: "text", value: stringValue }])
|
|
2750
|
+
};
|
|
2751
|
+
}
|
|
2752
|
+
case "string-array": {
|
|
2753
|
+
const items = asStringArray(value, name);
|
|
2754
|
+
const node = {
|
|
2755
|
+
"#name": "string-array",
|
|
2756
|
+
$: { name },
|
|
2757
|
+
$$: [],
|
|
2758
|
+
item: []
|
|
2759
|
+
};
|
|
2760
|
+
const itemNodes = [];
|
|
2761
|
+
for (const itemValue of items) {
|
|
2762
|
+
const escaped = escapeAndroidString(itemValue);
|
|
2763
|
+
const itemNode = {
|
|
2764
|
+
"#name": "item",
|
|
2765
|
+
_: escaped,
|
|
2766
|
+
$$: [{ "#name": "__text__", _: escaped }]
|
|
2274
2767
|
};
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2768
|
+
node.$$.push(itemNode);
|
|
2769
|
+
node.item.push(itemNode);
|
|
2770
|
+
itemNodes.push({
|
|
2771
|
+
node: itemNode,
|
|
2772
|
+
meta: makeTextMeta([{ kind: "text", value: itemValue }])
|
|
2773
|
+
});
|
|
2774
|
+
}
|
|
2775
|
+
return {
|
|
2776
|
+
type: "string-array",
|
|
2777
|
+
name,
|
|
2778
|
+
translatable: true,
|
|
2779
|
+
node,
|
|
2780
|
+
items: itemNodes
|
|
2781
|
+
};
|
|
2782
|
+
}
|
|
2783
|
+
case "plurals": {
|
|
2784
|
+
const pluralMap = asPluralMap(value, name);
|
|
2785
|
+
const node = {
|
|
2786
|
+
"#name": "plurals",
|
|
2787
|
+
$: { name },
|
|
2788
|
+
$$: [],
|
|
2789
|
+
item: []
|
|
2790
|
+
};
|
|
2791
|
+
const items = [];
|
|
2792
|
+
for (const [quantity, pluralValue] of Object.entries(pluralMap)) {
|
|
2793
|
+
const escaped = escapeAndroidString(pluralValue);
|
|
2794
|
+
const itemNode = {
|
|
2795
|
+
"#name": "item",
|
|
2796
|
+
$: { quantity },
|
|
2797
|
+
_: escaped,
|
|
2798
|
+
$$: [{ "#name": "__text__", _: escaped }]
|
|
2279
2799
|
};
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2800
|
+
node.$$.push(itemNode);
|
|
2801
|
+
node.item.push(itemNode);
|
|
2802
|
+
items.push({
|
|
2803
|
+
node: itemNode,
|
|
2804
|
+
quantity,
|
|
2805
|
+
meta: makeTextMeta([{ kind: "text", value: pluralValue }])
|
|
2806
|
+
});
|
|
2807
|
+
}
|
|
2808
|
+
return {
|
|
2809
|
+
type: "plurals",
|
|
2810
|
+
name,
|
|
2811
|
+
translatable: true,
|
|
2812
|
+
node,
|
|
2813
|
+
items
|
|
2814
|
+
};
|
|
2815
|
+
}
|
|
2816
|
+
case "bool": {
|
|
2817
|
+
const boolValue = asBoolean(value, name);
|
|
2818
|
+
const textValue = boolValue ? "true" : "false";
|
|
2819
|
+
const node = {
|
|
2820
|
+
"#name": "bool",
|
|
2821
|
+
$: { name },
|
|
2822
|
+
_: textValue,
|
|
2823
|
+
$$: [{ "#name": "__text__", _: textValue }]
|
|
2824
|
+
};
|
|
2825
|
+
return {
|
|
2826
|
+
type: "bool",
|
|
2827
|
+
name,
|
|
2828
|
+
translatable: true,
|
|
2829
|
+
node,
|
|
2830
|
+
meta: makeTextMeta([{ kind: "text", value: textValue }])
|
|
2831
|
+
};
|
|
2832
|
+
}
|
|
2833
|
+
case "integer": {
|
|
2834
|
+
const intValue = asInteger(value, name);
|
|
2835
|
+
const textValue = intValue.toString();
|
|
2836
|
+
const node = {
|
|
2837
|
+
"#name": "integer",
|
|
2838
|
+
$: { name },
|
|
2839
|
+
_: textValue,
|
|
2840
|
+
$$: [{ "#name": "__text__", _: textValue }]
|
|
2841
|
+
};
|
|
2842
|
+
return {
|
|
2843
|
+
type: "integer",
|
|
2844
|
+
name,
|
|
2845
|
+
translatable: true,
|
|
2846
|
+
node,
|
|
2847
|
+
meta: makeTextMeta([{ kind: "text", value: textValue }])
|
|
2848
|
+
};
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
function cloneDocumentStructure(document) {
|
|
2853
|
+
const resourcesClone = deepClone(document.resources);
|
|
2854
|
+
const lookup = buildResourceLookup(resourcesClone);
|
|
2855
|
+
const resourceNodes = [];
|
|
2856
|
+
for (const resource of document.resourceNodes) {
|
|
2857
|
+
const cloned = cloneResourceNodeFromLookup(resource, lookup);
|
|
2858
|
+
resourceNodes.push(cloned);
|
|
2859
|
+
}
|
|
2860
|
+
return {
|
|
2861
|
+
resources: resourcesClone,
|
|
2862
|
+
resourceNodes
|
|
2863
|
+
};
|
|
2864
|
+
}
|
|
2865
|
+
function buildResourceLookup(resources) {
|
|
2866
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
2867
|
+
const children = Array.isArray(resources.$$) ? resources.$$ : [];
|
|
2868
|
+
for (const child of children) {
|
|
2869
|
+
const type = _optionalChain([child, 'optionalAccess', _128 => _128["#name"]]);
|
|
2870
|
+
const name = _optionalChain([child, 'optionalAccess', _129 => _129.$, 'optionalAccess', _130 => _130.name]);
|
|
2871
|
+
if (!type || !name || !isResourceElementName(type)) {
|
|
2872
|
+
continue;
|
|
2873
|
+
}
|
|
2874
|
+
const key = resourceLookupKey(type, name);
|
|
2875
|
+
if (!lookup.has(key)) {
|
|
2876
|
+
lookup.set(key, []);
|
|
2877
|
+
}
|
|
2878
|
+
lookup.get(key).push(child);
|
|
2879
|
+
}
|
|
2880
|
+
return lookup;
|
|
2881
|
+
}
|
|
2882
|
+
function cloneResourceNodeFromLookup(resource, lookup) {
|
|
2883
|
+
const node = takeResourceNode(lookup, resource.type, resource.name);
|
|
2884
|
+
if (!node) {
|
|
2885
|
+
return cloneResourceNode(resource);
|
|
2886
|
+
}
|
|
2887
|
+
switch (resource.type) {
|
|
2888
|
+
case "string": {
|
|
2889
|
+
return {
|
|
2890
|
+
type: "string",
|
|
2891
|
+
name: resource.name,
|
|
2892
|
+
translatable: resource.translatable,
|
|
2893
|
+
node,
|
|
2894
|
+
meta: cloneTextMeta(resource.meta)
|
|
2895
|
+
};
|
|
2896
|
+
}
|
|
2897
|
+
case "string-array": {
|
|
2898
|
+
const childItems = (Array.isArray(node.$$) ? node.$$ : []).filter(
|
|
2899
|
+
(child) => _optionalChain([child, 'optionalAccess', _131 => _131["#name"]]) === "item"
|
|
2900
|
+
);
|
|
2901
|
+
node.item = childItems;
|
|
2902
|
+
if (childItems.length < resource.items.length) {
|
|
2903
|
+
return cloneResourceNode(resource);
|
|
2904
|
+
}
|
|
2905
|
+
const items = resource.items.map((item, index) => {
|
|
2906
|
+
const nodeItem = childItems[index];
|
|
2907
|
+
if (!nodeItem) {
|
|
2908
|
+
return {
|
|
2909
|
+
node: deepClone(item.node),
|
|
2910
|
+
meta: cloneTextMeta(item.meta)
|
|
2911
|
+
};
|
|
2310
2912
|
}
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2913
|
+
return {
|
|
2914
|
+
node: nodeItem,
|
|
2915
|
+
meta: cloneTextMeta(item.meta)
|
|
2916
|
+
};
|
|
2917
|
+
});
|
|
2918
|
+
return {
|
|
2919
|
+
type: "string-array",
|
|
2920
|
+
name: resource.name,
|
|
2921
|
+
translatable: resource.translatable,
|
|
2922
|
+
node,
|
|
2923
|
+
items
|
|
2924
|
+
};
|
|
2925
|
+
}
|
|
2926
|
+
case "plurals": {
|
|
2927
|
+
const childItems = (Array.isArray(node.$$) ? node.$$ : []).filter(
|
|
2928
|
+
(child) => _optionalChain([child, 'optionalAccess', _132 => _132["#name"]]) === "item"
|
|
2929
|
+
);
|
|
2930
|
+
node.item = childItems;
|
|
2931
|
+
const itemMap = /* @__PURE__ */ new Map();
|
|
2932
|
+
for (const item of childItems) {
|
|
2933
|
+
if (_optionalChain([item, 'optionalAccess', _133 => _133.$, 'optionalAccess', _134 => _134.quantity])) {
|
|
2934
|
+
itemMap.set(item.$.quantity, item);
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
const items = [];
|
|
2938
|
+
for (const templateItem of resource.items) {
|
|
2939
|
+
const nodeItem = itemMap.get(templateItem.quantity);
|
|
2940
|
+
if (!nodeItem) {
|
|
2941
|
+
return cloneResourceNode(resource);
|
|
2942
|
+
}
|
|
2943
|
+
items.push({
|
|
2944
|
+
node: nodeItem,
|
|
2945
|
+
quantity: templateItem.quantity,
|
|
2946
|
+
meta: cloneTextMeta(templateItem.meta)
|
|
2947
|
+
});
|
|
2948
|
+
}
|
|
2949
|
+
return {
|
|
2950
|
+
type: "plurals",
|
|
2951
|
+
name: resource.name,
|
|
2952
|
+
translatable: resource.translatable,
|
|
2953
|
+
node,
|
|
2954
|
+
items
|
|
2955
|
+
};
|
|
2956
|
+
}
|
|
2957
|
+
case "bool": {
|
|
2958
|
+
return {
|
|
2959
|
+
type: "bool",
|
|
2960
|
+
name: resource.name,
|
|
2961
|
+
translatable: resource.translatable,
|
|
2962
|
+
node,
|
|
2963
|
+
meta: cloneTextMeta(resource.meta)
|
|
2964
|
+
};
|
|
2965
|
+
}
|
|
2966
|
+
case "integer": {
|
|
2967
|
+
return {
|
|
2968
|
+
type: "integer",
|
|
2969
|
+
name: resource.name,
|
|
2970
|
+
translatable: resource.translatable,
|
|
2971
|
+
node,
|
|
2972
|
+
meta: cloneTextMeta(resource.meta)
|
|
2973
|
+
};
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
function takeResourceNode(lookup, type, name) {
|
|
2978
|
+
const key = resourceLookupKey(type, name);
|
|
2979
|
+
const list = lookup.get(key);
|
|
2980
|
+
if (!list || list.length === 0) {
|
|
2981
|
+
return void 0;
|
|
2982
|
+
}
|
|
2983
|
+
return list.shift();
|
|
2984
|
+
}
|
|
2985
|
+
function resourceLookupKey(type, name) {
|
|
2986
|
+
return `${type}:${name}`;
|
|
2987
|
+
}
|
|
2988
|
+
function extractValueFromResource(resource) {
|
|
2989
|
+
switch (resource.type) {
|
|
2990
|
+
case "string":
|
|
2991
|
+
return decodeAndroidText(segmentsToString(resource.meta.segments));
|
|
2992
|
+
case "string-array":
|
|
2993
|
+
return resource.items.map(
|
|
2994
|
+
(item) => decodeAndroidText(segmentsToString(item.meta.segments))
|
|
2995
|
+
);
|
|
2996
|
+
case "plurals": {
|
|
2997
|
+
const result = {};
|
|
2998
|
+
for (const item of resource.items) {
|
|
2999
|
+
result[item.quantity] = decodeAndroidText(
|
|
3000
|
+
segmentsToString(item.meta.segments)
|
|
3001
|
+
);
|
|
3002
|
+
}
|
|
3003
|
+
return result;
|
|
3004
|
+
}
|
|
3005
|
+
case "bool": {
|
|
3006
|
+
const value = segmentsToString(resource.meta.segments).trim();
|
|
3007
|
+
return value === "true";
|
|
3008
|
+
}
|
|
3009
|
+
case "integer": {
|
|
3010
|
+
const value = parseInt(
|
|
3011
|
+
segmentsToString(resource.meta.segments).trim(),
|
|
3012
|
+
10
|
|
3013
|
+
);
|
|
3014
|
+
return Number.isNaN(value) ? 0 : value;
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
function inferTypeFromValue(value) {
|
|
3019
|
+
if (typeof value === "string") {
|
|
3020
|
+
return "string";
|
|
3021
|
+
}
|
|
3022
|
+
if (Array.isArray(value)) {
|
|
3023
|
+
return "string-array";
|
|
3024
|
+
}
|
|
3025
|
+
if (value && typeof value === "object") {
|
|
3026
|
+
return "plurals";
|
|
3027
|
+
}
|
|
3028
|
+
if (typeof value === "boolean") {
|
|
3029
|
+
return "bool";
|
|
3030
|
+
}
|
|
3031
|
+
if (typeof value === "number" && Number.isInteger(value)) {
|
|
3032
|
+
return "integer";
|
|
3033
|
+
}
|
|
3034
|
+
throw new CLIError({
|
|
3035
|
+
message: "Unable to infer Android resource type from payload",
|
|
3036
|
+
docUrl: "androidResouceError"
|
|
3037
|
+
});
|
|
3038
|
+
}
|
|
3039
|
+
function extractResourceMetadata(xml) {
|
|
3040
|
+
const parser = sax.parser(true, {
|
|
3041
|
+
trim: false,
|
|
3042
|
+
normalize: false,
|
|
3043
|
+
lowercase: false
|
|
3044
|
+
});
|
|
3045
|
+
const stack = [];
|
|
3046
|
+
const result = [];
|
|
3047
|
+
parser.onopentag = (node) => {
|
|
3048
|
+
const lowerName = node.name.toLowerCase();
|
|
3049
|
+
const attributes = {};
|
|
3050
|
+
for (const [key, value] of Object.entries(_nullishCoalesce(node.attributes, () => ( {})))) {
|
|
3051
|
+
attributes[key.toLowerCase()] = String(value);
|
|
3052
|
+
}
|
|
3053
|
+
stack.push({
|
|
3054
|
+
name: lowerName,
|
|
3055
|
+
rawName: node.name,
|
|
3056
|
+
attributes,
|
|
3057
|
+
segments: [],
|
|
3058
|
+
items: []
|
|
3059
|
+
});
|
|
3060
|
+
if (lowerName !== "resources" && lowerName !== "item" && !isResourceElementName(lowerName)) {
|
|
3061
|
+
const attrString = Object.entries(_nullishCoalesce(node.attributes, () => ( {}))).map(
|
|
3062
|
+
([key, value]) => ` ${key}="${escapeAttributeValue(String(value))}"`
|
|
3063
|
+
).join("");
|
|
3064
|
+
appendSegmentToNearestResource(stack, {
|
|
3065
|
+
kind: "text",
|
|
3066
|
+
value: `<${node.name}${attrString}>`
|
|
3067
|
+
});
|
|
3068
|
+
}
|
|
3069
|
+
};
|
|
3070
|
+
parser.ontext = (text) => {
|
|
3071
|
+
if (!text) {
|
|
3072
|
+
return;
|
|
3073
|
+
}
|
|
3074
|
+
appendSegmentToNearestResource(stack, { kind: "text", value: text });
|
|
3075
|
+
};
|
|
3076
|
+
parser.oncdata = (cdata) => {
|
|
3077
|
+
appendSegmentToNearestResource(stack, { kind: "cdata", value: cdata });
|
|
3078
|
+
};
|
|
3079
|
+
parser.onclosetag = () => {
|
|
3080
|
+
const entry = stack.pop();
|
|
3081
|
+
if (!entry) {
|
|
3082
|
+
return;
|
|
3083
|
+
}
|
|
3084
|
+
const parent = stack[stack.length - 1];
|
|
3085
|
+
if (entry.name === "item" && parent) {
|
|
3086
|
+
const meta = makeTextMeta(entry.segments);
|
|
3087
|
+
parent.items.push({
|
|
3088
|
+
quantity: entry.attributes.quantity,
|
|
3089
|
+
meta
|
|
3090
|
+
});
|
|
3091
|
+
return;
|
|
3092
|
+
}
|
|
3093
|
+
if (entry.name !== "resources" && entry.name !== "item" && !isResourceElementName(entry.name)) {
|
|
3094
|
+
appendSegmentToNearestResource(stack, {
|
|
3095
|
+
kind: "text",
|
|
3096
|
+
value: `</${entry.rawName}>`
|
|
3097
|
+
});
|
|
3098
|
+
return;
|
|
3099
|
+
}
|
|
3100
|
+
if (!isResourceElementName(entry.name)) {
|
|
3101
|
+
return;
|
|
3102
|
+
}
|
|
3103
|
+
const name = entry.attributes.name;
|
|
3104
|
+
if (!name) {
|
|
3105
|
+
return;
|
|
3106
|
+
}
|
|
3107
|
+
const translatable = (_nullishCoalesce(entry.attributes.translatable, () => ( ""))).toLowerCase() !== "false";
|
|
3108
|
+
switch (entry.name) {
|
|
3109
|
+
case "string": {
|
|
3110
|
+
result.push({
|
|
3111
|
+
type: "string",
|
|
3112
|
+
name,
|
|
3113
|
+
translatable,
|
|
3114
|
+
meta: makeTextMeta(entry.segments)
|
|
3115
|
+
});
|
|
3116
|
+
break;
|
|
3117
|
+
}
|
|
3118
|
+
case "string-array": {
|
|
3119
|
+
result.push({
|
|
3120
|
+
type: "string-array",
|
|
3121
|
+
name,
|
|
3122
|
+
translatable,
|
|
3123
|
+
items: entry.items.map((item) => ({
|
|
3124
|
+
meta: cloneTextMeta(item.meta)
|
|
3125
|
+
}))
|
|
3126
|
+
});
|
|
3127
|
+
break;
|
|
3128
|
+
}
|
|
3129
|
+
case "plurals": {
|
|
3130
|
+
const items = [];
|
|
3131
|
+
for (const item of entry.items) {
|
|
3132
|
+
if (!item.quantity) {
|
|
3133
|
+
continue;
|
|
2317
3134
|
}
|
|
3135
|
+
items.push({
|
|
3136
|
+
quantity: item.quantity,
|
|
3137
|
+
meta: cloneTextMeta(item.meta)
|
|
3138
|
+
});
|
|
3139
|
+
}
|
|
3140
|
+
result.push({
|
|
3141
|
+
type: "plurals",
|
|
3142
|
+
name,
|
|
3143
|
+
translatable,
|
|
3144
|
+
items
|
|
2318
3145
|
});
|
|
2319
|
-
|
|
2320
|
-
}
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
3146
|
+
break;
|
|
3147
|
+
}
|
|
3148
|
+
case "bool": {
|
|
3149
|
+
result.push({
|
|
3150
|
+
type: "bool",
|
|
3151
|
+
name,
|
|
3152
|
+
translatable,
|
|
3153
|
+
meta: makeTextMeta(entry.segments)
|
|
2325
3154
|
});
|
|
3155
|
+
break;
|
|
3156
|
+
}
|
|
3157
|
+
case "integer": {
|
|
3158
|
+
result.push({
|
|
3159
|
+
type: "integer",
|
|
3160
|
+
name,
|
|
3161
|
+
translatable,
|
|
3162
|
+
meta: makeTextMeta(entry.segments)
|
|
3163
|
+
});
|
|
3164
|
+
break;
|
|
2326
3165
|
}
|
|
2327
3166
|
}
|
|
2328
|
-
}
|
|
3167
|
+
};
|
|
3168
|
+
parser.write(xml).close();
|
|
3169
|
+
return result;
|
|
3170
|
+
}
|
|
3171
|
+
function appendSegmentToNearestResource(stack, segment) {
|
|
3172
|
+
for (let index = stack.length - 1; index >= 0; index--) {
|
|
3173
|
+
const entry = stack[index];
|
|
3174
|
+
if (entry.name === "string" || entry.name === "item" || entry.name === "bool" || entry.name === "integer") {
|
|
3175
|
+
entry.segments.push(segment);
|
|
3176
|
+
return;
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
function isResourceElementName(value) {
|
|
3181
|
+
return value === "string" || value === "string-array" || value === "plurals" || value === "bool" || value === "integer";
|
|
3182
|
+
}
|
|
3183
|
+
function deepClone(value) {
|
|
3184
|
+
return value === void 0 ? value : JSON.parse(JSON.stringify(value));
|
|
3185
|
+
}
|
|
3186
|
+
function serializeElement(node) {
|
|
3187
|
+
if (!node) {
|
|
3188
|
+
return "";
|
|
3189
|
+
}
|
|
3190
|
+
const name = _nullishCoalesce(node["#name"], () => ( "resources"));
|
|
3191
|
+
if (name === "__text__") {
|
|
3192
|
+
return _nullishCoalesce(node._, () => ( ""));
|
|
3193
|
+
}
|
|
3194
|
+
if (name === "__cdata") {
|
|
3195
|
+
return `<![CDATA[${_nullishCoalesce(node._, () => ( ""))}]]>`;
|
|
3196
|
+
}
|
|
3197
|
+
if (name === "__comment__") {
|
|
3198
|
+
return `<!--${_nullishCoalesce(node._, () => ( ""))}-->`;
|
|
3199
|
+
}
|
|
3200
|
+
const attributes = _nullishCoalesce(node.$, () => ( {}));
|
|
3201
|
+
const attrString = Object.entries(attributes).map(([key, value]) => ` ${key}="${escapeAttributeValue(String(value))}"`).join("");
|
|
3202
|
+
const children = Array.isArray(node.$$) ? node.$$ : [];
|
|
3203
|
+
if (children.length === 0) {
|
|
3204
|
+
const textContent = _nullishCoalesce(node._, () => ( ""));
|
|
3205
|
+
return `<${name}${attrString}>${textContent}</${name}>`;
|
|
3206
|
+
}
|
|
3207
|
+
const childContent = children.map(serializeElement).join("");
|
|
3208
|
+
return `<${name}${attrString}>${childContent}</${name}>`;
|
|
3209
|
+
}
|
|
3210
|
+
function escapeAttributeValue(value) {
|
|
3211
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'");
|
|
3212
|
+
}
|
|
3213
|
+
function decodeAndroidText(value) {
|
|
3214
|
+
return value.replace(/\\'/g, "'");
|
|
2329
3215
|
}
|
|
2330
3216
|
|
|
2331
3217
|
// src/cli/loaders/csv.ts
|
|
@@ -2334,7 +3220,7 @@ var _sync3 = require('csv-stringify/sync');
|
|
|
2334
3220
|
|
|
2335
3221
|
function detectKeyColumnName(csvString) {
|
|
2336
3222
|
const row = _sync.parse.call(void 0, csvString)[0];
|
|
2337
|
-
const firstColumn = _optionalChain([row, 'optionalAccess',
|
|
3223
|
+
const firstColumn = _optionalChain([row, 'optionalAccess', _135 => _135[0], 'optionalAccess', _136 => _136.trim, 'call', _137 => _137()]);
|
|
2338
3224
|
return firstColumn || "KEY";
|
|
2339
3225
|
}
|
|
2340
3226
|
function createCsvLoader() {
|
|
@@ -2436,7 +3322,7 @@ function createHtmlLoader() {
|
|
|
2436
3322
|
break;
|
|
2437
3323
|
}
|
|
2438
3324
|
const siblings = Array.from(parent.childNodes).filter(
|
|
2439
|
-
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
3325
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _138 => _138.textContent, 'optionalAccess', _139 => _139.trim, 'call', _140 => _140()])
|
|
2440
3326
|
);
|
|
2441
3327
|
const index = siblings.indexOf(current);
|
|
2442
3328
|
if (index !== -1) {
|
|
@@ -2472,15 +3358,15 @@ function createHtmlLoader() {
|
|
|
2472
3358
|
}
|
|
2473
3359
|
});
|
|
2474
3360
|
Array.from(element.childNodes).filter(
|
|
2475
|
-
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
3361
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _141 => _141.textContent, 'optionalAccess', _142 => _142.trim, 'call', _143 => _143()])
|
|
2476
3362
|
).forEach(processNode);
|
|
2477
3363
|
}
|
|
2478
3364
|
};
|
|
2479
3365
|
Array.from(document.head.childNodes).filter(
|
|
2480
|
-
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
3366
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _144 => _144.textContent, 'optionalAccess', _145 => _145.trim, 'call', _146 => _146()])
|
|
2481
3367
|
).forEach(processNode);
|
|
2482
3368
|
Array.from(document.body.childNodes).filter(
|
|
2483
|
-
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
3369
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _147 => _147.textContent, 'optionalAccess', _148 => _148.trim, 'call', _149 => _149()])
|
|
2484
3370
|
).forEach(processNode);
|
|
2485
3371
|
return result;
|
|
2486
3372
|
},
|
|
@@ -2505,7 +3391,7 @@ function createHtmlLoader() {
|
|
|
2505
3391
|
for (let i = 0; i < indices.length; i++) {
|
|
2506
3392
|
const index = parseInt(indices[i]);
|
|
2507
3393
|
const siblings = Array.from(parent.childNodes).filter(
|
|
2508
|
-
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
3394
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _150 => _150.textContent, 'optionalAccess', _151 => _151.trim, 'call', _152 => _152()])
|
|
2509
3395
|
);
|
|
2510
3396
|
if (index >= siblings.length) {
|
|
2511
3397
|
if (i === indices.length - 1) {
|
|
@@ -2556,7 +3442,7 @@ function createMarkdownLoader() {
|
|
|
2556
3442
|
yaml: yamlEngine
|
|
2557
3443
|
}
|
|
2558
3444
|
});
|
|
2559
|
-
const sections = content.split(SECTION_REGEX).map((section) => _nullishCoalesce(_optionalChain([section, 'optionalAccess',
|
|
3445
|
+
const sections = content.split(SECTION_REGEX).map((section) => _nullishCoalesce(_optionalChain([section, 'optionalAccess', _153 => _153.trim, 'call', _154 => _154()]), () => ( ""))).filter(Boolean);
|
|
2560
3446
|
return {
|
|
2561
3447
|
...Object.fromEntries(
|
|
2562
3448
|
sections.map((section, index) => [`${MD_SECTION_PREFIX}${index}`, section]).filter(([, section]) => Boolean(section))
|
|
@@ -2575,7 +3461,7 @@ function createMarkdownLoader() {
|
|
|
2575
3461
|
);
|
|
2576
3462
|
let content = Object.entries(data).filter(([key]) => key.startsWith(MD_SECTION_PREFIX)).sort(
|
|
2577
3463
|
([a], [b]) => Number(a.split("-").pop()) - Number(b.split("-").pop())
|
|
2578
|
-
).map(([, value]) => _nullishCoalesce(_optionalChain([value, 'optionalAccess',
|
|
3464
|
+
).map(([, value]) => _nullishCoalesce(_optionalChain([value, 'optionalAccess', _155 => _155.trim, 'call', _156 => _156()]), () => ( ""))).filter(Boolean).join("\n\n");
|
|
2579
3465
|
if (Object.keys(frontmatter).length > 0) {
|
|
2580
3466
|
content = `
|
|
2581
3467
|
${content}`;
|
|
@@ -2600,7 +3486,7 @@ function createMarkdocLoader() {
|
|
|
2600
3486
|
const result = {};
|
|
2601
3487
|
const counters = {};
|
|
2602
3488
|
traverseAndExtract(ast, "", result, counters);
|
|
2603
|
-
if (_optionalChain([ast, 'access',
|
|
3489
|
+
if (_optionalChain([ast, 'access', _157 => _157.attributes, 'optionalAccess', _158 => _158.frontmatter])) {
|
|
2604
3490
|
const frontmatter = _yaml2.default.parse(ast.attributes.frontmatter);
|
|
2605
3491
|
Object.entries(frontmatter).forEach(([key, value]) => {
|
|
2606
3492
|
if (typeof value === "string") {
|
|
@@ -2646,7 +3532,7 @@ function traverseAndExtract(node, path19, result, counters, parentType) {
|
|
|
2646
3532
|
if (nodeSemanticType && !["text", "strong", "em", "inline", "link"].includes(nodeSemanticType)) {
|
|
2647
3533
|
semanticType = nodeSemanticType;
|
|
2648
3534
|
}
|
|
2649
|
-
if (node.type === "text" && _optionalChain([node, 'access',
|
|
3535
|
+
if (node.type === "text" && _optionalChain([node, 'access', _159 => _159.attributes, 'optionalAccess', _160 => _160.content])) {
|
|
2650
3536
|
const content = node.attributes.content;
|
|
2651
3537
|
if (typeof content === "string" && content.trim()) {
|
|
2652
3538
|
if (semanticType) {
|
|
@@ -2673,7 +3559,7 @@ function buildPathMap(node, path19, counters, pathMap, parentType) {
|
|
|
2673
3559
|
if (nodeSemanticType && !["text", "strong", "em", "inline", "link"].includes(nodeSemanticType)) {
|
|
2674
3560
|
semanticType = nodeSemanticType;
|
|
2675
3561
|
}
|
|
2676
|
-
if (node.type === "text" && _optionalChain([node, 'access',
|
|
3562
|
+
if (node.type === "text" && _optionalChain([node, 'access', _161 => _161.attributes, 'optionalAccess', _162 => _162.content])) {
|
|
2677
3563
|
const content = node.attributes.content;
|
|
2678
3564
|
if (typeof content === "string" && content.trim()) {
|
|
2679
3565
|
if (semanticType) {
|
|
@@ -2696,7 +3582,7 @@ function applyTranslations(node, path19, data, pathMap) {
|
|
|
2696
3582
|
if (!node || typeof node !== "object") {
|
|
2697
3583
|
return;
|
|
2698
3584
|
}
|
|
2699
|
-
if (node.type === "text" && _optionalChain([node, 'access',
|
|
3585
|
+
if (node.type === "text" && _optionalChain([node, 'access', _163 => _163.attributes, 'optionalAccess', _164 => _164.content])) {
|
|
2700
3586
|
const content = node.attributes.content;
|
|
2701
3587
|
if (typeof content === "string") {
|
|
2702
3588
|
const contentPath = path19 ? `${path19}/attributes/content` : "attributes/content";
|
|
@@ -2746,7 +3632,7 @@ function isSkippableLine(line) {
|
|
|
2746
3632
|
function parsePropertyLine(line) {
|
|
2747
3633
|
const [key, ...valueParts] = line.split("=");
|
|
2748
3634
|
return {
|
|
2749
|
-
key: _optionalChain([key, 'optionalAccess',
|
|
3635
|
+
key: _optionalChain([key, 'optionalAccess', _165 => _165.trim, 'call', _166 => _166()]) || "",
|
|
2750
3636
|
value: valueParts.join("=").trim()
|
|
2751
3637
|
};
|
|
2752
3638
|
}
|
|
@@ -2834,7 +3720,7 @@ function createXcodeXcstringsLoader(defaultLocale) {
|
|
|
2834
3720
|
if (rootTranslationEntity.shouldTranslate === false) {
|
|
2835
3721
|
continue;
|
|
2836
3722
|
}
|
|
2837
|
-
const langTranslationEntity = _optionalChain([rootTranslationEntity, 'optionalAccess',
|
|
3723
|
+
const langTranslationEntity = _optionalChain([rootTranslationEntity, 'optionalAccess', _167 => _167.localizations, 'optionalAccess', _168 => _168[locale]]);
|
|
2838
3724
|
if (langTranslationEntity) {
|
|
2839
3725
|
if ("stringUnit" in langTranslationEntity) {
|
|
2840
3726
|
resultData[translationKey] = langTranslationEntity.stringUnit.value;
|
|
@@ -2843,7 +3729,7 @@ function createXcodeXcstringsLoader(defaultLocale) {
|
|
|
2843
3729
|
resultData[translationKey] = {};
|
|
2844
3730
|
const pluralForms = langTranslationEntity.variations.plural;
|
|
2845
3731
|
for (const form in pluralForms) {
|
|
2846
|
-
if (_optionalChain([pluralForms, 'access',
|
|
3732
|
+
if (_optionalChain([pluralForms, 'access', _169 => _169[form], 'optionalAccess', _170 => _170.stringUnit, 'optionalAccess', _171 => _171.value])) {
|
|
2847
3733
|
resultData[translationKey][form] = pluralForms[form].stringUnit.value;
|
|
2848
3734
|
}
|
|
2849
3735
|
}
|
|
@@ -2869,7 +3755,7 @@ function createXcodeXcstringsLoader(defaultLocale) {
|
|
|
2869
3755
|
const hasDoNotTranslateFlag = originalInput && originalInput.strings && originalInput.strings[key] && originalInput.strings[key].shouldTranslate === false;
|
|
2870
3756
|
if (typeof value === "string") {
|
|
2871
3757
|
langDataToMerge.strings[key] = {
|
|
2872
|
-
extractionState: _optionalChain([originalInput, 'optionalAccess',
|
|
3758
|
+
extractionState: _optionalChain([originalInput, 'optionalAccess', _172 => _172.strings, 'optionalAccess', _173 => _173[key], 'optionalAccess', _174 => _174.extractionState]),
|
|
2873
3759
|
localizations: {
|
|
2874
3760
|
[locale]: {
|
|
2875
3761
|
stringUnit: {
|
|
@@ -2927,7 +3813,7 @@ function createXcodeXcstringsLoader(defaultLocale) {
|
|
|
2927
3813
|
for (const [locale, localization] of Object.entries(
|
|
2928
3814
|
entity.localizations
|
|
2929
3815
|
)) {
|
|
2930
|
-
if (_optionalChain([localization, 'access',
|
|
3816
|
+
if (_optionalChain([localization, 'access', _175 => _175.variations, 'optionalAccess', _176 => _176.plural])) {
|
|
2931
3817
|
const pluralForms = localization.variations.plural;
|
|
2932
3818
|
for (const form in pluralForms) {
|
|
2933
3819
|
const pluralKey = `${translationKey}/${form}`;
|
|
@@ -2947,7 +3833,7 @@ function _removeLocale(input2, locale) {
|
|
|
2947
3833
|
const { strings } = input2;
|
|
2948
3834
|
const newStrings = _lodash2.default.cloneDeep(strings);
|
|
2949
3835
|
for (const [key, value] of Object.entries(newStrings)) {
|
|
2950
|
-
if (_optionalChain([value, 'access',
|
|
3836
|
+
if (_optionalChain([value, 'access', _177 => _177.localizations, 'optionalAccess', _178 => _178[locale]])) {
|
|
2951
3837
|
delete value.localizations[locale];
|
|
2952
3838
|
}
|
|
2953
3839
|
}
|
|
@@ -3139,14 +4025,14 @@ function pluralWithMetaToXcstrings(data) {
|
|
|
3139
4025
|
if (element.type === "literal") {
|
|
3140
4026
|
text += element.value;
|
|
3141
4027
|
} else if (element.type === "pound") {
|
|
3142
|
-
const pluralVar = Object.entries(_optionalChain([data, 'access',
|
|
4028
|
+
const pluralVar = Object.entries(_optionalChain([data, 'access', _179 => _179._meta, 'optionalAccess', _180 => _180.variables]) || {}).find(
|
|
3143
4029
|
([_36, meta]) => meta.role === "plural"
|
|
3144
4030
|
);
|
|
3145
|
-
text += _optionalChain([pluralVar, 'optionalAccess',
|
|
4031
|
+
text += _optionalChain([pluralVar, 'optionalAccess', _181 => _181[1], 'access', _182 => _182.format]) || "%lld";
|
|
3146
4032
|
} else if (element.type === "argument") {
|
|
3147
4033
|
const varName = element.value;
|
|
3148
|
-
const varMeta = _optionalChain([data, 'access',
|
|
3149
|
-
text += _optionalChain([varMeta, 'optionalAccess',
|
|
4034
|
+
const varMeta = _optionalChain([data, 'access', _183 => _183._meta, 'optionalAccess', _184 => _184.variables, 'optionalAccess', _185 => _185[varName]]);
|
|
4035
|
+
text += _optionalChain([varMeta, 'optionalAccess', _186 => _186.format]) || "%@";
|
|
3150
4036
|
}
|
|
3151
4037
|
}
|
|
3152
4038
|
let xcstringsFormName = form;
|
|
@@ -3524,8 +4410,8 @@ async function formatDataWithBiome(data, filePath, options) {
|
|
|
3524
4410
|
});
|
|
3525
4411
|
return formatted.content;
|
|
3526
4412
|
} catch (error) {
|
|
3527
|
-
const errorMessage = error instanceof Error ? error.message || _optionalChain([error, 'access',
|
|
3528
|
-
if (_optionalChain([errorMessage, 'optionalAccess',
|
|
4413
|
+
const errorMessage = error instanceof Error ? error.message || _optionalChain([error, 'access', _187 => _187.stackTrace, 'optionalAccess', _188 => _188.toString, 'call', _189 => _189(), 'access', _190 => _190.split, 'call', _191 => _191("\n"), 'access', _192 => _192[0]]) : "";
|
|
4414
|
+
if (_optionalChain([errorMessage, 'optionalAccess', _193 => _193.includes, 'call', _194 => _194("does not exist in the workspace")])) {
|
|
3529
4415
|
} else {
|
|
3530
4416
|
console.log(`\u26A0\uFE0F Biome skipped ${path14.default.basename(filePath)}`);
|
|
3531
4417
|
if (errorMessage) {
|
|
@@ -3572,7 +4458,7 @@ function createPoDataLoader(params) {
|
|
|
3572
4458
|
Object.entries(entries).forEach(([msgid, entry]) => {
|
|
3573
4459
|
if (msgid && entry.msgid) {
|
|
3574
4460
|
const context = entry.msgctxt || "";
|
|
3575
|
-
const fullEntry = _optionalChain([parsedPo, 'access',
|
|
4461
|
+
const fullEntry = _optionalChain([parsedPo, 'access', _195 => _195.translations, 'access', _196 => _196[context], 'optionalAccess', _197 => _197[msgid]]);
|
|
3576
4462
|
if (fullEntry) {
|
|
3577
4463
|
result[msgid] = fullEntry;
|
|
3578
4464
|
}
|
|
@@ -3582,8 +4468,8 @@ function createPoDataLoader(params) {
|
|
|
3582
4468
|
return result;
|
|
3583
4469
|
},
|
|
3584
4470
|
async push(locale, data, originalInput, originalLocale, pullInput) {
|
|
3585
|
-
const currentSections = _optionalChain([pullInput, 'optionalAccess',
|
|
3586
|
-
const originalSections = _optionalChain([originalInput, 'optionalAccess',
|
|
4471
|
+
const currentSections = _optionalChain([pullInput, 'optionalAccess', _198 => _198.split, 'call', _199 => _199("\n\n"), 'access', _200 => _200.filter, 'call', _201 => _201(Boolean)]) || [];
|
|
4472
|
+
const originalSections = _optionalChain([originalInput, 'optionalAccess', _202 => _202.split, 'call', _203 => _203("\n\n"), 'access', _204 => _204.filter, 'call', _205 => _205(Boolean)]) || [];
|
|
3587
4473
|
const result = originalSections.map((section) => {
|
|
3588
4474
|
const sectionPo = _gettextparser2.default.po.parse(section);
|
|
3589
4475
|
if (Object.keys(sectionPo.translations).length === 0) {
|
|
@@ -3652,8 +4538,8 @@ function createPoContentLoader() {
|
|
|
3652
4538
|
{
|
|
3653
4539
|
...entry,
|
|
3654
4540
|
msgstr: [
|
|
3655
|
-
_optionalChain([data, 'access',
|
|
3656
|
-
_optionalChain([data, 'access',
|
|
4541
|
+
_optionalChain([data, 'access', _206 => _206[entry.msgid], 'optionalAccess', _207 => _207.singular]),
|
|
4542
|
+
_optionalChain([data, 'access', _208 => _208[entry.msgid], 'optionalAccess', _209 => _209.plural]) || null
|
|
3657
4543
|
].filter(Boolean)
|
|
3658
4544
|
}
|
|
3659
4545
|
]).fromPairs().value();
|
|
@@ -3775,7 +4661,7 @@ function pullV1(xliffElement, locale, originalLocale) {
|
|
|
3775
4661
|
let key = getTransUnitKey(unit);
|
|
3776
4662
|
if (!key) return;
|
|
3777
4663
|
if (seenKeys.has(key)) {
|
|
3778
|
-
const id = _optionalChain([unit, 'access',
|
|
4664
|
+
const id = _optionalChain([unit, 'access', _210 => _210.getAttribute, 'call', _211 => _211("id"), 'optionalAccess', _212 => _212.trim, 'call', _213 => _213()]);
|
|
3779
4665
|
if (id) {
|
|
3780
4666
|
key = `${key}#${id}`;
|
|
3781
4667
|
} else {
|
|
@@ -3823,7 +4709,7 @@ function pushV1(dom, xliffElement, locale, translations, originalLocale, origina
|
|
|
3823
4709
|
let key = getTransUnitKey(unit);
|
|
3824
4710
|
if (!key) return;
|
|
3825
4711
|
if (seenKeys.has(key)) {
|
|
3826
|
-
const id = _optionalChain([unit, 'access',
|
|
4712
|
+
const id = _optionalChain([unit, 'access', _214 => _214.getAttribute, 'call', _215 => _215("id"), 'optionalAccess', _216 => _216.trim, 'call', _217 => _217()]);
|
|
3827
4713
|
if (id) {
|
|
3828
4714
|
key = `${key}#${id}`;
|
|
3829
4715
|
} else {
|
|
@@ -3865,7 +4751,7 @@ function pushV1(dom, xliffElement, locale, translations, originalLocale, origina
|
|
|
3865
4751
|
const translationKeys = new Set(Object.keys(translations));
|
|
3866
4752
|
existingUnits.forEach((unit, key) => {
|
|
3867
4753
|
if (!translationKeys.has(key)) {
|
|
3868
|
-
_optionalChain([unit, 'access',
|
|
4754
|
+
_optionalChain([unit, 'access', _218 => _218.parentNode, 'optionalAccess', _219 => _219.removeChild, 'call', _220 => _220(unit)]);
|
|
3869
4755
|
}
|
|
3870
4756
|
});
|
|
3871
4757
|
return serializeWithDeclaration(
|
|
@@ -3908,18 +4794,18 @@ function traverseUnitsV2(container, fileId, currentPath, result) {
|
|
|
3908
4794
|
Array.from(container.children).forEach((child) => {
|
|
3909
4795
|
const tagName = child.tagName;
|
|
3910
4796
|
if (tagName === "unit") {
|
|
3911
|
-
const unitId = _optionalChain([child, 'access',
|
|
4797
|
+
const unitId = _optionalChain([child, 'access', _221 => _221.getAttribute, 'call', _222 => _222("id"), 'optionalAccess', _223 => _223.trim, 'call', _224 => _224()]);
|
|
3912
4798
|
if (!unitId) return;
|
|
3913
4799
|
const key = `resources/${fileId}/${currentPath}${unitId}/source`;
|
|
3914
4800
|
const segment = child.querySelector("segment");
|
|
3915
|
-
const source = _optionalChain([segment, 'optionalAccess',
|
|
4801
|
+
const source = _optionalChain([segment, 'optionalAccess', _225 => _225.querySelector, 'call', _226 => _226("source")]);
|
|
3916
4802
|
if (source) {
|
|
3917
4803
|
result[key] = extractTextContent(source);
|
|
3918
4804
|
} else {
|
|
3919
4805
|
result[key] = unitId;
|
|
3920
4806
|
}
|
|
3921
4807
|
} else if (tagName === "group") {
|
|
3922
|
-
const groupId = _optionalChain([child, 'access',
|
|
4808
|
+
const groupId = _optionalChain([child, 'access', _227 => _227.getAttribute, 'call', _228 => _228("id"), 'optionalAccess', _229 => _229.trim, 'call', _230 => _230()]);
|
|
3923
4809
|
const newPath = groupId ? `${currentPath}${groupId}/groupUnits/` : currentPath;
|
|
3924
4810
|
traverseUnitsV2(child, fileId, newPath, result);
|
|
3925
4811
|
}
|
|
@@ -3955,12 +4841,12 @@ function indexUnitsV2(container, fileId, currentPath, index) {
|
|
|
3955
4841
|
Array.from(container.children).forEach((child) => {
|
|
3956
4842
|
const tagName = child.tagName;
|
|
3957
4843
|
if (tagName === "unit") {
|
|
3958
|
-
const unitId = _optionalChain([child, 'access',
|
|
4844
|
+
const unitId = _optionalChain([child, 'access', _231 => _231.getAttribute, 'call', _232 => _232("id"), 'optionalAccess', _233 => _233.trim, 'call', _234 => _234()]);
|
|
3959
4845
|
if (!unitId) return;
|
|
3960
4846
|
const key = `resources/${fileId}/${currentPath}${unitId}/source`;
|
|
3961
4847
|
index.set(key, child);
|
|
3962
4848
|
} else if (tagName === "group") {
|
|
3963
|
-
const groupId = _optionalChain([child, 'access',
|
|
4849
|
+
const groupId = _optionalChain([child, 'access', _235 => _235.getAttribute, 'call', _236 => _236("id"), 'optionalAccess', _237 => _237.trim, 'call', _238 => _238()]);
|
|
3964
4850
|
const newPath = groupId ? `${currentPath}${groupId}/groupUnits/` : currentPath;
|
|
3965
4851
|
indexUnitsV2(child, fileId, newPath, index);
|
|
3966
4852
|
}
|
|
@@ -3981,9 +4867,9 @@ function updateUnitV2(unit, value) {
|
|
|
3981
4867
|
setTextContent(source, value);
|
|
3982
4868
|
}
|
|
3983
4869
|
function getTransUnitKey(transUnit) {
|
|
3984
|
-
const resname = _optionalChain([transUnit, 'access',
|
|
4870
|
+
const resname = _optionalChain([transUnit, 'access', _239 => _239.getAttribute, 'call', _240 => _240("resname"), 'optionalAccess', _241 => _241.trim, 'call', _242 => _242()]);
|
|
3985
4871
|
if (resname) return resname;
|
|
3986
|
-
const id = _optionalChain([transUnit, 'access',
|
|
4872
|
+
const id = _optionalChain([transUnit, 'access', _243 => _243.getAttribute, 'call', _244 => _244("id"), 'optionalAccess', _245 => _245.trim, 'call', _246 => _246()]);
|
|
3987
4873
|
if (id) return id;
|
|
3988
4874
|
const sourceElement = transUnit.querySelector("source");
|
|
3989
4875
|
if (sourceElement) {
|
|
@@ -4040,7 +4926,7 @@ function formatXml(xml) {
|
|
|
4040
4926
|
if (cdataNode) {
|
|
4041
4927
|
return `${indent2}${openTag}<![CDATA[${cdataNode.nodeValue}]]></${tagName}>`;
|
|
4042
4928
|
}
|
|
4043
|
-
const textContent = _optionalChain([element, 'access',
|
|
4929
|
+
const textContent = _optionalChain([element, 'access', _247 => _247.textContent, 'optionalAccess', _248 => _248.trim, 'call', _249 => _249()]) || "";
|
|
4044
4930
|
const hasOnlyText = element.childNodes.length === 1 && element.childNodes[0].nodeType === 3;
|
|
4045
4931
|
if (hasOnlyText && textContent) {
|
|
4046
4932
|
return `${indent2}${openTag}${textContent}</${tagName}>`;
|
|
@@ -4333,7 +5219,7 @@ function createDatoClient(params) {
|
|
|
4333
5219
|
ids: !records.length ? void 0 : records.join(",")
|
|
4334
5220
|
}
|
|
4335
5221
|
}).catch(
|
|
4336
|
-
(error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
5222
|
+
(error) => Promise.reject(_optionalChain([error, 'optionalAccess', _250 => _250.response, 'optionalAccess', _251 => _251.body, 'optionalAccess', _252 => _252.data, 'optionalAccess', _253 => _253[0]]) || error)
|
|
4337
5223
|
);
|
|
4338
5224
|
},
|
|
4339
5225
|
findRecordsForModel: async (modelId, records) => {
|
|
@@ -4344,10 +5230,10 @@ function createDatoClient(params) {
|
|
|
4344
5230
|
filter: {
|
|
4345
5231
|
type: modelId,
|
|
4346
5232
|
only_valid: "true",
|
|
4347
|
-
ids: !_optionalChain([records, 'optionalAccess',
|
|
5233
|
+
ids: !_optionalChain([records, 'optionalAccess', _254 => _254.length]) ? void 0 : records.join(",")
|
|
4348
5234
|
}
|
|
4349
5235
|
}).catch(
|
|
4350
|
-
(error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
5236
|
+
(error) => Promise.reject(_optionalChain([error, 'optionalAccess', _255 => _255.response, 'optionalAccess', _256 => _256.body, 'optionalAccess', _257 => _257.data, 'optionalAccess', _258 => _258[0]]) || error)
|
|
4351
5237
|
);
|
|
4352
5238
|
return result;
|
|
4353
5239
|
} catch (_error) {
|
|
@@ -4363,10 +5249,10 @@ function createDatoClient(params) {
|
|
|
4363
5249
|
updateRecord: async (id, payload) => {
|
|
4364
5250
|
try {
|
|
4365
5251
|
await dato.items.update(id, payload).catch(
|
|
4366
|
-
(error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
5252
|
+
(error) => Promise.reject(_optionalChain([error, 'optionalAccess', _259 => _259.response, 'optionalAccess', _260 => _260.body, 'optionalAccess', _261 => _261.data, 'optionalAccess', _262 => _262[0]]) || error)
|
|
4367
5253
|
);
|
|
4368
5254
|
} catch (_error) {
|
|
4369
|
-
if (_optionalChain([_error, 'optionalAccess',
|
|
5255
|
+
if (_optionalChain([_error, 'optionalAccess', _263 => _263.attributes, 'optionalAccess', _264 => _264.details, 'optionalAccess', _265 => _265.message])) {
|
|
4370
5256
|
throw new Error(
|
|
4371
5257
|
[
|
|
4372
5258
|
`${_error.attributes.details.message}`,
|
|
@@ -4388,10 +5274,10 @@ function createDatoClient(params) {
|
|
|
4388
5274
|
enableFieldLocalization: async (args) => {
|
|
4389
5275
|
try {
|
|
4390
5276
|
await dato.fields.update(`${args.modelId}::${args.fieldId}`, { localized: true }).catch(
|
|
4391
|
-
(error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
5277
|
+
(error) => Promise.reject(_optionalChain([error, 'optionalAccess', _266 => _266.response, 'optionalAccess', _267 => _267.body, 'optionalAccess', _268 => _268.data, 'optionalAccess', _269 => _269[0]]) || error)
|
|
4392
5278
|
);
|
|
4393
5279
|
} catch (_error) {
|
|
4394
|
-
if (_optionalChain([_error, 'optionalAccess',
|
|
5280
|
+
if (_optionalChain([_error, 'optionalAccess', _270 => _270.attributes, 'optionalAccess', _271 => _271.code]) === "NOT_FOUND") {
|
|
4395
5281
|
throw new Error(
|
|
4396
5282
|
[
|
|
4397
5283
|
`Field "${args.fieldId}" not found in model "${args.modelId}".`,
|
|
@@ -4399,7 +5285,7 @@ function createDatoClient(params) {
|
|
|
4399
5285
|
].join("\n\n")
|
|
4400
5286
|
);
|
|
4401
5287
|
}
|
|
4402
|
-
if (_optionalChain([_error, 'optionalAccess',
|
|
5288
|
+
if (_optionalChain([_error, 'optionalAccess', _272 => _272.attributes, 'optionalAccess', _273 => _273.details, 'optionalAccess', _274 => _274.message])) {
|
|
4403
5289
|
throw new Error(
|
|
4404
5290
|
[
|
|
4405
5291
|
`${_error.attributes.details.message}`,
|
|
@@ -4477,7 +5363,7 @@ function createDatoApiLoader(config, onConfigUpdate) {
|
|
|
4477
5363
|
const records = await dato.findRecordsForModel(modelId);
|
|
4478
5364
|
const recordChoices = createRecordChoices(
|
|
4479
5365
|
records,
|
|
4480
|
-
_optionalChain([config, 'access',
|
|
5366
|
+
_optionalChain([config, 'access', _275 => _275.models, 'access', _276 => _276[modelId], 'optionalAccess', _277 => _277.records]) || [],
|
|
4481
5367
|
project
|
|
4482
5368
|
);
|
|
4483
5369
|
const selectedRecords = await promptRecordSelection(
|
|
@@ -4496,14 +5382,14 @@ function createDatoApiLoader(config, onConfigUpdate) {
|
|
|
4496
5382
|
},
|
|
4497
5383
|
async pull(locale, input2, initCtx) {
|
|
4498
5384
|
const result = {};
|
|
4499
|
-
for (const modelId of _lodash2.default.keys(_optionalChain([initCtx, 'optionalAccess',
|
|
4500
|
-
let records = _optionalChain([initCtx, 'optionalAccess',
|
|
5385
|
+
for (const modelId of _lodash2.default.keys(_optionalChain([initCtx, 'optionalAccess', _278 => _278.models]) || {})) {
|
|
5386
|
+
let records = _optionalChain([initCtx, 'optionalAccess', _279 => _279.models, 'access', _280 => _280[modelId], 'access', _281 => _281.records]) || [];
|
|
4501
5387
|
const recordIds = records.map((record) => record.id);
|
|
4502
5388
|
records = await dato.findRecords(recordIds);
|
|
4503
5389
|
console.log(`Fetched ${records.length} records for model ${modelId}`);
|
|
4504
5390
|
if (records.length > 0) {
|
|
4505
5391
|
result[modelId] = {
|
|
4506
|
-
fields: _optionalChain([initCtx, 'optionalAccess',
|
|
5392
|
+
fields: _optionalChain([initCtx, 'optionalAccess', _282 => _282.models, 'optionalAccess', _283 => _283[modelId], 'optionalAccess', _284 => _284.fields]) || [],
|
|
4507
5393
|
records
|
|
4508
5394
|
};
|
|
4509
5395
|
}
|
|
@@ -4566,7 +5452,7 @@ function createRecordChoices(records, selectedIds = [], project) {
|
|
|
4566
5452
|
return records.map((record) => ({
|
|
4567
5453
|
name: `${record.id} - https://${project.internal_domain}/editor/item_types/${record.item_type.id}/items/${record.id}`,
|
|
4568
5454
|
value: record.id,
|
|
4569
|
-
checked: _optionalChain([selectedIds, 'optionalAccess',
|
|
5455
|
+
checked: _optionalChain([selectedIds, 'optionalAccess', _285 => _285.includes, 'call', _286 => _286(record.id)])
|
|
4570
5456
|
}));
|
|
4571
5457
|
}
|
|
4572
5458
|
async function promptRecordSelection(modelName, choices) {
|
|
@@ -4885,7 +5771,7 @@ function createVttLoader() {
|
|
|
4885
5771
|
if (!input2) {
|
|
4886
5772
|
return "";
|
|
4887
5773
|
}
|
|
4888
|
-
const vtt = _optionalChain([_nodewebvtt2.default, 'access',
|
|
5774
|
+
const vtt = _optionalChain([_nodewebvtt2.default, 'access', _287 => _287.parse, 'call', _288 => _288(input2), 'optionalAccess', _289 => _289.cues]);
|
|
4889
5775
|
if (Object.keys(vtt).length === 0) {
|
|
4890
5776
|
return {};
|
|
4891
5777
|
} else {
|
|
@@ -4948,7 +5834,7 @@ function variableExtractLoader(params) {
|
|
|
4948
5834
|
for (let i = 0; i < matches.length; i++) {
|
|
4949
5835
|
const match2 = matches[i];
|
|
4950
5836
|
const currentValue = result[key].value;
|
|
4951
|
-
const newValue = _optionalChain([currentValue, 'optionalAccess',
|
|
5837
|
+
const newValue = _optionalChain([currentValue, 'optionalAccess', _290 => _290.replace, 'call', _291 => _291(match2, `{variable:${i}}`)]);
|
|
4952
5838
|
result[key].value = newValue;
|
|
4953
5839
|
result[key].variables[i] = match2;
|
|
4954
5840
|
}
|
|
@@ -4961,7 +5847,7 @@ function variableExtractLoader(params) {
|
|
|
4961
5847
|
result[key] = valueObj.value;
|
|
4962
5848
|
const resultValue = result[key];
|
|
4963
5849
|
if (isICUPluralObject(resultValue)) {
|
|
4964
|
-
const originalValue = _optionalChain([originalInput, 'optionalAccess',
|
|
5850
|
+
const originalValue = _optionalChain([originalInput, 'optionalAccess', _292 => _292[key]]);
|
|
4965
5851
|
if (isICUPluralObject(originalValue) && originalValue._meta) {
|
|
4966
5852
|
resultValue._meta = originalValue._meta;
|
|
4967
5853
|
resultValue[Symbol.for("@lingo.dev/icu-plural-object")] = true;
|
|
@@ -4971,7 +5857,7 @@ function variableExtractLoader(params) {
|
|
|
4971
5857
|
const variable = valueObj.variables[i];
|
|
4972
5858
|
const currentValue = result[key];
|
|
4973
5859
|
if (typeof currentValue === "string") {
|
|
4974
|
-
const newValue = _optionalChain([currentValue, 'optionalAccess',
|
|
5860
|
+
const newValue = _optionalChain([currentValue, 'optionalAccess', _293 => _293.replace, 'call', _294 => _294(`{variable:${i}}`, variable)]);
|
|
4975
5861
|
result[key] = newValue;
|
|
4976
5862
|
}
|
|
4977
5863
|
}
|
|
@@ -5172,7 +6058,7 @@ function createVueJsonLoader() {
|
|
|
5172
6058
|
return createLoader({
|
|
5173
6059
|
pull: async (locale, input2, ctx) => {
|
|
5174
6060
|
const parsed = parseVueFile(input2);
|
|
5175
|
-
return _nullishCoalesce(_optionalChain([parsed, 'optionalAccess',
|
|
6061
|
+
return _nullishCoalesce(_optionalChain([parsed, 'optionalAccess', _295 => _295.i18n, 'optionalAccess', _296 => _296[locale]]), () => ( {}));
|
|
5176
6062
|
},
|
|
5177
6063
|
push: async (locale, data, originalInput) => {
|
|
5178
6064
|
const parsed = parseVueFile(_nullishCoalesce(originalInput, () => ( "")));
|
|
@@ -5357,7 +6243,7 @@ function updateStringsInObjectExpression(objectExpression, data) {
|
|
|
5357
6243
|
objectExpression.properties.forEach((prop) => {
|
|
5358
6244
|
if (!t.isObjectProperty(prop)) return;
|
|
5359
6245
|
const key = getPropertyKey(prop);
|
|
5360
|
-
const incomingVal = _optionalChain([data, 'optionalAccess',
|
|
6246
|
+
const incomingVal = _optionalChain([data, 'optionalAccess', _297 => _297[key]]);
|
|
5361
6247
|
if (incomingVal === void 0) {
|
|
5362
6248
|
return;
|
|
5363
6249
|
}
|
|
@@ -5393,7 +6279,7 @@ function updateStringsInArrayExpression(arrayExpression, incoming) {
|
|
|
5393
6279
|
let modified = false;
|
|
5394
6280
|
arrayExpression.elements.forEach((element, index) => {
|
|
5395
6281
|
if (!element) return;
|
|
5396
|
-
const incomingVal = _optionalChain([incoming, 'optionalAccess',
|
|
6282
|
+
const incomingVal = _optionalChain([incoming, 'optionalAccess', _298 => _298[index]]);
|
|
5397
6283
|
if (incomingVal === void 0) return;
|
|
5398
6284
|
if (t.isStringLiteral(element) && typeof incomingVal === "string") {
|
|
5399
6285
|
if (element.value !== incomingVal) {
|
|
@@ -5884,7 +6770,7 @@ var AST = class _AST {
|
|
|
5884
6770
|
const ret = this.type === null ? this.#parts.slice().map((p) => typeof p === "string" ? p : p.toJSON()) : [this.type, ...this.#parts.map((p) => p.toJSON())];
|
|
5885
6771
|
if (this.isStart() && !this.type)
|
|
5886
6772
|
ret.unshift([]);
|
|
5887
|
-
if (this.isEnd() && (this === this.#root || this.#root.#filledNegs && _optionalChain([this, 'access',
|
|
6773
|
+
if (this.isEnd() && (this === this.#root || this.#root.#filledNegs && _optionalChain([this, 'access', _299 => _299.#parent, 'optionalAccess', _300 => _300.type]) === "!")) {
|
|
5888
6774
|
ret.push({});
|
|
5889
6775
|
}
|
|
5890
6776
|
return ret;
|
|
@@ -5892,7 +6778,7 @@ var AST = class _AST {
|
|
|
5892
6778
|
isStart() {
|
|
5893
6779
|
if (this.#root === this)
|
|
5894
6780
|
return true;
|
|
5895
|
-
if (!_optionalChain([this, 'access',
|
|
6781
|
+
if (!_optionalChain([this, 'access', _301 => _301.#parent, 'optionalAccess', _302 => _302.isStart, 'call', _303 => _303()]))
|
|
5896
6782
|
return false;
|
|
5897
6783
|
if (this.#parentIndex === 0)
|
|
5898
6784
|
return true;
|
|
@@ -5908,12 +6794,12 @@ var AST = class _AST {
|
|
|
5908
6794
|
isEnd() {
|
|
5909
6795
|
if (this.#root === this)
|
|
5910
6796
|
return true;
|
|
5911
|
-
if (_optionalChain([this, 'access',
|
|
6797
|
+
if (_optionalChain([this, 'access', _304 => _304.#parent, 'optionalAccess', _305 => _305.type]) === "!")
|
|
5912
6798
|
return true;
|
|
5913
|
-
if (!_optionalChain([this, 'access',
|
|
6799
|
+
if (!_optionalChain([this, 'access', _306 => _306.#parent, 'optionalAccess', _307 => _307.isEnd, 'call', _308 => _308()]))
|
|
5914
6800
|
return false;
|
|
5915
6801
|
if (!this.type)
|
|
5916
|
-
return _optionalChain([this, 'access',
|
|
6802
|
+
return _optionalChain([this, 'access', _309 => _309.#parent, 'optionalAccess', _310 => _310.isEnd, 'call', _311 => _311()]);
|
|
5917
6803
|
const pl = this.#parent ? this.#parent.#parts.length : 0;
|
|
5918
6804
|
return this.#parentIndex === pl - 1;
|
|
5919
6805
|
}
|
|
@@ -6158,7 +7044,7 @@ var AST = class _AST {
|
|
|
6158
7044
|
}
|
|
6159
7045
|
}
|
|
6160
7046
|
let end = "";
|
|
6161
|
-
if (this.isEnd() && this.#root.#filledNegs && _optionalChain([this, 'access',
|
|
7047
|
+
if (this.isEnd() && this.#root.#filledNegs && _optionalChain([this, 'access', _312 => _312.#parent, 'optionalAccess', _313 => _313.type]) === "!") {
|
|
6162
7048
|
end = "(?:$|\\/)";
|
|
6163
7049
|
}
|
|
6164
7050
|
const final2 = start2 + src + end;
|
|
@@ -7248,7 +8134,7 @@ function createMdxSectionsSplit2Loader() {
|
|
|
7248
8134
|
const content = _lodash2.default.chain(data.sections).values().join("\n\n").value();
|
|
7249
8135
|
const result = {
|
|
7250
8136
|
frontmatter: data.frontmatter,
|
|
7251
|
-
codePlaceholders: _optionalChain([pullInput, 'optionalAccess',
|
|
8137
|
+
codePlaceholders: _optionalChain([pullInput, 'optionalAccess', _314 => _314.codePlaceholders]) || {},
|
|
7252
8138
|
content
|
|
7253
8139
|
};
|
|
7254
8140
|
return result;
|
|
@@ -8281,7 +9167,7 @@ function createBasicTranslator(model, systemPrompt, settings = {}) {
|
|
|
8281
9167
|
]
|
|
8282
9168
|
});
|
|
8283
9169
|
const result = JSON.parse(response.text);
|
|
8284
|
-
return _optionalChain([result, 'optionalAccess',
|
|
9170
|
+
return _optionalChain([result, 'optionalAccess', _315 => _315.data]) || {};
|
|
8285
9171
|
}
|
|
8286
9172
|
}
|
|
8287
9173
|
function extractPayloadChunks(payload) {
|
|
@@ -8364,7 +9250,7 @@ function getPureModelProvider(provider) {
|
|
|
8364
9250
|
|
|
8365
9251
|
${_chalk2.default.hex(colors.blue)("Docs: https://lingo.dev/go/docs")}
|
|
8366
9252
|
`;
|
|
8367
|
-
switch (_optionalChain([provider, 'optionalAccess',
|
|
9253
|
+
switch (_optionalChain([provider, 'optionalAccess', _316 => _316.id])) {
|
|
8368
9254
|
case "openai": {
|
|
8369
9255
|
if (!process.env.OPENAI_API_KEY) {
|
|
8370
9256
|
throw new Error(
|
|
@@ -8422,7 +9308,7 @@ function getPureModelProvider(provider) {
|
|
|
8422
9308
|
})(provider.model);
|
|
8423
9309
|
}
|
|
8424
9310
|
default: {
|
|
8425
|
-
throw new Error(createUnsupportedProviderErrorMessage(_optionalChain([provider, 'optionalAccess',
|
|
9311
|
+
throw new Error(createUnsupportedProviderErrorMessage(_optionalChain([provider, 'optionalAccess', _317 => _317.id])));
|
|
8426
9312
|
}
|
|
8427
9313
|
}
|
|
8428
9314
|
}
|
|
@@ -8707,7 +9593,7 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
8707
9593
|
validateParams(i18nConfig, flags);
|
|
8708
9594
|
ora.succeed("Localization configuration is valid");
|
|
8709
9595
|
ora.start("Connecting to Lingo.dev Localization Engine...");
|
|
8710
|
-
const isByokMode = !!_optionalChain([i18nConfig, 'optionalAccess',
|
|
9596
|
+
const isByokMode = !!_optionalChain([i18nConfig, 'optionalAccess', _318 => _318.provider]);
|
|
8711
9597
|
if (isByokMode) {
|
|
8712
9598
|
authId = null;
|
|
8713
9599
|
ora.succeed("Using external provider (BYOK mode)");
|
|
@@ -8721,16 +9607,16 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
8721
9607
|
flags
|
|
8722
9608
|
});
|
|
8723
9609
|
let buckets = getBuckets(i18nConfig);
|
|
8724
|
-
if (_optionalChain([flags, 'access',
|
|
9610
|
+
if (_optionalChain([flags, 'access', _319 => _319.bucket, 'optionalAccess', _320 => _320.length])) {
|
|
8725
9611
|
buckets = buckets.filter(
|
|
8726
9612
|
(bucket) => flags.bucket.includes(bucket.type)
|
|
8727
9613
|
);
|
|
8728
9614
|
}
|
|
8729
9615
|
ora.succeed("Buckets retrieved");
|
|
8730
|
-
if (_optionalChain([flags, 'access',
|
|
9616
|
+
if (_optionalChain([flags, 'access', _321 => _321.file, 'optionalAccess', _322 => _322.length])) {
|
|
8731
9617
|
buckets = buckets.map((bucket) => {
|
|
8732
9618
|
const paths = bucket.paths.filter(
|
|
8733
|
-
(path19) => flags.file.find((file) => _optionalChain([path19, 'access',
|
|
9619
|
+
(path19) => flags.file.find((file) => _optionalChain([path19, 'access', _323 => _323.pathPattern, 'optionalAccess', _324 => _324.includes, 'call', _325 => _325(file)]))
|
|
8734
9620
|
);
|
|
8735
9621
|
return { ...bucket, paths };
|
|
8736
9622
|
}).filter((bucket) => bucket.paths.length > 0);
|
|
@@ -8751,7 +9637,7 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
8751
9637
|
});
|
|
8752
9638
|
}
|
|
8753
9639
|
}
|
|
8754
|
-
const targetLocales = _optionalChain([flags, 'access',
|
|
9640
|
+
const targetLocales = _optionalChain([flags, 'access', _326 => _326.locale, 'optionalAccess', _327 => _327.length]) ? flags.locale : i18nConfig.locale.targets;
|
|
8755
9641
|
ora.start("Setting up localization cache...");
|
|
8756
9642
|
const checkLockfileProcessor = createDeltaProcessor("");
|
|
8757
9643
|
const lockfileExists = await checkLockfileProcessor.checkIfLockExists();
|
|
@@ -8989,7 +9875,16 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
8989
9875
|
`Applying changes to ${bucketPath} (${targetLocale})`
|
|
8990
9876
|
);
|
|
8991
9877
|
}
|
|
8992
|
-
const finalDiffSize = _lodash2.default.chain(finalTargetData).omitBy((value, key) =>
|
|
9878
|
+
const finalDiffSize = _lodash2.default.chain(finalTargetData).omitBy((value, key) => {
|
|
9879
|
+
const targetValue = targetData[key];
|
|
9880
|
+
if (isICUPluralObject(value) && isICUPluralObject(targetValue)) {
|
|
9881
|
+
return _lodash2.default.isEqual(
|
|
9882
|
+
{ icu: value.icu, _meta: value._meta },
|
|
9883
|
+
{ icu: targetValue.icu, _meta: targetValue._meta }
|
|
9884
|
+
);
|
|
9885
|
+
}
|
|
9886
|
+
return value === targetValue;
|
|
9887
|
+
}).size().value();
|
|
8993
9888
|
await bucketLoader.push(targetLocale, finalTargetData);
|
|
8994
9889
|
if (finalDiffSize > 0 || flags.force) {
|
|
8995
9890
|
bucketOra.succeed(
|
|
@@ -9028,7 +9923,7 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
9028
9923
|
}
|
|
9029
9924
|
const deltaProcessor = createDeltaProcessor(bucketPath.pathPattern);
|
|
9030
9925
|
const checksums = await deltaProcessor.createChecksums(sourceData);
|
|
9031
|
-
if (!_optionalChain([flags, 'access',
|
|
9926
|
+
if (!_optionalChain([flags, 'access', _328 => _328.locale, 'optionalAccess', _329 => _329.length])) {
|
|
9032
9927
|
await deltaProcessor.saveChecksums(checksums);
|
|
9033
9928
|
}
|
|
9034
9929
|
}
|
|
@@ -9152,12 +10047,12 @@ function validateParams(i18nConfig, flags) {
|
|
|
9152
10047
|
message: "No buckets found in i18n.json. Please add at least one bucket containing i18n content.",
|
|
9153
10048
|
docUrl: "bucketNotFound"
|
|
9154
10049
|
});
|
|
9155
|
-
} else if (_optionalChain([flags, 'access',
|
|
10050
|
+
} else if (_optionalChain([flags, 'access', _330 => _330.locale, 'optionalAccess', _331 => _331.some, 'call', _332 => _332((locale) => !i18nConfig.locale.targets.includes(locale))])) {
|
|
9156
10051
|
throw new ValidationError({
|
|
9157
10052
|
message: `One or more specified locales do not exist in i18n.json locale.targets. Please add them to the list and try again.`,
|
|
9158
10053
|
docUrl: "localeTargetNotFound"
|
|
9159
10054
|
});
|
|
9160
|
-
} else if (_optionalChain([flags, 'access',
|
|
10055
|
+
} else if (_optionalChain([flags, 'access', _333 => _333.bucket, 'optionalAccess', _334 => _334.some, 'call', _335 => _335(
|
|
9161
10056
|
(bucket) => !i18nConfig.buckets[bucket]
|
|
9162
10057
|
)])) {
|
|
9163
10058
|
throw new ValidationError({
|
|
@@ -9683,7 +10578,7 @@ function createLingoDotDevLocalizer(explicitApiKey) {
|
|
|
9683
10578
|
const response = await engine.whoami();
|
|
9684
10579
|
return {
|
|
9685
10580
|
authenticated: !!response,
|
|
9686
|
-
username: _optionalChain([response, 'optionalAccess',
|
|
10581
|
+
username: _optionalChain([response, 'optionalAccess', _336 => _336.email])
|
|
9687
10582
|
};
|
|
9688
10583
|
} catch (error) {
|
|
9689
10584
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -9799,7 +10694,7 @@ function createExplicitLocalizer(provider) {
|
|
|
9799
10694
|
}
|
|
9800
10695
|
function createAiSdkLocalizer(params) {
|
|
9801
10696
|
const skipAuth = params.skipAuth === true;
|
|
9802
|
-
const apiKey = process.env[_nullishCoalesce(_optionalChain([params, 'optionalAccess',
|
|
10697
|
+
const apiKey = process.env[_nullishCoalesce(_optionalChain([params, 'optionalAccess', _337 => _337.apiKeyName]), () => ( ""))];
|
|
9803
10698
|
if (!skipAuth && !apiKey || !params.apiKeyName) {
|
|
9804
10699
|
throw new Error(
|
|
9805
10700
|
_dedent2.default`
|
|
@@ -9933,8 +10828,8 @@ async function setup(input2) {
|
|
|
9933
10828
|
throw new Error(
|
|
9934
10829
|
"No buckets found in i18n.json. Please add at least one bucket containing i18n content."
|
|
9935
10830
|
);
|
|
9936
|
-
} else if (_optionalChain([ctx, 'access',
|
|
9937
|
-
(bucket) => !_optionalChain([ctx, 'access',
|
|
10831
|
+
} else if (_optionalChain([ctx, 'access', _338 => _338.flags, 'access', _339 => _339.bucket, 'optionalAccess', _340 => _340.some, 'call', _341 => _341(
|
|
10832
|
+
(bucket) => !_optionalChain([ctx, 'access', _342 => _342.config, 'optionalAccess', _343 => _343.buckets, 'access', _344 => _344[bucket]])
|
|
9938
10833
|
)])) {
|
|
9939
10834
|
throw new Error(
|
|
9940
10835
|
`One or more specified buckets do not exist in i18n.json. Please add them to the list first and try again.`
|
|
@@ -9947,7 +10842,7 @@ async function setup(input2) {
|
|
|
9947
10842
|
title: "Selecting localization provider",
|
|
9948
10843
|
task: async (ctx, task) => {
|
|
9949
10844
|
ctx.localizer = createLocalizer(
|
|
9950
|
-
_optionalChain([ctx, 'access',
|
|
10845
|
+
_optionalChain([ctx, 'access', _345 => _345.config, 'optionalAccess', _346 => _346.provider]),
|
|
9951
10846
|
ctx.flags.apiKey
|
|
9952
10847
|
);
|
|
9953
10848
|
if (!ctx.localizer) {
|
|
@@ -9960,7 +10855,7 @@ async function setup(input2) {
|
|
|
9960
10855
|
},
|
|
9961
10856
|
{
|
|
9962
10857
|
title: "Checking authentication",
|
|
9963
|
-
enabled: (ctx) => _optionalChain([ctx, 'access',
|
|
10858
|
+
enabled: (ctx) => _optionalChain([ctx, 'access', _347 => _347.localizer, 'optionalAccess', _348 => _348.id]) === "Lingo.dev",
|
|
9964
10859
|
task: async (ctx, task) => {
|
|
9965
10860
|
const authStatus = await ctx.localizer.checkAuth();
|
|
9966
10861
|
if (!authStatus.authenticated) {
|
|
@@ -9973,7 +10868,7 @@ async function setup(input2) {
|
|
|
9973
10868
|
},
|
|
9974
10869
|
{
|
|
9975
10870
|
title: "Validating configuration",
|
|
9976
|
-
enabled: (ctx) => _optionalChain([ctx, 'access',
|
|
10871
|
+
enabled: (ctx) => _optionalChain([ctx, 'access', _349 => _349.localizer, 'optionalAccess', _350 => _350.id]) !== "Lingo.dev",
|
|
9977
10872
|
task: async (ctx, task) => {
|
|
9978
10873
|
const validationStatus = await ctx.localizer.validateSettings();
|
|
9979
10874
|
if (!validationStatus.valid) {
|
|
@@ -10290,7 +11185,7 @@ function createWorkerTask(args) {
|
|
|
10290
11185
|
const processableData = _lodash2.default.chain(sourceData).entries().filter(
|
|
10291
11186
|
([key, value]) => delta.added.includes(key) || delta.updated.includes(key) || !!args.ctx.flags.force
|
|
10292
11187
|
).filter(
|
|
10293
|
-
([key]) => !assignedTask.onlyKeys.length || _optionalChain([assignedTask, 'access',
|
|
11188
|
+
([key]) => !assignedTask.onlyKeys.length || _optionalChain([assignedTask, 'access', _351 => _351.onlyKeys, 'optionalAccess', _352 => _352.some, 'call', _353 => _353(
|
|
10294
11189
|
(pattern) => minimatch(key, pattern)
|
|
10295
11190
|
)])
|
|
10296
11191
|
).fromPairs().value();
|
|
@@ -10358,7 +11253,7 @@ function createWorkerTask(args) {
|
|
|
10358
11253
|
finalRenamedTargetData
|
|
10359
11254
|
);
|
|
10360
11255
|
const checksums = await deltaProcessor.createChecksums(sourceData);
|
|
10361
|
-
if (!_optionalChain([args, 'access',
|
|
11256
|
+
if (!_optionalChain([args, 'access', _354 => _354.ctx, 'access', _355 => _355.flags, 'access', _356 => _356.targetLocale, 'optionalAccess', _357 => _357.length])) {
|
|
10362
11257
|
await deltaProcessor.saveChecksums(checksums);
|
|
10363
11258
|
}
|
|
10364
11259
|
});
|
|
@@ -10563,10 +11458,10 @@ var flagsSchema2 = _zod.z.object({
|
|
|
10563
11458
|
async function frozen(input2) {
|
|
10564
11459
|
console.log(_chalk2.default.hex(colors.orange)("[Frozen]"));
|
|
10565
11460
|
let buckets = getBuckets(input2.config);
|
|
10566
|
-
if (_optionalChain([input2, 'access',
|
|
11461
|
+
if (_optionalChain([input2, 'access', _358 => _358.flags, 'access', _359 => _359.bucket, 'optionalAccess', _360 => _360.length])) {
|
|
10567
11462
|
buckets = buckets.filter((b) => input2.flags.bucket.includes(b.type));
|
|
10568
11463
|
}
|
|
10569
|
-
if (_optionalChain([input2, 'access',
|
|
11464
|
+
if (_optionalChain([input2, 'access', _361 => _361.flags, 'access', _362 => _362.file, 'optionalAccess', _363 => _363.length])) {
|
|
10570
11465
|
buckets = buckets.map((bucket) => {
|
|
10571
11466
|
const paths = bucket.paths.filter(
|
|
10572
11467
|
(p) => input2.flags.file.some(
|
|
@@ -10703,13 +11598,13 @@ async function frozen(input2) {
|
|
|
10703
11598
|
|
|
10704
11599
|
// src/cli/cmd/run/_utils.ts
|
|
10705
11600
|
async function determineAuthId(ctx) {
|
|
10706
|
-
const isByokMode = !!_optionalChain([ctx, 'access',
|
|
11601
|
+
const isByokMode = !!_optionalChain([ctx, 'access', _364 => _364.config, 'optionalAccess', _365 => _365.provider]);
|
|
10707
11602
|
if (isByokMode) {
|
|
10708
11603
|
return null;
|
|
10709
11604
|
} else {
|
|
10710
11605
|
try {
|
|
10711
|
-
const authStatus = await _optionalChain([ctx, 'access',
|
|
10712
|
-
return _optionalChain([authStatus, 'optionalAccess',
|
|
11606
|
+
const authStatus = await _optionalChain([ctx, 'access', _366 => _366.localizer, 'optionalAccess', _367 => _367.checkAuth, 'call', _368 => _368()]);
|
|
11607
|
+
return _optionalChain([authStatus, 'optionalAccess', _369 => _369.username]) || null;
|
|
10713
11608
|
} catch (e3) {
|
|
10714
11609
|
return null;
|
|
10715
11610
|
}
|
|
@@ -10906,7 +11801,7 @@ var InBranchFlow = class extends IntegrationFlow {
|
|
|
10906
11801
|
_child_process.execSync.call(void 0, `git config --global safe.directory ${process.cwd()}`);
|
|
10907
11802
|
_child_process.execSync.call(void 0, `git config user.name "${gitConfig.userName}"`);
|
|
10908
11803
|
_child_process.execSync.call(void 0, `git config user.email "${gitConfig.userEmail}"`);
|
|
10909
|
-
_optionalChain([this, 'access',
|
|
11804
|
+
_optionalChain([this, 'access', _370 => _370.platformKit, 'optionalAccess', _371 => _371.gitConfig, 'call', _372 => _372()]);
|
|
10910
11805
|
_child_process.execSync.call(void 0, `git fetch origin ${baseBranchName}`, { stdio: "inherit" });
|
|
10911
11806
|
_child_process.execSync.call(void 0, `git checkout ${baseBranchName} --`, { stdio: "inherit" });
|
|
10912
11807
|
if (!processOwnCommits) {
|
|
@@ -10938,7 +11833,7 @@ var InBranchFlow = class extends IntegrationFlow {
|
|
|
10938
11833
|
// src/cli/cmd/ci/flows/pull-request.ts
|
|
10939
11834
|
var PullRequestFlow = class extends InBranchFlow {
|
|
10940
11835
|
async preRun() {
|
|
10941
|
-
const canContinue = await _optionalChain([super.preRun.bind(this), 'optionalCall',
|
|
11836
|
+
const canContinue = await _optionalChain([super.preRun.bind(this), 'optionalCall', _373 => _373()]);
|
|
10942
11837
|
if (!canContinue) {
|
|
10943
11838
|
return false;
|
|
10944
11839
|
}
|
|
@@ -11201,10 +12096,10 @@ var BitbucketPlatformKit = class extends PlatformKit {
|
|
|
11201
12096
|
repo_slug: this.platformConfig.repositoryName,
|
|
11202
12097
|
state: "OPEN"
|
|
11203
12098
|
}).then(({ data: { values } }) => {
|
|
11204
|
-
return _optionalChain([values, 'optionalAccess',
|
|
11205
|
-
({ source, destination }) => _optionalChain([source, 'optionalAccess',
|
|
12099
|
+
return _optionalChain([values, 'optionalAccess', _374 => _374.find, 'call', _375 => _375(
|
|
12100
|
+
({ source, destination }) => _optionalChain([source, 'optionalAccess', _376 => _376.branch, 'optionalAccess', _377 => _377.name]) === branch && _optionalChain([destination, 'optionalAccess', _378 => _378.branch, 'optionalAccess', _379 => _379.name]) === this.platformConfig.baseBranchName
|
|
11206
12101
|
)]);
|
|
11207
|
-
}).then((pr) => _optionalChain([pr, 'optionalAccess',
|
|
12102
|
+
}).then((pr) => _optionalChain([pr, 'optionalAccess', _380 => _380.id]));
|
|
11208
12103
|
}
|
|
11209
12104
|
async closePullRequest({ pullRequestNumber }) {
|
|
11210
12105
|
await this.bb.repositories.declinePullRequest({
|
|
@@ -11300,7 +12195,7 @@ var GitHubPlatformKit = class extends PlatformKit {
|
|
|
11300
12195
|
repo: this.platformConfig.repositoryName,
|
|
11301
12196
|
base: this.platformConfig.baseBranchName,
|
|
11302
12197
|
state: "open"
|
|
11303
|
-
}).then(({ data }) => data[0]).then((pr) => _optionalChain([pr, 'optionalAccess',
|
|
12198
|
+
}).then(({ data }) => data[0]).then((pr) => _optionalChain([pr, 'optionalAccess', _381 => _381.number]));
|
|
11304
12199
|
}
|
|
11305
12200
|
async closePullRequest({ pullRequestNumber }) {
|
|
11306
12201
|
await this.octokit.rest.pulls.update({
|
|
@@ -11427,7 +12322,7 @@ var GitlabPlatformKit = class extends PlatformKit {
|
|
|
11427
12322
|
sourceBranch: branch,
|
|
11428
12323
|
state: "opened"
|
|
11429
12324
|
});
|
|
11430
|
-
return _optionalChain([mergeRequests, 'access',
|
|
12325
|
+
return _optionalChain([mergeRequests, 'access', _382 => _382[0], 'optionalAccess', _383 => _383.iid]);
|
|
11431
12326
|
}
|
|
11432
12327
|
async closePullRequest({
|
|
11433
12328
|
pullRequestNumber
|
|
@@ -11533,7 +12428,7 @@ var ci_default = new (0, _interactivecommander.Command)().command("ci").descript
|
|
|
11533
12428
|
}
|
|
11534
12429
|
const env = {
|
|
11535
12430
|
LINGODOTDEV_API_KEY: settings.auth.apiKey,
|
|
11536
|
-
LINGODOTDEV_PULL_REQUEST: _optionalChain([options, 'access',
|
|
12431
|
+
LINGODOTDEV_PULL_REQUEST: _optionalChain([options, 'access', _384 => _384.pullRequest, 'optionalAccess', _385 => _385.toString, 'call', _386 => _386()]) || "false",
|
|
11537
12432
|
...options.commitMessage && {
|
|
11538
12433
|
LINGODOTDEV_COMMIT_MESSAGE: options.commitMessage
|
|
11539
12434
|
},
|
|
@@ -11553,7 +12448,7 @@ var ci_default = new (0, _interactivecommander.Command)().command("ci").descript
|
|
|
11553
12448
|
const { isPullRequestMode } = platformKit.config;
|
|
11554
12449
|
ora.info(`Pull request mode: ${isPullRequestMode ? "on" : "off"}`);
|
|
11555
12450
|
const flow = isPullRequestMode ? new PullRequestFlow(ora, platformKit) : new InBranchFlow(ora, platformKit);
|
|
11556
|
-
const canRun = await _optionalChain([flow, 'access',
|
|
12451
|
+
const canRun = await _optionalChain([flow, 'access', _387 => _387.preRun, 'optionalCall', _388 => _388()]);
|
|
11557
12452
|
if (canRun === false) {
|
|
11558
12453
|
return;
|
|
11559
12454
|
}
|
|
@@ -11563,7 +12458,7 @@ var ci_default = new (0, _interactivecommander.Command)().command("ci").descript
|
|
|
11563
12458
|
if (!hasChanges) {
|
|
11564
12459
|
return;
|
|
11565
12460
|
}
|
|
11566
|
-
await _optionalChain([flow, 'access',
|
|
12461
|
+
await _optionalChain([flow, 'access', _389 => _389.postRun, 'optionalCall', _390 => _390()]);
|
|
11567
12462
|
});
|
|
11568
12463
|
function parseBooleanArg(val) {
|
|
11569
12464
|
if (val === true) return true;
|
|
@@ -11600,8 +12495,8 @@ function exitGracefully(elapsedMs = 0) {
|
|
|
11600
12495
|
}
|
|
11601
12496
|
}
|
|
11602
12497
|
function checkForPendingOperations() {
|
|
11603
|
-
const activeHandles = _optionalChain([process, 'access',
|
|
11604
|
-
const activeRequests = _optionalChain([process, 'access',
|
|
12498
|
+
const activeHandles = _optionalChain([process, 'access', _391 => _391._getActiveHandles, 'optionalCall', _392 => _392()]) || [];
|
|
12499
|
+
const activeRequests = _optionalChain([process, 'access', _393 => _393._getActiveRequests, 'optionalCall', _394 => _394()]) || [];
|
|
11605
12500
|
const nonStandardHandles = activeHandles.filter((handle) => {
|
|
11606
12501
|
if (handle === process.stdin || handle === process.stdout || handle === process.stderr) {
|
|
11607
12502
|
return false;
|
|
@@ -11670,17 +12565,17 @@ var status_default = new (0, _interactivecommander.Command)().command("status").
|
|
|
11670
12565
|
flags
|
|
11671
12566
|
});
|
|
11672
12567
|
let buckets = getBuckets(i18nConfig);
|
|
11673
|
-
if (_optionalChain([flags, 'access',
|
|
12568
|
+
if (_optionalChain([flags, 'access', _395 => _395.bucket, 'optionalAccess', _396 => _396.length])) {
|
|
11674
12569
|
buckets = buckets.filter(
|
|
11675
12570
|
(bucket) => flags.bucket.includes(bucket.type)
|
|
11676
12571
|
);
|
|
11677
12572
|
}
|
|
11678
12573
|
ora.succeed("Buckets retrieved");
|
|
11679
|
-
if (_optionalChain([flags, 'access',
|
|
12574
|
+
if (_optionalChain([flags, 'access', _397 => _397.file, 'optionalAccess', _398 => _398.length])) {
|
|
11680
12575
|
buckets = buckets.map((bucket) => {
|
|
11681
12576
|
const paths = bucket.paths.filter(
|
|
11682
12577
|
(path19) => flags.file.find(
|
|
11683
|
-
(file) => _optionalChain([path19, 'access',
|
|
12578
|
+
(file) => _optionalChain([path19, 'access', _399 => _399.pathPattern, 'optionalAccess', _400 => _400.includes, 'call', _401 => _401(file)]) || _optionalChain([path19, 'access', _402 => _402.pathPattern, 'optionalAccess', _403 => _403.match, 'call', _404 => _404(file)]) || minimatch(path19.pathPattern, file)
|
|
11684
12579
|
)
|
|
11685
12580
|
);
|
|
11686
12581
|
return { ...bucket, paths };
|
|
@@ -11700,7 +12595,7 @@ var status_default = new (0, _interactivecommander.Command)().command("status").
|
|
|
11700
12595
|
});
|
|
11701
12596
|
}
|
|
11702
12597
|
}
|
|
11703
|
-
const targetLocales = _optionalChain([flags, 'access',
|
|
12598
|
+
const targetLocales = _optionalChain([flags, 'access', _405 => _405.locale, 'optionalAccess', _406 => _406.length]) ? flags.locale : i18nConfig.locale.targets;
|
|
11704
12599
|
let totalSourceKeyCount = 0;
|
|
11705
12600
|
let uniqueKeysToTranslate = 0;
|
|
11706
12601
|
let totalExistingTranslations = 0;
|
|
@@ -12106,12 +13001,12 @@ function validateParams2(i18nConfig, flags) {
|
|
|
12106
13001
|
message: "No buckets found in i18n.json. Please add at least one bucket containing i18n content.",
|
|
12107
13002
|
docUrl: "bucketNotFound"
|
|
12108
13003
|
});
|
|
12109
|
-
} else if (_optionalChain([flags, 'access',
|
|
13004
|
+
} else if (_optionalChain([flags, 'access', _407 => _407.locale, 'optionalAccess', _408 => _408.some, 'call', _409 => _409((locale) => !i18nConfig.locale.targets.includes(locale))])) {
|
|
12110
13005
|
throw new CLIError({
|
|
12111
13006
|
message: `One or more specified locales do not exist in i18n.json locale.targets. Please add them to the list and try again.`,
|
|
12112
13007
|
docUrl: "localeTargetNotFound"
|
|
12113
13008
|
});
|
|
12114
|
-
} else if (_optionalChain([flags, 'access',
|
|
13009
|
+
} else if (_optionalChain([flags, 'access', _410 => _410.bucket, 'optionalAccess', _411 => _411.some, 'call', _412 => _412(
|
|
12115
13010
|
(bucket) => !i18nConfig.buckets[bucket]
|
|
12116
13011
|
)])) {
|
|
12117
13012
|
throw new CLIError({
|
|
@@ -12203,7 +13098,7 @@ async function renderHero2() {
|
|
|
12203
13098
|
// package.json
|
|
12204
13099
|
var package_default = {
|
|
12205
13100
|
name: "lingo.dev",
|
|
12206
|
-
version: "0.113.
|
|
13101
|
+
version: "0.113.6",
|
|
12207
13102
|
description: "Lingo.dev CLI",
|
|
12208
13103
|
private: false,
|
|
12209
13104
|
publishConfig: {
|
|
@@ -12410,6 +13305,7 @@ var package_default = {
|
|
|
12410
13305
|
"remark-parse": "^11.0.0",
|
|
12411
13306
|
"remark-rehype": "^11.1.2",
|
|
12412
13307
|
"remark-stringify": "^11.0.0",
|
|
13308
|
+
sax: "^1.4.1",
|
|
12413
13309
|
"srt-parser-2": "^1.2.3",
|
|
12414
13310
|
unified: "^11.0.5",
|
|
12415
13311
|
"unist-util-visit": "^5.0.0",
|
|
@@ -12493,7 +13389,7 @@ var purge_default = new (0, _interactivecommander.Command)().command("purge").de
|
|
|
12493
13389
|
if (options.file && options.file.length) {
|
|
12494
13390
|
buckets = buckets.map((bucket) => {
|
|
12495
13391
|
const paths = bucket.paths.filter(
|
|
12496
|
-
(bucketPath) => _optionalChain([options, 'access',
|
|
13392
|
+
(bucketPath) => _optionalChain([options, 'access', _413 => _413.file, 'optionalAccess', _414 => _414.some, 'call', _415 => _415((f) => bucketPath.pathPattern.includes(f))])
|
|
12497
13393
|
);
|
|
12498
13394
|
return { ...bucket, paths };
|
|
12499
13395
|
}).filter((bucket) => bucket.paths.length > 0);
|