fix(compiler): add support for marker tags in xliff serializers (#21250)
The Xliff serializer now supports the tags `seg-source` and `mrk`, while the Xliff2 serializer now supports `mrk`. Fixes #21078 PR Close #21250
This commit is contained in:
parent
d3d9aac4e9
commit
f74130c9f7
|
@ -20,9 +20,11 @@ const _XMLNS = 'urn:oasis:names:tc:xliff:document:1.2';
|
|||
// TODO(vicb): make this a param (s/_/-/)
|
||||
const _DEFAULT_SOURCE_LANG = 'en';
|
||||
const _PLACEHOLDER_TAG = 'x';
|
||||
const _MARKER_TAG = 'mrk';
|
||||
|
||||
const _FILE_TAG = 'file';
|
||||
const _SOURCE_TAG = 'source';
|
||||
const _SEGMENT_SOURCE_TAG = 'seg-source';
|
||||
const _TARGET_TAG = 'target';
|
||||
const _UNIT_TAG = 'trans-unit';
|
||||
const _CONTEXT_GROUP_TAG = 'context-group';
|
||||
|
@ -214,8 +216,9 @@ class XliffParser implements ml.Visitor {
|
|||
}
|
||||
break;
|
||||
|
||||
// ignore those tags
|
||||
case _SOURCE_TAG:
|
||||
// ignore source message
|
||||
case _SEGMENT_SOURCE_TAG:
|
||||
break;
|
||||
|
||||
case _TARGET_TAG:
|
||||
|
@ -266,7 +269,7 @@ class XmlToI18n implements ml.Visitor {
|
|||
|
||||
const i18nNodes = this._errors.length > 0 || xmlIcu.rootNodes.length == 0 ?
|
||||
[] :
|
||||
ml.visitAll(this, xmlIcu.rootNodes);
|
||||
[].concat(...ml.visitAll(this, xmlIcu.rootNodes));
|
||||
|
||||
return {
|
||||
i18nNodes: i18nNodes,
|
||||
|
@ -276,7 +279,7 @@ class XmlToI18n implements ml.Visitor {
|
|||
|
||||
visitText(text: ml.Text, context: any) { return new i18n.Text(text.value, text.sourceSpan !); }
|
||||
|
||||
visitElement(el: ml.Element, context: any): i18n.Placeholder|null {
|
||||
visitElement(el: ml.Element, context: any): i18n.Placeholder|ml.Node[]|null {
|
||||
if (el.name === _PLACEHOLDER_TAG) {
|
||||
const nameAttr = el.attrs.find((attr) => attr.name === 'id');
|
||||
if (nameAttr) {
|
||||
|
@ -284,9 +287,14 @@ class XmlToI18n implements ml.Visitor {
|
|||
}
|
||||
|
||||
this._addError(el, `<${_PLACEHOLDER_TAG}> misses the "id" attribute`);
|
||||
} else {
|
||||
this._addError(el, `Unexpected tag`);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (el.name === _MARKER_TAG) {
|
||||
return [].concat(...ml.visitAll(this, el.children));
|
||||
}
|
||||
|
||||
this._addError(el, `Unexpected tag`);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ const _XMLNS = 'urn:oasis:names:tc:xliff:document:2.0';
|
|||
const _DEFAULT_SOURCE_LANG = 'en';
|
||||
const _PLACEHOLDER_TAG = 'ph';
|
||||
const _PLACEHOLDER_SPANNING_TAG = 'pc';
|
||||
const _MARKER_TAG = 'mrk';
|
||||
|
||||
const _XLIFF_TAG = 'xliff';
|
||||
const _SOURCE_TAG = 'source';
|
||||
|
@ -332,6 +333,8 @@ class XmlToI18n implements ml.Visitor {
|
|||
new i18n.Placeholder('', endId, el.sourceSpan));
|
||||
}
|
||||
break;
|
||||
case _MARKER_TAG:
|
||||
return [].concat(...ml.visitAll(this, el.children));
|
||||
default:
|
||||
this._addError(el, `Unexpected tag`);
|
||||
}
|
||||
|
|
|
@ -238,6 +238,24 @@ lines</source>
|
|||
lignes</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="mrk-test">
|
||||
<notes>
|
||||
<note id="n1" appliesTo="target">Please check the translation for 'namespace'. On also can use 'espace de nom',but I think most technical manuals use the English term.</note>
|
||||
</notes>
|
||||
<segment>
|
||||
<source>You use your own namespace.</source>
|
||||
<target>Vous pouvez utiliser votre propre <mrk id="m1" type="comment" ref="#n1">namespace</mrk>.</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="mrk-test2">
|
||||
<notes>
|
||||
<note id="n1" appliesTo="target">Please check the translation for 'namespace'. On also can use 'espace de nom',but I think most technical manuals use the English term.</note>
|
||||
</notes>
|
||||
<segment>
|
||||
<source>You use your own namespace.</source>
|
||||
<target>Vous pouvez utiliser <mrk id="m1" type="comment" ref="#n1">votre propre <mrk id="m2" type="comment" ref="#n1">namespace</mrk></mrk>.</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
`;
|
||||
|
@ -289,7 +307,9 @@ lignes</target>
|
|||
'5229984852258993423': '{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph' +
|
||||
' name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}, =other {[beaucoup]}}',
|
||||
'2340165783990709777': `multi
|
||||
lignes`
|
||||
lignes`,
|
||||
'mrk-test': 'Vous pouvez utiliser votre propre namespace.',
|
||||
'mrk-test2': 'Vous pouvez utiliser votre propre namespace.'
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -221,6 +221,20 @@ lignes</target>
|
|||
<context context-type="linenumber">12</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="mrk-test">
|
||||
<source>First sentence.</source>
|
||||
<seg-source>
|
||||
<invalid-tag>Should not be parsed</invalid-tag>
|
||||
</seg-source>
|
||||
<target>Translated <mrk mtype="seg" mid="1">first sentence</mrk>.</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="mrk-test2">
|
||||
<source>First sentence. Second sentence.</source>
|
||||
<seg-source>
|
||||
<invalid-tag>Should not be parsed</invalid-tag>
|
||||
</seg-source>
|
||||
<target>Translated <mrk mtype="seg" mid="1"><mrk mtype="seg" mid="2">first</mrk> sentence</mrk>.</target>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
|
@ -273,7 +287,9 @@ lignes</target>
|
|||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph' +
|
||||
' name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}, =other {[beaucoup]}}',
|
||||
'fcfa109b0e152d4c217dbc02530be0bcb8123ad1': `multi
|
||||
lignes`
|
||||
lignes`,
|
||||
'mrk-test': 'Translated first sentence.',
|
||||
'mrk-test2': 'Translated first sentence.'
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue