forked from MapComplete/MapComplete
Improve error handling
This commit is contained in:
parent
ae7db7ddc2
commit
78052b9aa2
1 changed files with 16 additions and 9 deletions
|
@ -189,7 +189,7 @@ class TranslationPart {
|
||||||
*/
|
*/
|
||||||
validate(path = []): {error: string, path: string[]} [] {
|
validate(path = []): {error: string, path: string[]} [] {
|
||||||
const errors : {error: string, path: string[]} []= []
|
const errors : {error: string, path: string[]} []= []
|
||||||
const neededSubparts = new Set<string>()
|
const neededSubparts = new Set<{ part: string, usedByLanguage: string }>()
|
||||||
|
|
||||||
let isLeaf : boolean = undefined
|
let isLeaf : boolean = undefined
|
||||||
this.contents.forEach((value, key) => {
|
this.contents.forEach((value, key) => {
|
||||||
|
@ -206,9 +206,14 @@ class TranslationPart {
|
||||||
|
|
||||||
let subparts: string[] = value.match(/{[^}]*}/g)
|
let subparts: string[] = value.match(/{[^}]*}/g)
|
||||||
if (subparts !== null) {
|
if (subparts !== null) {
|
||||||
|
let [_, __, weblatepart, lang] = key.split("/")
|
||||||
|
if (lang === undefined) {
|
||||||
|
// This is a core translation, it has one less path segment
|
||||||
|
lang = weblatepart
|
||||||
|
}
|
||||||
subparts = subparts.map(p => p.split(/\(.*\)/)[0])
|
subparts = subparts.map(p => p.split(/\(.*\)/)[0])
|
||||||
for (const subpart of subparts) {
|
for (const subpart of subparts) {
|
||||||
neededSubparts.add(subpart)
|
neededSubparts.add({part: subpart, usedByLanguage: lang})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -216,7 +221,7 @@ class TranslationPart {
|
||||||
|
|
||||||
// Actually check for the needed sub-parts, e.g. that {key} isn't translated into {sleutel}
|
// Actually check for the needed sub-parts, e.g. that {key} isn't translated into {sleutel}
|
||||||
this.contents.forEach((value, key) => {
|
this.contents.forEach((value, key) => {
|
||||||
neededSubparts.forEach(part => {
|
neededSubparts.forEach(({part, usedByLanguage}) => {
|
||||||
if (typeof value !== "string") {
|
if (typeof value !== "string") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -239,12 +244,14 @@ class TranslationPart {
|
||||||
lang = weblatepart
|
lang = weblatepart
|
||||||
weblatepart = "core"
|
weblatepart = "core"
|
||||||
}
|
}
|
||||||
errors.push({
|
if(lang === "en" || usedByLanguage === "en"){
|
||||||
error: `The translation for ${key} does not have the required subpart ${part}.
|
errors.push({
|
||||||
\tThe full translation is ${value}
|
error: `The translation for ${key} does not have the required subpart ${part}.
|
||||||
\tFix it on https://hosted.weblate.org/translate/mapcomplete/${weblatepart}/${lang}/?offset=1&q=context%3A%3D%22${path.join(".")}%22`,
|
\tThe full translation is ${value}
|
||||||
path: path
|
\tFix it on https://hosted.weblate.org/translate/mapcomplete/${weblatepart}/${lang}/?offset=1&q=context%3A%3D%22${encodeURIComponent( path.join("."))}%22`,
|
||||||
})
|
path: path
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue