Merge master

This commit is contained in:
Pieter Vander Vennet 2025-08-08 00:44:06 +02:00
commit dcea114c99
7 changed files with 152 additions and 155 deletions

View file

@ -128,24 +128,28 @@ export class AddContextToTranslations<T> extends DesugaringStep<T> {
if (leaf === undefined || leaf === null) {
return leaf
}
if (typeof leaf === "object") {
// follow the path. If we encounter a number, check that there is no ID we can use instead
let breadcrumb = json
for (let i = 0; i < path.length; i++) {
const pointer = path[i]
breadcrumb = breadcrumb[pointer]
if (pointer.match("[0-9]+") && breadcrumb["id"] !== undefined) {
path[i] = breadcrumb["id"]
}
}
return {
...leaf,
_context: this._prefix + context.path.concat(path).join("."),
}
} else {
if (typeof leaf !== "object") {
return leaf
}
if(leaf["_context"] !== undefined){
// Context is already set
return leaf
}
// follow the path. If we encounter a number, check that there is no ID we can use instead
let breadcrumb = json
for (let i = 0; i < path.length; i++) {
const pointer = path[i]
breadcrumb = breadcrumb[pointer]
if (pointer.match("[0-9]+") && breadcrumb["id"] !== undefined) {
path[i] = breadcrumb["id"]
}
}
const pth = this._prefix + Utils.NoEmpty(context.path.concat(path).map(x => "" + x)).join(".")
console.log("Setting _context to: ",pth)
return {
...leaf,
_context: pth,
}
},
(obj) => obj === undefined || obj === null || Translations.isProbablyATranslation(obj)
)