/**
* @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 {Xliff2} from '@angular/compiler/src/i18n/serializers/xliff2';
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(XLIFF2_TOMERGE + LF_LINE_ENDING_XLIFF2_TOMERGE, 'xlf2')));
it('should extract from templates', () => {
const serializer = new Xliff2();
const serializedXliff2 = serializeTranslations(HTML, serializer);
XLIFF2_EXTRACTED.forEach(x => {
expect(serializedXliff2).toContain(x);
});
expect(serializedXliff2).toContain(LF_LINE_ENDING_XLIFF2_EXTRACTED);
});
it('should translate templates', () => {
const {tb, cmp, el} = createComponent(HTML);
validateHtml(tb, cmp, el);
});
});
describe('(with CRLF line endings', () => {
beforeEach(waitForAsync(
() => configureCompiler(XLIFF2_TOMERGE + CRLF_LINE_ENDING_XLIFF2_TOMERGE, 'xlf2')));
it('should extract from templates (with CRLF line endings)', () => {
const serializer = new Xliff2();
const serializedXliff = serializeTranslations(HTML.replace(/\n/g, '\r\n'), serializer);
XLIFF2_EXTRACTED.forEach(x => {
expect(serializedXliff).toContain(x);
});
expect(serializedXliff).toContain(CRLF_LINE_ENDING_XLIFF2_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 XLIFF2_TOMERGE = `
i18n attribute on tags
attributs i18n sur les balises
nested
imbriqué
nested
imbriqué
with placeholders
avec des espaces réservés
file.ts:11
with nested placeholders
avec espaces réservés imbriqués
on not translatable node
sur des balises non traductibles
<b>bold</b>
<b>gras</b>
on translatable node
sur des balises traductibles
{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {many} }
{VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {beaucoup} }
file.ts:23
{VAR_SELECT, select, other {other} male {m} female {female} }
{VAR_SELECT, select, other {autre} male {homme} female {femme} }
file.ts:25,27
{VAR_SELECT, select, male {m} female {f} }
{VAR_SELECT, select, male {homme} female {femme} }
sex =
sexe =
in a translatable section
dans une section traductible
Markers in html comments
Balises dans les commentaires html
it should work
ca devrait marcher
with an explicit ID
avec un ID explicite
{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {many} }
{VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {beaucoup} }
foobar
FOOBAR
`;
const LF_LINE_ENDING_XLIFF2_TOMERGE = `
{VAR_PLURAL, plural, =0 {Found no results} =1 {Found one result} other {Found results} }
{VAR_PLURAL, plural, =0 {Pas de réponse} =1 {Une réponse} other { réponses} }
`;
const CRLF_LINE_ENDING_XLIFF2_TOMERGE = `
{VAR_PLURAL, plural, =0 {Found no results} =1 {Found one result} other {Found results} }
{VAR_PLURAL, plural, =0 {Pas de réponse} =1 {Une réponse} other { réponses} }
`;
const XLIFF2_EXTRACTED = [
`
file.ts:3
i18n attribute on tags
`,
`
file.ts:5
nested
`,
`
different meaning
file.ts:7
nested
`,
`
file.ts:9
file.ts:10
with placeholders
`,
`
file.ts:11
with nested placeholders
`,
`
file.ts:14
on not translatable node
`,
`
file.ts:14
<b>bold</b>
`,
`
file.ts:15
on translatable node
`,
`
file.ts:20
file.ts:37
{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {many} }
`,
`
file.ts:22,24
`,
`
file.ts:23
{VAR_SELECT, select, male {m} female {f} other {other} }
`,
`
file.ts:25,27
`,
`
file.ts:26
{VAR_SELECT, select, male {m} female {f} }
`,
`
file.ts:29
`,
`
file.ts:30
sex =
`,
`
file.ts:31
`,
`
file.ts:36
file.ts:54
in a translatable section
`,
`
file.ts:34,38
Markers in html comments
`,
`
file.ts:40
it should work
`,
`
file.ts:42
with an explicit ID
`,
`
file.ts:43
{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {many} }
`,
`
file.ts:54
foobar
`,
`
file.ts:56
`
];
const LF_LINE_ENDING_XLIFF2_EXTRACTED = `
desc
file.ts:46,52
{VAR_PLURAL, plural, =0 {Found no results} =1 {Found one result} other {Found results} }
`;
const CRLF_LINE_ENDING_XLIFF2_EXTRACTED = `
desc
file.ts:46,52
{VAR_PLURAL, plural, =0 {Found no results} =1 {Found one result} other {Found results} }
`;