/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Xliff} from '@angular/compiler/src/i18n/serializers/xliff';
import {waitForAsync} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {configureCompiler, createComponent, HTML, serializeTranslations, validateHtml} from './integration_common';
describe('i18n XLIFF integration spec', () => {
describe('(with LF line endings)', () => {
beforeEach(
waitForAsync(() => configureCompiler(XLIFF_TOMERGE + LF_LINE_ENDING_XLIFF_TOMERGE, 'xlf')));
it('should extract from templates', () => {
const serializer = new Xliff();
const serializedXliff = serializeTranslations(HTML, serializer);
XLIFF_EXTRACTED.forEach(x => {
expect(serializedXliff).toContain(x);
});
expect(serializedXliff).toContain(LF_LINE_ENDING_XLIFF_EXTRACTED);
});
it('should translate templates', () => {
const {tb, cmp, el} = createComponent(HTML);
validateHtml(tb, cmp, el);
});
});
describe('(with CRLF line endings', () => {
beforeEach(waitForAsync(
() => configureCompiler(XLIFF_TOMERGE + CRLF_LINE_ENDING_XLIFF_TOMERGE, 'xlf')));
it('should extract from templates (with CRLF line endings)', () => {
const serializer = new Xliff();
const serializedXliff = serializeTranslations(HTML.replace(/\n/g, '\r\n'), serializer);
XLIFF_EXTRACTED.forEach(x => {
expect(serializedXliff).toContain(x);
});
expect(serializedXliff).toContain(CRLF_LINE_ENDING_XLIFF_EXTRACTED);
});
it('should translate templates (with CRLF line endings)', () => {
const {tb, cmp, el} = createComponent(HTML.replace(/\n/g, '\r\n'));
validateHtml(tb, cmp, el);
});
});
});
const XLIFF_TOMERGE = `
attributs i18n sur les balises
imbriqué
imbriqué
different meaning
avec des espaces réservés
with nested placeholders
file.ts
11
sur des balises non traductibles
<b>gras</b>
sur des balises traductibles
{VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {beaucoup} }
{VAR_SELECT, select, other {autre} male {homme} female {femme}}
{VAR_SELECT, select, male {homme} female {femme} }
sexe =
dans une section traductible
Balises dans les commentaires html
ca devrait marcher
avec un ID explicite
{VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {beaucoup} }
FOOBAR
`;
const LF_LINE_ENDING_XLIFF_TOMERGE =
`
{VAR_PLURAL, plural, =0 {Pas de réponse} =1 {Une réponse} other { réponses} }
desc
`;
const CRLF_LINE_ENDING_XLIFF_TOMERGE =
`
{VAR_PLURAL, plural, =0 {Pas de réponse} =1 {Une réponse} other { réponses} }
desc
`;
const XLIFF_EXTRACTED: string[] = [
`
file.ts
3
`,
`
file.ts
5
`,
`
file.ts
7
different meaning
`,
`
file.ts
9
file.ts
10
`,
`
file.ts
11
`,
`
file.ts
14
`,
`
file.ts
14
`,
`
file.ts
15
`,
`
file.ts
20
file.ts
37
`,
`
file.ts
22
`,
`
file.ts
23
`,
`
file.ts
25
`,
`
file.ts
26
`,
`
file.ts
29
`,
`
file.ts
30
`,
`
file.ts
31
`,
`
file.ts
36
file.ts
54
`,
`
file.ts
34
`,
`
file.ts
40
`,
`
file.ts
42
`,
`
file.ts
43
`,
`
file.ts
54
`,
`
file.ts
56
`
];
const LF_LINE_ENDING_XLIFF_EXTRACTED =
`
file.ts
46
desc
`;
const CRLF_LINE_ENDING_XLIFF_EXTRACTED =
`
file.ts
46
desc
`;