Support empty messages during location import

This commit is contained in:
Dirk Baeumer
2021-03-02 14:46:49 +01:00
parent 58ab537f4f
commit ed1118b27b
2 changed files with 10 additions and 11 deletions

View File

@@ -237,14 +237,13 @@ XLF.parse = function (xlfString) {
}
let val = unit.target[0];
if (typeof val !== 'string') {
val = val._;
// We allow empty source values so support them for translations as well.
val = val._ ? val._ : '';
}
if (key && val) {
messages[key] = decodeEntities(val);
}
else {
reject(new Error(`XLF parsing error: XLIFF file ${originalFilePath} does not contain full localization data. ID or target translation for one of the trans-unit nodes is not present.`));
if (!key) {
reject(new Error(`XLF parsing error: trans-unit ${JSON.stringify(unit, undefined, 0)} defined in file ${originalFilePath} is missing the ID attribute.`));
}
messages[key] = decodeEntities(val);
});
files.push({ messages: messages, originalFilePath: originalFilePath, language: language.toLowerCase() });
}

View File

@@ -339,13 +339,13 @@ export class XLF {
let val = unit.target[0];
if (typeof val !== 'string') {
val = val._;
// We allow empty source values so support them for translations as well.
val = val._ ? val._ : '';
}
if (key && val) {
messages[key] = decodeEntities(val);
} else {
reject(new Error(`XLF parsing error: XLIFF file ${originalFilePath} does not contain full localization data. ID or target translation for one of the trans-unit nodes is not present.`));
if (!key) {
reject(new Error(`XLF parsing error: trans-unit ${JSON.stringify(unit, undefined, 0)} defined in file ${originalFilePath} is missing the ID attribute.`));
}
messages[key] = decodeEntities(val);
});
files.push({ messages: messages, originalFilePath: originalFilePath, language: language.toLowerCase() });
}