Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(localize): relax error to warning for missing target #41944

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -140,13 +140,23 @@ class XliffTranslationVisitor extends BaseVisitor {
return;
}

// Error if there is no `<target>` child element
const targetMessage = element.children.find(isNamedElement('target'));
let targetMessage = element.children.find(isNamedElement('target'));
if (targetMessage === undefined) {
// Warn if there is no `<target>` child element
addParseDiagnostic(
bundle.diagnostics, element.sourceSpan, 'Missing required <target> element',
ParseErrorLevel.ERROR);
return;
bundle.diagnostics, element.sourceSpan, 'Missing <target> element',
ParseErrorLevel.WARNING);

// Fallback to the `<source>` element if available.
targetMessage = element.children.find(isNamedElement('source'));
if (targetMessage === undefined) {
// Error if there is neither `<target>` nor `<source>`.
addParseDiagnostic(
bundle.diagnostics, element.sourceSpan,
'Missing required element: one of <target> or <source> is required',
ParseErrorLevel.ERROR);
return;
}
}

const {translation, parseErrors, serializeErrors} = serializeTranslationMessage(targetMessage, {
Expand Down
Expand Up @@ -132,12 +132,23 @@ class Xliff2TranslationVisitor extends BaseVisitor {
return;
}

const targetMessage = element.children.find(isNamedElement('target'));
let targetMessage = element.children.find(isNamedElement('target'));
if (targetMessage === undefined) {
// Warn if there is no `<target>` child element
addParseDiagnostic(
bundle.diagnostics, element.sourceSpan, 'Missing required <target> element',
ParseErrorLevel.ERROR);
return;
bundle.diagnostics, element.sourceSpan, 'Missing <target> element',
ParseErrorLevel.WARNING);

// Fallback to the `<source>` element if available.
targetMessage = element.children.find(isNamedElement('source'));
if (targetMessage === undefined) {
// Error if there is neither `<target>` nor `<source>`.
addParseDiagnostic(
bundle.diagnostics, element.sourceSpan,
'Missing required element: one of <target> or <source> is required',
ParseErrorLevel.ERROR);
return;
}
}

const {translation, parseErrors, serializeErrors} = serializeTranslationMessage(targetMessage, {
Expand Down