lingo.dev 0.117.4 → 0.117.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 +437 -240
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +332 -135
- package/build/cli.mjs.map +1 -1
- package/package.json +7 -3
package/build/cli.mjs
CHANGED
|
@@ -2728,16 +2728,9 @@ function appendResourceNode(document, resourceNode) {
|
|
|
2728
2728
|
function setTextualNodeContent(node, value, useCdata) {
|
|
2729
2729
|
const escapedValue = useCdata ? escapeApostrophesOnly(value) : escapeAndroidString(value);
|
|
2730
2730
|
node._ = escapedValue;
|
|
2731
|
-
node.$$ =
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
);
|
|
2735
|
-
if (!textNode) {
|
|
2736
|
-
textNode = {};
|
|
2737
|
-
node.$$.push(textNode);
|
|
2738
|
-
}
|
|
2739
|
-
textNode["#name"] = useCdata ? "__cdata" : "__text__";
|
|
2740
|
-
textNode._ = escapedValue;
|
|
2731
|
+
node.$$ = [
|
|
2732
|
+
{ "#name": useCdata ? "__cdata" : "__text__", _: escapedValue }
|
|
2733
|
+
];
|
|
2741
2734
|
}
|
|
2742
2735
|
function buildResourceNameMap(document) {
|
|
2743
2736
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -3410,8 +3403,8 @@ function serializeElement(node) {
|
|
|
3410
3403
|
const attrString = Object.entries(attributes).map(([key, value]) => ` ${key}="${escapeAttributeValue(String(value))}"`).join("");
|
|
3411
3404
|
const children = Array.isArray(node.$$) ? node.$$ : [];
|
|
3412
3405
|
if (children.length === 0) {
|
|
3413
|
-
const
|
|
3414
|
-
return `<${name}${attrString}>${
|
|
3406
|
+
const textContent2 = node._ ?? "";
|
|
3407
|
+
return `<${name}${attrString}>${textContent2}</${name}>`;
|
|
3415
3408
|
}
|
|
3416
3409
|
const childContent = children.map(serializeElement).join("");
|
|
3417
3410
|
return `<${name}${attrString}>${childContent}</${name}>`;
|
|
@@ -3500,135 +3493,335 @@ function createPullOutputCleaner() {
|
|
|
3500
3493
|
}
|
|
3501
3494
|
|
|
3502
3495
|
// src/cli/loaders/html.ts
|
|
3503
|
-
import
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
return trimmed;
|
|
3508
|
-
}
|
|
3496
|
+
import * as htmlparser2 from "htmlparser2";
|
|
3497
|
+
import { DomHandler } from "domhandler";
|
|
3498
|
+
import * as domutils from "domutils";
|
|
3499
|
+
import * as DomSerializer from "dom-serializer";
|
|
3509
3500
|
function createHtmlLoader() {
|
|
3501
|
+
const PHRASING_ELEMENTS = /* @__PURE__ */ new Set([
|
|
3502
|
+
// Text-level semantics
|
|
3503
|
+
"a",
|
|
3504
|
+
"abbr",
|
|
3505
|
+
"b",
|
|
3506
|
+
"bdi",
|
|
3507
|
+
"bdo",
|
|
3508
|
+
"br",
|
|
3509
|
+
"cite",
|
|
3510
|
+
"code",
|
|
3511
|
+
"data",
|
|
3512
|
+
"dfn",
|
|
3513
|
+
"em",
|
|
3514
|
+
"i",
|
|
3515
|
+
"kbd",
|
|
3516
|
+
"mark",
|
|
3517
|
+
"q",
|
|
3518
|
+
"ruby",
|
|
3519
|
+
"s",
|
|
3520
|
+
"samp",
|
|
3521
|
+
"small",
|
|
3522
|
+
"span",
|
|
3523
|
+
"strong",
|
|
3524
|
+
"sub",
|
|
3525
|
+
"sup",
|
|
3526
|
+
"time",
|
|
3527
|
+
"u",
|
|
3528
|
+
"var",
|
|
3529
|
+
"wbr",
|
|
3530
|
+
// Media
|
|
3531
|
+
"audio",
|
|
3532
|
+
"img",
|
|
3533
|
+
"video",
|
|
3534
|
+
"picture",
|
|
3535
|
+
// Interactive
|
|
3536
|
+
"button",
|
|
3537
|
+
"input",
|
|
3538
|
+
"label",
|
|
3539
|
+
"select",
|
|
3540
|
+
"textarea",
|
|
3541
|
+
// Embedded
|
|
3542
|
+
"canvas",
|
|
3543
|
+
"iframe",
|
|
3544
|
+
"object",
|
|
3545
|
+
"svg",
|
|
3546
|
+
"math",
|
|
3547
|
+
// Other
|
|
3548
|
+
"del",
|
|
3549
|
+
"ins",
|
|
3550
|
+
"map",
|
|
3551
|
+
"area"
|
|
3552
|
+
]);
|
|
3553
|
+
const BLOCK_ELEMENTS = /* @__PURE__ */ new Set([
|
|
3554
|
+
"div",
|
|
3555
|
+
"p",
|
|
3556
|
+
"h1",
|
|
3557
|
+
"h2",
|
|
3558
|
+
"h3",
|
|
3559
|
+
"h4",
|
|
3560
|
+
"h5",
|
|
3561
|
+
"h6",
|
|
3562
|
+
"ul",
|
|
3563
|
+
"ol",
|
|
3564
|
+
"li",
|
|
3565
|
+
"dl",
|
|
3566
|
+
"dt",
|
|
3567
|
+
"dd",
|
|
3568
|
+
"blockquote",
|
|
3569
|
+
"pre",
|
|
3570
|
+
"article",
|
|
3571
|
+
"aside",
|
|
3572
|
+
"nav",
|
|
3573
|
+
"section",
|
|
3574
|
+
"header",
|
|
3575
|
+
"footer",
|
|
3576
|
+
"main",
|
|
3577
|
+
"figure",
|
|
3578
|
+
"figcaption",
|
|
3579
|
+
"table",
|
|
3580
|
+
"thead",
|
|
3581
|
+
"tbody",
|
|
3582
|
+
"tfoot",
|
|
3583
|
+
"tr",
|
|
3584
|
+
"td",
|
|
3585
|
+
"th",
|
|
3586
|
+
"caption",
|
|
3587
|
+
"form",
|
|
3588
|
+
"fieldset",
|
|
3589
|
+
"legend",
|
|
3590
|
+
"details",
|
|
3591
|
+
"summary",
|
|
3592
|
+
"address",
|
|
3593
|
+
"hr",
|
|
3594
|
+
"search",
|
|
3595
|
+
"dialog",
|
|
3596
|
+
"noscript",
|
|
3597
|
+
"title"
|
|
3598
|
+
// <title> should be treated as a block element for translation
|
|
3599
|
+
]);
|
|
3600
|
+
const UNLOCALIZABLE_TAGS = /* @__PURE__ */ new Set(["script", "style"]);
|
|
3510
3601
|
const LOCALIZABLE_ATTRIBUTES = {
|
|
3511
3602
|
meta: ["content"],
|
|
3512
|
-
img: ["alt"],
|
|
3513
|
-
input: ["placeholder"],
|
|
3514
|
-
|
|
3603
|
+
img: ["alt", "title"],
|
|
3604
|
+
input: ["placeholder", "title"],
|
|
3605
|
+
textarea: ["placeholder", "title"],
|
|
3606
|
+
a: ["title"],
|
|
3607
|
+
abbr: ["title"],
|
|
3608
|
+
button: ["title"],
|
|
3609
|
+
link: ["title"]
|
|
3515
3610
|
};
|
|
3516
|
-
const UNLOCALIZABLE_TAGS = ["script", "style"];
|
|
3517
3611
|
return createLoader({
|
|
3518
3612
|
async pull(locale, input2) {
|
|
3519
3613
|
const result = {};
|
|
3520
|
-
const
|
|
3521
|
-
const
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3614
|
+
const handler = new DomHandler();
|
|
3615
|
+
const parser = new htmlparser2.Parser(handler, {
|
|
3616
|
+
lowerCaseTags: false,
|
|
3617
|
+
lowerCaseAttributeNames: false
|
|
3618
|
+
});
|
|
3619
|
+
parser.write(input2);
|
|
3620
|
+
parser.end();
|
|
3621
|
+
const dom = handler.dom;
|
|
3622
|
+
function isInsideUnlocalizableTag(element) {
|
|
3623
|
+
let current = element.parent;
|
|
3624
|
+
while (current && current.type === "tag") {
|
|
3625
|
+
if (UNLOCALIZABLE_TAGS.has(current.name.toLowerCase())) {
|
|
3626
|
+
return true;
|
|
3532
3627
|
}
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3628
|
+
current = current.parent;
|
|
3629
|
+
}
|
|
3630
|
+
return false;
|
|
3631
|
+
}
|
|
3632
|
+
function hasTranslatableContent(element) {
|
|
3633
|
+
const text = domutils.textContent(element);
|
|
3634
|
+
return text.trim().length > 0;
|
|
3635
|
+
}
|
|
3636
|
+
function isLeafBlock(element) {
|
|
3637
|
+
const childElements = element.children.filter(
|
|
3638
|
+
(child) => child.type === "tag"
|
|
3639
|
+
);
|
|
3640
|
+
for (const child of childElements) {
|
|
3641
|
+
if (BLOCK_ELEMENTS.has(child.name.toLowerCase())) {
|
|
3642
|
+
return false;
|
|
3539
3643
|
}
|
|
3540
|
-
current = parent;
|
|
3541
3644
|
}
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3645
|
+
return hasTranslatableContent(element);
|
|
3646
|
+
}
|
|
3647
|
+
function getInnerHTML(element) {
|
|
3648
|
+
return element.children.map((child) => DomSerializer.default(child, { encodeEntities: false })).join("");
|
|
3649
|
+
}
|
|
3650
|
+
function extractAttributes(element, path19) {
|
|
3651
|
+
const tagName = element.name.toLowerCase();
|
|
3652
|
+
const attrs = LOCALIZABLE_ATTRIBUTES[tagName];
|
|
3653
|
+
if (!attrs) return;
|
|
3654
|
+
for (const attr of attrs) {
|
|
3655
|
+
const value = element.attribs?.[attr];
|
|
3656
|
+
if (value && value.trim()) {
|
|
3657
|
+
result[`${path19}#${attr}`] = value.trim();
|
|
3550
3658
|
}
|
|
3551
|
-
parent = parent.parentElement;
|
|
3552
3659
|
}
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3660
|
+
}
|
|
3661
|
+
function extractFromElement(element, pathParts) {
|
|
3662
|
+
const path19 = pathParts.join("/");
|
|
3663
|
+
if (isInsideUnlocalizableTag(element)) {
|
|
3664
|
+
return;
|
|
3665
|
+
}
|
|
3666
|
+
extractAttributes(element, path19);
|
|
3667
|
+
const tagName = element.name.toLowerCase();
|
|
3668
|
+
if (BLOCK_ELEMENTS.has(tagName) && isLeafBlock(element)) {
|
|
3669
|
+
const content = getInnerHTML(element).trim();
|
|
3670
|
+
if (content) {
|
|
3671
|
+
result[path19] = content;
|
|
3558
3672
|
}
|
|
3559
|
-
|
|
3560
|
-
const element = node;
|
|
3561
|
-
const tagName = element.tagName.toLowerCase();
|
|
3562
|
-
const attributes = LOCALIZABLE_ATTRIBUTES[tagName] || [];
|
|
3563
|
-
attributes.forEach((attr) => {
|
|
3564
|
-
const value = element.getAttribute(attr);
|
|
3565
|
-
if (value) {
|
|
3566
|
-
result[getPath(element, attr)] = value;
|
|
3567
|
-
}
|
|
3568
|
-
});
|
|
3569
|
-
Array.from(element.childNodes).filter(
|
|
3570
|
-
(n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()
|
|
3571
|
-
).forEach(processNode);
|
|
3673
|
+
return;
|
|
3572
3674
|
}
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3675
|
+
if (PHRASING_ELEMENTS.has(tagName) && hasTranslatableContent(element)) {
|
|
3676
|
+
const content = getInnerHTML(element).trim();
|
|
3677
|
+
if (content) {
|
|
3678
|
+
result[path19] = content;
|
|
3679
|
+
}
|
|
3680
|
+
return;
|
|
3681
|
+
}
|
|
3682
|
+
let childIndex = 0;
|
|
3683
|
+
const childElements = element.children.filter(
|
|
3684
|
+
(child) => child.type === "tag"
|
|
3685
|
+
);
|
|
3686
|
+
for (const child of childElements) {
|
|
3687
|
+
extractFromElement(child, [...pathParts, childIndex++]);
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
const html = domutils.findOne(
|
|
3691
|
+
(elem) => elem.type === "tag" && elem.name.toLowerCase() === "html",
|
|
3692
|
+
dom,
|
|
3693
|
+
true
|
|
3694
|
+
);
|
|
3695
|
+
if (html) {
|
|
3696
|
+
const head = domutils.findOne(
|
|
3697
|
+
(elem) => elem.type === "tag" && elem.name.toLowerCase() === "head",
|
|
3698
|
+
html.children,
|
|
3699
|
+
true
|
|
3700
|
+
);
|
|
3701
|
+
const body = domutils.findOne(
|
|
3702
|
+
(elem) => elem.type === "tag" && elem.name.toLowerCase() === "body",
|
|
3703
|
+
html.children,
|
|
3704
|
+
true
|
|
3705
|
+
);
|
|
3706
|
+
if (head) {
|
|
3707
|
+
let headIndex = 0;
|
|
3708
|
+
const headChildren = head.children.filter(
|
|
3709
|
+
(child) => child.type === "tag"
|
|
3710
|
+
);
|
|
3711
|
+
for (const child of headChildren) {
|
|
3712
|
+
extractFromElement(child, ["head", headIndex++]);
|
|
3713
|
+
}
|
|
3714
|
+
}
|
|
3715
|
+
if (body) {
|
|
3716
|
+
let bodyIndex = 0;
|
|
3717
|
+
const bodyChildren = body.children.filter(
|
|
3718
|
+
(child) => child.type === "tag"
|
|
3719
|
+
);
|
|
3720
|
+
for (const child of bodyChildren) {
|
|
3721
|
+
extractFromElement(child, ["body", bodyIndex++]);
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3724
|
+
} else {
|
|
3725
|
+
let rootIndex = 0;
|
|
3726
|
+
const rootElements = dom.filter(
|
|
3727
|
+
(child) => child.type === "tag"
|
|
3728
|
+
);
|
|
3729
|
+
for (const child of rootElements) {
|
|
3730
|
+
extractFromElement(child, [rootIndex++]);
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3580
3733
|
return result;
|
|
3581
3734
|
},
|
|
3582
3735
|
async push(locale, data, originalInput) {
|
|
3583
|
-
const
|
|
3736
|
+
const handler = new DomHandler();
|
|
3737
|
+
const parser = new htmlparser2.Parser(handler, {
|
|
3738
|
+
lowerCaseTags: false,
|
|
3739
|
+
lowerCaseAttributeNames: false
|
|
3740
|
+
});
|
|
3741
|
+
parser.write(
|
|
3584
3742
|
originalInput ?? "<!DOCTYPE html><html><head></head><body></body></html>"
|
|
3585
3743
|
);
|
|
3586
|
-
|
|
3587
|
-
const
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
let
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
const index = parseInt(
|
|
3602
|
-
const
|
|
3603
|
-
(
|
|
3744
|
+
parser.end();
|
|
3745
|
+
const dom = handler.dom;
|
|
3746
|
+
const html = domutils.findOne(
|
|
3747
|
+
(elem) => elem.type === "tag" && elem.name.toLowerCase() === "html",
|
|
3748
|
+
dom,
|
|
3749
|
+
true
|
|
3750
|
+
);
|
|
3751
|
+
if (html) {
|
|
3752
|
+
html.attribs = html.attribs || {};
|
|
3753
|
+
html.attribs.lang = locale;
|
|
3754
|
+
}
|
|
3755
|
+
function traverseByIndices(element, indices) {
|
|
3756
|
+
let current = element;
|
|
3757
|
+
for (const indexStr of indices) {
|
|
3758
|
+
if (!current) return null;
|
|
3759
|
+
const index = parseInt(indexStr, 10);
|
|
3760
|
+
const children = current.children.filter(
|
|
3761
|
+
(child) => child.type === "tag"
|
|
3604
3762
|
);
|
|
3605
|
-
if (index >=
|
|
3606
|
-
|
|
3607
|
-
const textNode = document.createTextNode("");
|
|
3608
|
-
parent.appendChild(textNode);
|
|
3609
|
-
current = textNode;
|
|
3610
|
-
} else {
|
|
3611
|
-
const element = document.createElement("div");
|
|
3612
|
-
parent.appendChild(element);
|
|
3613
|
-
current = element;
|
|
3614
|
-
parent = element;
|
|
3615
|
-
}
|
|
3616
|
-
} else {
|
|
3617
|
-
current = siblings[index];
|
|
3618
|
-
if (current.nodeType === 1) {
|
|
3619
|
-
parent = current;
|
|
3620
|
-
}
|
|
3763
|
+
if (index >= children.length) {
|
|
3764
|
+
return null;
|
|
3621
3765
|
}
|
|
3766
|
+
current = children[index];
|
|
3767
|
+
}
|
|
3768
|
+
return current;
|
|
3769
|
+
}
|
|
3770
|
+
function resolvePathToElement(path19) {
|
|
3771
|
+
const parts = path19.split("/");
|
|
3772
|
+
const [rootTag, ...indices] = parts;
|
|
3773
|
+
let current = null;
|
|
3774
|
+
if (html) {
|
|
3775
|
+
if (rootTag === "head") {
|
|
3776
|
+
current = domutils.findOne(
|
|
3777
|
+
(elem) => elem.type === "tag" && elem.name.toLowerCase() === "head",
|
|
3778
|
+
html.children,
|
|
3779
|
+
true
|
|
3780
|
+
);
|
|
3781
|
+
} else if (rootTag === "body") {
|
|
3782
|
+
current = domutils.findOne(
|
|
3783
|
+
(elem) => elem.type === "tag" && elem.name.toLowerCase() === "body",
|
|
3784
|
+
html.children,
|
|
3785
|
+
true
|
|
3786
|
+
);
|
|
3787
|
+
}
|
|
3788
|
+
if (!current) return null;
|
|
3789
|
+
return traverseByIndices(current, indices);
|
|
3790
|
+
} else {
|
|
3791
|
+
const rootElements = dom.filter(
|
|
3792
|
+
(child) => child.type === "tag"
|
|
3793
|
+
);
|
|
3794
|
+
const rootIndex = parseInt(rootTag, 10);
|
|
3795
|
+
if (rootIndex >= rootElements.length) {
|
|
3796
|
+
return null;
|
|
3797
|
+
}
|
|
3798
|
+
current = rootElements[rootIndex];
|
|
3799
|
+
return traverseByIndices(current, indices);
|
|
3622
3800
|
}
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3801
|
+
}
|
|
3802
|
+
for (const [path19, value] of Object.entries(data)) {
|
|
3803
|
+
const [nodePath, attribute] = path19.split("#");
|
|
3804
|
+
const element = resolvePathToElement(nodePath);
|
|
3805
|
+
if (!element) {
|
|
3806
|
+
console.warn(`Path not found in original HTML: ${nodePath}`);
|
|
3807
|
+
continue;
|
|
3808
|
+
}
|
|
3809
|
+
if (attribute) {
|
|
3810
|
+
element.attribs = element.attribs || {};
|
|
3811
|
+
element.attribs[attribute] = value;
|
|
3812
|
+
} else {
|
|
3813
|
+
if (value) {
|
|
3814
|
+
const valueHandler = new DomHandler();
|
|
3815
|
+
const valueParser = new htmlparser2.Parser(valueHandler);
|
|
3816
|
+
valueParser.write(value);
|
|
3817
|
+
valueParser.end();
|
|
3818
|
+
element.children = valueHandler.dom;
|
|
3626
3819
|
} else {
|
|
3627
|
-
|
|
3820
|
+
element.children = [];
|
|
3628
3821
|
}
|
|
3629
3822
|
}
|
|
3630
|
-
}
|
|
3631
|
-
return
|
|
3823
|
+
}
|
|
3824
|
+
return DomSerializer.default(dom, { encodeEntities: false });
|
|
3632
3825
|
}
|
|
3633
3826
|
});
|
|
3634
3827
|
}
|
|
@@ -4074,7 +4267,7 @@ function escapeString(str) {
|
|
|
4074
4267
|
}
|
|
4075
4268
|
|
|
4076
4269
|
// src/cli/loaders/xcode-strings/parser.ts
|
|
4077
|
-
var
|
|
4270
|
+
var Parser2 = class {
|
|
4078
4271
|
tokens;
|
|
4079
4272
|
pos;
|
|
4080
4273
|
constructor(tokens) {
|
|
@@ -4147,7 +4340,7 @@ function createXcodeStringsLoader() {
|
|
|
4147
4340
|
async pull(locale, input2) {
|
|
4148
4341
|
const tokenizer = new Tokenizer(input2);
|
|
4149
4342
|
const tokens = tokenizer.tokenize();
|
|
4150
|
-
const parser = new
|
|
4343
|
+
const parser = new Parser2(tokens);
|
|
4151
4344
|
const result = parser.parse();
|
|
4152
4345
|
return result;
|
|
4153
4346
|
},
|
|
@@ -5011,7 +5204,7 @@ function preserveCommentOrder(section, originalSection) {
|
|
|
5011
5204
|
}
|
|
5012
5205
|
|
|
5013
5206
|
// src/cli/loaders/xliff.ts
|
|
5014
|
-
import { JSDOM
|
|
5207
|
+
import { JSDOM } from "jsdom";
|
|
5015
5208
|
function createXliffLoader() {
|
|
5016
5209
|
return createLoader({
|
|
5017
5210
|
async pull(locale, input2, _ctx, originalLocale) {
|
|
@@ -5020,7 +5213,7 @@ function createXliffLoader() {
|
|
|
5020
5213
|
return createEmptyResult(originalLocale, locale);
|
|
5021
5214
|
}
|
|
5022
5215
|
try {
|
|
5023
|
-
const dom = new
|
|
5216
|
+
const dom = new JSDOM(trimmedInput, { contentType: "text/xml" });
|
|
5024
5217
|
const document = dom.window.document;
|
|
5025
5218
|
const parserError = document.querySelector("parsererror");
|
|
5026
5219
|
if (parserError) {
|
|
@@ -5046,7 +5239,7 @@ function createXliffLoader() {
|
|
|
5046
5239
|
return pushNewFile(locale, translations, originalLocale);
|
|
5047
5240
|
}
|
|
5048
5241
|
try {
|
|
5049
|
-
const dom = new
|
|
5242
|
+
const dom = new JSDOM(originalInput, { contentType: "text/xml" });
|
|
5050
5243
|
const document = dom.window.document;
|
|
5051
5244
|
const xliffElement = document.documentElement;
|
|
5052
5245
|
const version = xliffElement.getAttribute("version") || "1.2";
|
|
@@ -5346,7 +5539,7 @@ ${serialized}`;
|
|
|
5346
5539
|
return serialized;
|
|
5347
5540
|
}
|
|
5348
5541
|
function formatXml(xml) {
|
|
5349
|
-
const dom = new
|
|
5542
|
+
const dom = new JSDOM(xml, { contentType: "text/xml" });
|
|
5350
5543
|
const doc = dom.window.document;
|
|
5351
5544
|
function formatElement(element, depth = 0) {
|
|
5352
5545
|
const indent2 = " ".repeat(depth);
|
|
@@ -5359,10 +5552,10 @@ function formatXml(xml) {
|
|
|
5359
5552
|
if (cdataNode) {
|
|
5360
5553
|
return `${indent2}${openTag}<![CDATA[${cdataNode.nodeValue}]]></${tagName}>`;
|
|
5361
5554
|
}
|
|
5362
|
-
const
|
|
5555
|
+
const textContent2 = element.textContent?.trim() || "";
|
|
5363
5556
|
const hasOnlyText = element.childNodes.length === 1 && element.childNodes[0].nodeType === 3;
|
|
5364
|
-
if (hasOnlyText &&
|
|
5365
|
-
return `${indent2}${openTag}${
|
|
5557
|
+
if (hasOnlyText && textContent2) {
|
|
5558
|
+
return `${indent2}${openTag}${textContent2}</${tagName}>`;
|
|
5366
5559
|
}
|
|
5367
5560
|
const children = Array.from(element.children);
|
|
5368
5561
|
if (children.length === 0) {
|
|
@@ -5389,7 +5582,7 @@ function pushNewFile(locale, translations, originalLocale) {
|
|
|
5389
5582
|
<body></body>
|
|
5390
5583
|
</file>
|
|
5391
5584
|
</xliff>`;
|
|
5392
|
-
const dom = new
|
|
5585
|
+
const dom = new JSDOM(skeleton, { contentType: "text/xml" });
|
|
5393
5586
|
const document = dom.window.document;
|
|
5394
5587
|
const bodyElement = document.querySelector("body");
|
|
5395
5588
|
Object.entries(translations).forEach(([key, value]) => {
|
|
@@ -8682,14 +8875,14 @@ function parseEjsForTranslation(input2) {
|
|
|
8682
8875
|
if (part.type === "ejs") {
|
|
8683
8876
|
template += part.content;
|
|
8684
8877
|
} else {
|
|
8685
|
-
const
|
|
8878
|
+
const textContent2 = part.content;
|
|
8686
8879
|
const htmlTagRegex = /<[^>]+>/g;
|
|
8687
8880
|
const textParts = [];
|
|
8688
8881
|
let lastTextIndex = 0;
|
|
8689
8882
|
let htmlMatch;
|
|
8690
|
-
while ((htmlMatch = htmlTagRegex.exec(
|
|
8883
|
+
while ((htmlMatch = htmlTagRegex.exec(textContent2)) !== null) {
|
|
8691
8884
|
if (htmlMatch.index > lastTextIndex) {
|
|
8692
|
-
const textBefore =
|
|
8885
|
+
const textBefore = textContent2.slice(lastTextIndex, htmlMatch.index);
|
|
8693
8886
|
if (textBefore.trim()) {
|
|
8694
8887
|
textParts.push({ type: "text", content: textBefore });
|
|
8695
8888
|
} else {
|
|
@@ -8699,8 +8892,8 @@ function parseEjsForTranslation(input2) {
|
|
|
8699
8892
|
textParts.push({ type: "html", content: htmlMatch[0] });
|
|
8700
8893
|
lastTextIndex = htmlMatch.index + htmlMatch[0].length;
|
|
8701
8894
|
}
|
|
8702
|
-
if (lastTextIndex <
|
|
8703
|
-
const remainingText =
|
|
8895
|
+
if (lastTextIndex < textContent2.length) {
|
|
8896
|
+
const remainingText = textContent2.slice(lastTextIndex);
|
|
8704
8897
|
if (remainingText.trim()) {
|
|
8705
8898
|
textParts.push({ type: "text", content: remainingText });
|
|
8706
8899
|
} else {
|
|
@@ -8708,11 +8901,11 @@ function parseEjsForTranslation(input2) {
|
|
|
8708
8901
|
}
|
|
8709
8902
|
}
|
|
8710
8903
|
if (textParts.length === 0) {
|
|
8711
|
-
const trimmedContent =
|
|
8904
|
+
const trimmedContent = textContent2.trim();
|
|
8712
8905
|
if (trimmedContent) {
|
|
8713
|
-
textParts.push({ type: "text", content:
|
|
8906
|
+
textParts.push({ type: "text", content: textContent2 });
|
|
8714
8907
|
} else {
|
|
8715
|
-
textParts.push({ type: "html", content:
|
|
8908
|
+
textParts.push({ type: "html", content: textContent2 });
|
|
8716
8909
|
}
|
|
8717
8910
|
}
|
|
8718
8911
|
for (const textPart of textParts) {
|
|
@@ -13639,7 +13832,7 @@ async function renderHero2() {
|
|
|
13639
13832
|
// package.json
|
|
13640
13833
|
var package_default = {
|
|
13641
13834
|
name: "lingo.dev",
|
|
13642
|
-
version: "0.117.
|
|
13835
|
+
version: "0.117.6",
|
|
13643
13836
|
description: "Lingo.dev CLI",
|
|
13644
13837
|
private: false,
|
|
13645
13838
|
publishConfig: {
|
|
@@ -13797,6 +13990,9 @@ var package_default = {
|
|
|
13797
13990
|
"date-fns": "4.1.0",
|
|
13798
13991
|
dedent: "1.7.0",
|
|
13799
13992
|
diff: "7.0.0",
|
|
13993
|
+
"dom-serializer": "2.0.0",
|
|
13994
|
+
domhandler: "5.0.3",
|
|
13995
|
+
domutils: "3.2.2",
|
|
13800
13996
|
dotenv: "16.4.7",
|
|
13801
13997
|
ejs: "3.1.10",
|
|
13802
13998
|
express: "5.1.0",
|
|
@@ -13807,6 +14003,7 @@ var package_default = {
|
|
|
13807
14003
|
glob: "11.1.0",
|
|
13808
14004
|
"gradient-string": "3.0.0",
|
|
13809
14005
|
"gray-matter": "4.0.3",
|
|
14006
|
+
htmlparser2: "10.0.0",
|
|
13810
14007
|
ini: "5.0.0",
|
|
13811
14008
|
ink: "4.2.0",
|
|
13812
14009
|
"ink-progress-bar": "3.0.0",
|