forked from MapComplete/MapComplete
Merge master
This commit is contained in:
commit
dcea114c99
7 changed files with 152 additions and 155 deletions
|
|
@ -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)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue