fix(i18n): add a default example to xmb placeholders (#13507)
Otherwise the TC would not be able to load the message
This commit is contained in:
parent
0c19898694
commit
0fe3cd9a4c
|
@ -39,6 +39,7 @@ const _DOCTYPE = `<!ELEMENT messagebundle (msg)*>
|
|||
|
||||
export class Xmb implements Serializer {
|
||||
write(messages: i18n.Message[]): string {
|
||||
const exampleVisitor = new ExampleVisitor();
|
||||
const visitor = new _Visitor();
|
||||
const visited: {[id: string]: boolean} = {};
|
||||
let rootNode = new xml.Tag(_MESSAGES_TAG);
|
||||
|
@ -71,7 +72,7 @@ export class Xmb implements Serializer {
|
|||
new xml.CR(),
|
||||
new xml.Doctype(_MESSAGES_TAG, _DOCTYPE),
|
||||
new xml.CR(),
|
||||
rootNode,
|
||||
exampleVisitor.addDefaultExamples(rootNode),
|
||||
new xml.CR(),
|
||||
]);
|
||||
}
|
||||
|
@ -133,4 +134,27 @@ class _Visitor implements i18n.Visitor {
|
|||
|
||||
export function digest(message: i18n.Message): string {
|
||||
return decimalDigest(message);
|
||||
}
|
||||
}
|
||||
|
||||
// TC requires at least one non-empty example on placeholders
|
||||
class ExampleVisitor implements xml.IVisitor {
|
||||
addDefaultExamples(node: xml.Node): xml.Node {
|
||||
node.visit(this);
|
||||
return node;
|
||||
}
|
||||
|
||||
visitTag(tag: xml.Tag): void {
|
||||
if (tag.name === _PLACEHOLDER_TAG) {
|
||||
if (!tag.children || tag.children.length == 0) {
|
||||
const exText = new xml.Text(tag.attrs['name'] || '...');
|
||||
tag.children = [new xml.Tag(_EXEMPLE_TAG, {}, [exText])];
|
||||
}
|
||||
} else if (tag.children) {
|
||||
tag.children.forEach(node => node.visit(this));
|
||||
}
|
||||
}
|
||||
|
||||
visitText(text: xml.Text): void {}
|
||||
visitDeclaration(decl: xml.Declaration): void {}
|
||||
visitDoctype(doctype: xml.Doctype): void {}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ export function main(): void {
|
|||
<!ELEMENT ex (#PCDATA)>
|
||||
]>
|
||||
<messagebundle>
|
||||
<msg id="7056919470098446707">translatable element <ph name="START_BOLD_TEXT"><ex><b></ex></ph>with placeholders<ph name="CLOSE_BOLD_TEXT"><ex></b></ex></ph> <ph name="INTERPOLATION"/></msg>
|
||||
<msg id="7056919470098446707">translatable element <ph name="START_BOLD_TEXT"><ex><b></ex></ph>with placeholders<ph name="CLOSE_BOLD_TEXT"><ex></b></ex></ph> <ph name="INTERPOLATION"><ex>INTERPOLATION</ex></ph></msg>
|
||||
<msg id="2981514368455622387">{VAR_PLURAL, plural, =0 {<ph name="START_PARAGRAPH"><ex><p></ex></ph>test<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} }</msg>
|
||||
<msg id="7999024498831672133" desc="d" meaning="m">foo</msg>
|
||||
<msg id="i" desc="d" meaning="m">foo</msg>
|
||||
|
|
Loading…
Reference in New Issue