style(compiler): reformat of codebase with new clang-format version (#36520)
This commit reformats the packages/compiler tree using the new version of clang-format. PR Close #36520
This commit is contained in:
@ -36,13 +36,13 @@ import {_extractMessages} from '../i18n_parser_spec';
|
||||
const visitor = new RecurseVisitor();
|
||||
const container = new i18n.Container(
|
||||
[
|
||||
new i18n.Text('', null !),
|
||||
new i18n.Placeholder('', '', null !),
|
||||
new i18n.IcuPlaceholder(null !, '', null !),
|
||||
new i18n.Text('', null!),
|
||||
new i18n.Placeholder('', '', null!),
|
||||
new i18n.IcuPlaceholder(null!, '', null!),
|
||||
],
|
||||
null !);
|
||||
const tag = new i18n.TagPlaceholder('', {}, '', '', [container], false, null !);
|
||||
const icu = new i18n.Icu('', '', {tag}, null !);
|
||||
null!);
|
||||
const tag = new i18n.TagPlaceholder('', {}, '', '', [container], false, null!);
|
||||
const icu = new i18n.Icu('', '', {tag}, null!);
|
||||
|
||||
icu.visit(visitor);
|
||||
expect(visitor.textCount).toEqual(1);
|
||||
@ -58,9 +58,15 @@ class RecurseVisitor extends i18n.RecurseVisitor {
|
||||
phCount = 0;
|
||||
icuPhCount = 0;
|
||||
|
||||
visitText(text: i18n.Text, context?: any): any { this.textCount++; }
|
||||
visitText(text: i18n.Text, context?: any): any {
|
||||
this.textCount++;
|
||||
}
|
||||
|
||||
visitPlaceholder(ph: i18n.Placeholder, context?: any): any { this.phCount++; }
|
||||
visitPlaceholder(ph: i18n.Placeholder, context?: any): any {
|
||||
this.phCount++;
|
||||
}
|
||||
|
||||
visitIcuPlaceholder(ph: i18n.IcuPlaceholder, context?: any): any { this.icuPhCount++; }
|
||||
visitIcuPlaceholder(ph: i18n.IcuPlaceholder, context?: any): any {
|
||||
this.icuPhCount++;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ import {PlaceholderRegistry} from '../../../src/i18n/serializers/placeholder';
|
||||
describe('PlaceholderRegistry', () => {
|
||||
let reg: PlaceholderRegistry;
|
||||
|
||||
beforeEach(() => { reg = new PlaceholderRegistry(); });
|
||||
beforeEach(() => {
|
||||
reg = new PlaceholderRegistry();
|
||||
});
|
||||
|
||||
describe('tag placeholder', () => {
|
||||
it('should generate names for well known tags', () => {
|
||||
@ -84,7 +86,6 @@ import {PlaceholderRegistry} from '../../../src/i18n/serializers/placeholder';
|
||||
expect(reg.getPlaceholderName('name1', 'content')).toEqual('NAME1');
|
||||
expect(reg.getPlaceholderName('name2', 'content')).toEqual('NAME2');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
@ -261,65 +261,67 @@ lignes</target>
|
||||
`;
|
||||
|
||||
(function() {
|
||||
const serializer = new Xliff2();
|
||||
const serializer = new Xliff2();
|
||||
|
||||
function toXliff(html: string, locale: string | null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
catalog.updateFromTemplate(html, 'file.ts', DEFAULT_INTERPOLATION_CONFIG);
|
||||
return catalog.write(serializer);
|
||||
}
|
||||
function toXliff(html: string, locale: string|null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
catalog.updateFromTemplate(html, 'file.ts', DEFAULT_INTERPOLATION_CONFIG);
|
||||
return catalog.write(serializer);
|
||||
}
|
||||
|
||||
function loadAsMap(xliff: string): {[id: string]: string} {
|
||||
const {i18nNodesByMsgId} = serializer.load(xliff, 'url');
|
||||
function loadAsMap(xliff: string): {[id: string]: string} {
|
||||
const {i18nNodesByMsgId} = serializer.load(xliff, 'url');
|
||||
|
||||
const msgMap: {[id: string]: string} = {};
|
||||
Object.keys(i18nNodesByMsgId)
|
||||
.forEach(id => msgMap[id] = serializeNodes(i18nNodesByMsgId[id]).join(''));
|
||||
const msgMap: {[id: string]: string} = {};
|
||||
Object.keys(i18nNodesByMsgId)
|
||||
.forEach(id => msgMap[id] = serializeNodes(i18nNodesByMsgId[id]).join(''));
|
||||
|
||||
return msgMap;
|
||||
}
|
||||
return msgMap;
|
||||
}
|
||||
|
||||
describe('XLIFF 2.0 serializer', () => {
|
||||
describe('write', () => {
|
||||
it('should write a valid xliff 2.0 file',
|
||||
() => { expect(toXliff(HTML)).toEqual(WRITE_XLIFF); });
|
||||
it('should write a valid xliff 2.0 file with a source language',
|
||||
() => { expect(toXliff(HTML, 'fr')).toContain('srcLang="fr"'); });
|
||||
describe('XLIFF 2.0 serializer', () => {
|
||||
describe('write', () => {
|
||||
it('should write a valid xliff 2.0 file', () => {
|
||||
expect(toXliff(HTML)).toEqual(WRITE_XLIFF);
|
||||
});
|
||||
it('should write a valid xliff 2.0 file with a source language', () => {
|
||||
expect(toXliff(HTML, 'fr')).toContain('srcLang="fr"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('load', () => {
|
||||
it('should load XLIFF files', () => {
|
||||
expect(loadAsMap(LOAD_XLIFF)).toEqual({
|
||||
'1933478729560469763': 'etubirtta elbatalsnart',
|
||||
'7056919470098446707':
|
||||
'<ph name="INTERPOLATION"/> <ph name="START_BOLD_TEXT"/>sredlohecalp htiw<ph name="CLOSE_BOLD_TEXT"/> tnemele elbatalsnart',
|
||||
'2981514368455622387':
|
||||
'{VAR_PLURAL, plural, =0 {[<ph name="START_PARAGRAPH"/>, TEST, <ph name="CLOSE_PARAGRAPH"/>]}}',
|
||||
'i': 'oof',
|
||||
'6440235004920703622':
|
||||
'<ph name="START_BOLD_TEXT"/><ph name="START_UNDERLINED_TEXT"/>txeT <ph name="INTERPOLATION"/><ph name="CLOSE_UNDERLINED_TEXT"/><ph name="CLOSE_BOLD_TEXT"/>',
|
||||
'8779402634269838862':
|
||||
'<ph name="TAG_IMG_1"/><ph name="TAG_IMG"/><ph name="LINE_BREAK"/>',
|
||||
'6536355551500405293': '<ph name="START_TAG_SPAN"/><ph name="CLOSE_TAG_SPAN"/> olleh',
|
||||
'baz':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}}',
|
||||
'6997386649824869937': 'Test: <ph name="ICU"/>',
|
||||
'5229984852258993423': '{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph' +
|
||||
' name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}, =other {[beaucoup]}}',
|
||||
'2340165783990709777': `multi
|
||||
describe('load', () => {
|
||||
it('should load XLIFF files', () => {
|
||||
expect(loadAsMap(LOAD_XLIFF)).toEqual({
|
||||
'1933478729560469763': 'etubirtta elbatalsnart',
|
||||
'7056919470098446707':
|
||||
'<ph name="INTERPOLATION"/> <ph name="START_BOLD_TEXT"/>sredlohecalp htiw<ph name="CLOSE_BOLD_TEXT"/> tnemele elbatalsnart',
|
||||
'2981514368455622387':
|
||||
'{VAR_PLURAL, plural, =0 {[<ph name="START_PARAGRAPH"/>, TEST, <ph name="CLOSE_PARAGRAPH"/>]}}',
|
||||
'i': 'oof',
|
||||
'6440235004920703622':
|
||||
'<ph name="START_BOLD_TEXT"/><ph name="START_UNDERLINED_TEXT"/>txeT <ph name="INTERPOLATION"/><ph name="CLOSE_UNDERLINED_TEXT"/><ph name="CLOSE_BOLD_TEXT"/>',
|
||||
'8779402634269838862': '<ph name="TAG_IMG_1"/><ph name="TAG_IMG"/><ph name="LINE_BREAK"/>',
|
||||
'6536355551500405293': '<ph name="START_TAG_SPAN"/><ph name="CLOSE_TAG_SPAN"/> olleh',
|
||||
'baz':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}}',
|
||||
'6997386649824869937': 'Test: <ph name="ICU"/>',
|
||||
'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`,
|
||||
'mrk-test': 'Vous pouvez utiliser votre propre namespace.',
|
||||
'mrk-test2': 'Vous pouvez utiliser votre propre namespace.'
|
||||
});
|
||||
'mrk-test': 'Vous pouvez utiliser votre propre namespace.',
|
||||
'mrk-test2': 'Vous pouvez utiliser votre propre namespace.'
|
||||
});
|
||||
|
||||
it('should return the target locale',
|
||||
() => { expect(serializer.load(LOAD_XLIFF, 'url').locale).toEqual('fr'); });
|
||||
});
|
||||
|
||||
describe('structure errors', () => {
|
||||
it('should throw when a wrong xliff version is used', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should return the target locale', () => {
|
||||
expect(serializer.load(LOAD_XLIFF, 'url').locale).toEqual('fr');
|
||||
});
|
||||
});
|
||||
|
||||
describe('structure errors', () => {
|
||||
it('should throw when a wrong xliff version is used', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<file source-language="en" datatype="plaintext" original="ng2.template">
|
||||
<body>
|
||||
@ -331,13 +333,13 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/The XLIFF file version 1.2 is not compatible with XLIFF 2.0 serializer/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/The XLIFF file version 1.2 is not compatible with XLIFF 2.0 serializer/);
|
||||
});
|
||||
|
||||
it('should throw when an unit has no translation', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw when an unit has no translation', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
|
||||
<file original="ng.template" id="ngi18n">
|
||||
<unit id="missingtarget">
|
||||
@ -348,14 +350,14 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Message missingtarget misses a translation/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Message missingtarget misses a translation/);
|
||||
});
|
||||
|
||||
|
||||
it('should throw when an unit has no id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw when an unit has no id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
|
||||
<file original="ng.template" id="ngi18n">
|
||||
<unit>
|
||||
@ -367,11 +369,13 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => { loadAsMap(XLIFF); }).toThrowError(/<unit> misses the "id" attribute/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/<unit> misses the "id" attribute/);
|
||||
});
|
||||
|
||||
it('should throw on duplicate unit id', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw on duplicate unit id', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
|
||||
<file original="ng.template" id="ngi18n">
|
||||
<unit id="deadbeef">
|
||||
@ -389,15 +393,15 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Duplicated translations for msg deadbeef/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Duplicated translations for msg deadbeef/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('message errors', () => {
|
||||
it('should throw on unknown message tags', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
describe('message errors', () => {
|
||||
it('should throw on unknown message tags', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
|
||||
<file original="ng.template" id="ngi18n">
|
||||
<unit id="deadbeef">
|
||||
@ -409,13 +413,15 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => { loadAsMap(XLIFF); })
|
||||
.toThrowError(new RegExp(
|
||||
escapeRegExp(`[ERROR ->]<b>msg should contain only ph and pc tags</b>`)));
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
})
|
||||
.toThrowError(
|
||||
new RegExp(escapeRegExp(`[ERROR ->]<b>msg should contain only ph and pc tags</b>`)));
|
||||
});
|
||||
|
||||
it('should throw when a placeholder misses an id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw when a placeholder misses an id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
|
||||
<file original="ng.template" id="ngi18n">
|
||||
<unit id="deadbeef">
|
||||
@ -427,10 +433,10 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(new RegExp(escapeRegExp(`<ph> misses the "equiv" attribute`)));
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(new RegExp(escapeRegExp(`<ph> misses the "equiv" attribute`)));
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
@ -241,63 +241,67 @@ lignes</target>
|
||||
`;
|
||||
|
||||
(function() {
|
||||
const serializer = new Xliff();
|
||||
const serializer = new Xliff();
|
||||
|
||||
function toXliff(html: string, locale: string | null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
catalog.updateFromTemplate(html, 'file.ts', DEFAULT_INTERPOLATION_CONFIG);
|
||||
return catalog.write(serializer);
|
||||
}
|
||||
function toXliff(html: string, locale: string|null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
catalog.updateFromTemplate(html, 'file.ts', DEFAULT_INTERPOLATION_CONFIG);
|
||||
return catalog.write(serializer);
|
||||
}
|
||||
|
||||
function loadAsMap(xliff: string): {[id: string]: string} {
|
||||
const {i18nNodesByMsgId} = serializer.load(xliff, 'url');
|
||||
function loadAsMap(xliff: string): {[id: string]: string} {
|
||||
const {i18nNodesByMsgId} = serializer.load(xliff, 'url');
|
||||
|
||||
const msgMap: {[id: string]: string} = {};
|
||||
Object.keys(i18nNodesByMsgId)
|
||||
.forEach(id => msgMap[id] = serializeNodes(i18nNodesByMsgId[id]).join(''));
|
||||
const msgMap: {[id: string]: string} = {};
|
||||
Object.keys(i18nNodesByMsgId)
|
||||
.forEach(id => msgMap[id] = serializeNodes(i18nNodesByMsgId[id]).join(''));
|
||||
|
||||
return msgMap;
|
||||
}
|
||||
return msgMap;
|
||||
}
|
||||
|
||||
describe('XLIFF serializer', () => {
|
||||
describe('write', () => {
|
||||
it('should write a valid xliff file', () => { expect(toXliff(HTML)).toEqual(WRITE_XLIFF); });
|
||||
it('should write a valid xliff file with a source language',
|
||||
() => { expect(toXliff(HTML, 'fr')).toContain('file source-language="fr"'); });
|
||||
describe('XLIFF serializer', () => {
|
||||
describe('write', () => {
|
||||
it('should write a valid xliff file', () => {
|
||||
expect(toXliff(HTML)).toEqual(WRITE_XLIFF);
|
||||
});
|
||||
it('should write a valid xliff file with a source language', () => {
|
||||
expect(toXliff(HTML, 'fr')).toContain('file source-language="fr"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('load', () => {
|
||||
it('should load XLIFF files', () => {
|
||||
expect(loadAsMap(LOAD_XLIFF)).toEqual({
|
||||
'983775b9a51ce14b036be72d4cfd65d68d64e231': 'etubirtta elbatalsnart',
|
||||
'ec1d033f2436133c14ab038286c4f5df4697484a':
|
||||
'<ph name="INTERPOLATION"/> footnemele elbatalsnart <ph name="START_BOLD_TEXT"/>sredlohecalp htiw<ph name="CLOSE_BOLD_TEXT"/>',
|
||||
'e2ccf3d131b15f54aa1fcf1314b1ca77c14bfcc2':
|
||||
'{VAR_PLURAL, plural, =0 {[<ph name="START_PARAGRAPH"/>, TEST, <ph name="CLOSE_PARAGRAPH"/>]}}',
|
||||
'db3e0a6a5a96481f60aec61d98c3eecddef5ac23': 'oof',
|
||||
'i': 'toto',
|
||||
'bar': 'tata',
|
||||
'd7fa2d59aaedcaa5309f13028c59af8c85b8c49d':
|
||||
'<ph name="START_TAG_DIV"/><ph name="CLOSE_TAG_DIV"/><ph name="TAG_IMG"/><ph name="LINE_BREAK"/>',
|
||||
'empty target': '',
|
||||
'baz':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}}',
|
||||
'52ffa620dcd76247a56d5331f34e73f340a43cdb': 'Test: <ph name="ICU"/>',
|
||||
'1503afd0ccc20ff01d5e2266a9157b7b342ba494':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph' +
|
||||
' name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}, =other {[beaucoup]}}',
|
||||
'fcfa109b0e152d4c217dbc02530be0bcb8123ad1': `multi
|
||||
lignes`,
|
||||
'mrk-test': 'Translated first sentence.',
|
||||
'mrk-test2': 'Translated first sentence.'
|
||||
});
|
||||
});
|
||||
|
||||
describe('load', () => {
|
||||
it('should load XLIFF files', () => {
|
||||
expect(loadAsMap(LOAD_XLIFF)).toEqual({
|
||||
'983775b9a51ce14b036be72d4cfd65d68d64e231': 'etubirtta elbatalsnart',
|
||||
'ec1d033f2436133c14ab038286c4f5df4697484a':
|
||||
'<ph name="INTERPOLATION"/> footnemele elbatalsnart <ph name="START_BOLD_TEXT"/>sredlohecalp htiw<ph name="CLOSE_BOLD_TEXT"/>',
|
||||
'e2ccf3d131b15f54aa1fcf1314b1ca77c14bfcc2':
|
||||
'{VAR_PLURAL, plural, =0 {[<ph name="START_PARAGRAPH"/>, TEST, <ph name="CLOSE_PARAGRAPH"/>]}}',
|
||||
'db3e0a6a5a96481f60aec61d98c3eecddef5ac23': 'oof',
|
||||
'i': 'toto',
|
||||
'bar': 'tata',
|
||||
'd7fa2d59aaedcaa5309f13028c59af8c85b8c49d':
|
||||
'<ph name="START_TAG_DIV"/><ph name="CLOSE_TAG_DIV"/><ph name="TAG_IMG"/><ph name="LINE_BREAK"/>',
|
||||
'empty target': '',
|
||||
'baz':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}}',
|
||||
'52ffa620dcd76247a56d5331f34e73f340a43cdb': 'Test: <ph name="ICU"/>',
|
||||
'1503afd0ccc20ff01d5e2266a9157b7b342ba494':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph' +
|
||||
' name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}, =other {[beaucoup]}}',
|
||||
'fcfa109b0e152d4c217dbc02530be0bcb8123ad1': `multi
|
||||
lignes`,
|
||||
'mrk-test': 'Translated first sentence.',
|
||||
'mrk-test2': 'Translated first sentence.'
|
||||
});
|
||||
});
|
||||
it('should return the target locale', () => {
|
||||
expect(serializer.load(LOAD_XLIFF, 'url').locale).toEqual('fr');
|
||||
});
|
||||
|
||||
it('should return the target locale',
|
||||
() => { expect(serializer.load(LOAD_XLIFF, 'url').locale).toEqual('fr'); });
|
||||
|
||||
it('should ignore alt-trans targets', () => {
|
||||
const XLIFF = `
|
||||
it('should ignore alt-trans targets', () => {
|
||||
const XLIFF = `
|
||||
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<file source-language="en" target-language="fr" datatype="plaintext" original="ng2.template">
|
||||
<body>
|
||||
@ -318,12 +322,12 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(loadAsMap(XLIFF)).toEqual({'registration.submit': 'Weiter'});
|
||||
});
|
||||
expect(loadAsMap(XLIFF)).toEqual({'registration.submit': 'Weiter'});
|
||||
});
|
||||
|
||||
describe('structure errors', () => {
|
||||
it('should throw when a trans-unit has no translation', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
describe('structure errors', () => {
|
||||
it('should throw when a trans-unit has no translation', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<file source-language="en" datatype="plaintext" original="ng2.template">
|
||||
<body>
|
||||
@ -334,14 +338,14 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Message missingtarget misses a translation/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Message missingtarget misses a translation/);
|
||||
});
|
||||
|
||||
|
||||
it('should throw when a trans-unit has no id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw when a trans-unit has no id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<file source-language="en" datatype="plaintext" original="ng2.template">
|
||||
<body>
|
||||
@ -353,13 +357,13 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/<trans-unit> misses the "id" attribute/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/<trans-unit> misses the "id" attribute/);
|
||||
});
|
||||
|
||||
it('should throw on duplicate trans-unit id', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw on duplicate trans-unit id', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<file source-language="en" datatype="plaintext" original="ng2.template">
|
||||
<body>
|
||||
@ -375,15 +379,15 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Duplicated translations for msg deadbeef/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Duplicated translations for msg deadbeef/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('message errors', () => {
|
||||
it('should throw on unknown message tags', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
describe('message errors', () => {
|
||||
it('should throw on unknown message tags', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<file source-language="en" datatype="plaintext" original="ng2.template">
|
||||
<body>
|
||||
@ -395,13 +399,15 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => { loadAsMap(XLIFF); })
|
||||
.toThrowError(
|
||||
new RegExp(escapeRegExp(`[ERROR ->]<b>msg should contain only ph tags</b>`)));
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
})
|
||||
.toThrowError(
|
||||
new RegExp(escapeRegExp(`[ERROR ->]<b>msg should contain only ph tags</b>`)));
|
||||
});
|
||||
|
||||
it('should throw when a placeholder misses an id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw when a placeholder misses an id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<file source-language="en" datatype="plaintext" original="ng2.template">
|
||||
<body>
|
||||
@ -413,12 +419,11 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(new RegExp(escapeRegExp(`<x> misses the "id" attribute`)));
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(new RegExp(escapeRegExp(`<x> misses the "id" attribute`)));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
@ -76,7 +76,7 @@ lines</msg>
|
||||
});
|
||||
}
|
||||
|
||||
function toXmb(html: string, url: string, locale: string | null = null): string {
|
||||
function toXmb(html: string, url: string, locale: string|null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
const serializer = new Xmb();
|
||||
|
||||
|
@ -15,11 +15,13 @@ import * as xml from '../../../src/i18n/serializers/xml_helper';
|
||||
.toEqual('<?xml version="1.0" ?>');
|
||||
});
|
||||
|
||||
it('should serialize text node',
|
||||
() => { expect(xml.serialize([new xml.Text('foo bar')])).toEqual('foo bar'); });
|
||||
it('should serialize text node', () => {
|
||||
expect(xml.serialize([new xml.Text('foo bar')])).toEqual('foo bar');
|
||||
});
|
||||
|
||||
it('should escape text nodes',
|
||||
() => { expect(xml.serialize([new xml.Text('<>')])).toEqual('<>'); });
|
||||
it('should escape text nodes', () => {
|
||||
expect(xml.serialize([new xml.Text('<>')])).toEqual('<>');
|
||||
});
|
||||
|
||||
it('should serialize xml nodes without children', () => {
|
||||
expect(xml.serialize([new xml.Tag('el', {foo: 'bar'}, [])])).toEqual('<el foo="bar"/>');
|
||||
@ -42,6 +44,5 @@ import * as xml from '../../../src/i18n/serializers/xml_helper';
|
||||
expect(xml.serialize([new xml.Tag('el', {foo: '<">'}, [])]))
|
||||
.toEqual('<el foo="<">"/>');
|
||||
});
|
||||
|
||||
});
|
||||
}
|
@ -117,7 +117,7 @@ import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||
</translationbundle>`;
|
||||
|
||||
// Invalid messages should not cause the parser to throw
|
||||
let i18nNodesByMsgId: {[id: string]: i18n.Node[]} = undefined !;
|
||||
let i18nNodesByMsgId: {[id: string]: i18n.Node[]} = undefined!;
|
||||
expect(() => {
|
||||
i18nNodesByMsgId = serializer.load(XTB, 'url').i18nNodesByMsgId;
|
||||
}).not.toThrow();
|
||||
@ -144,7 +144,9 @@ import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||
<translation></translation>
|
||||
</translationbundle>`;
|
||||
|
||||
expect(() => { loadAsMap(XTB); }).toThrowError(/<translation> misses the "id" attribute/);
|
||||
expect(() => {
|
||||
loadAsMap(XTB);
|
||||
}).toThrowError(/<translation> misses the "id" attribute/);
|
||||
});
|
||||
|
||||
it('should throw when a placeholder has no name attribute', () => {
|
||||
@ -152,7 +154,9 @@ import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||
<translation id="1186013544048295927"><ph /></translation>
|
||||
</translationbundle>`;
|
||||
|
||||
expect(() => { loadAsMap(XTB); }).toThrowError(/<ph> misses the "name" attribute/);
|
||||
expect(() => {
|
||||
loadAsMap(XTB);
|
||||
}).toThrowError(/<ph> misses the "name" attribute/);
|
||||
});
|
||||
|
||||
it('should throw on unknown xtb tags', () => {
|
||||
@ -168,7 +172,9 @@ import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||
<translation id="1186013544048295927"><b>msg should contain only ph tags</b></translation>
|
||||
</translationbundle>`;
|
||||
|
||||
expect(() => { loadAsMap(XTB); })
|
||||
expect(() => {
|
||||
loadAsMap(XTB);
|
||||
})
|
||||
.toThrowError(
|
||||
new RegExp(escapeRegExp(`[ERROR ->]<b>msg should contain only ph tags</b>`)));
|
||||
});
|
||||
@ -184,9 +190,11 @@ import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||
}).toThrowError(/Duplicated translations for msg 1186013544048295927/);
|
||||
});
|
||||
|
||||
it('should throw when trying to save an xtb file',
|
||||
() => { expect(() => { serializer.write([], null); }).toThrowError(/Unsupported/); });
|
||||
|
||||
it('should throw when trying to save an xtb file', () => {
|
||||
expect(() => {
|
||||
serializer.write([], null);
|
||||
}).toThrowError(/Unsupported/);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user