/**
* @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 {Xmb} from '@angular/compiler/src/i18n/serializers/xmb';
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 XMB/XTB integration spec', () => {
describe('(with LF line endings)', () => {
beforeEach(waitForAsync(() => configureCompiler(XTB + LF_LINE_ENDING_XTB, 'xtb')));
it('should extract from templates', () => {
const serializer = new Xmb();
const serializedXmb = serializeTranslations(HTML, serializer);
XMB.forEach(x => {
expect(serializedXmb).toContain(x);
});
expect(serializedXmb).toContain(LF_LINE_ENDING_XMB);
});
it('should translate templates', () => {
const {tb, cmp, el} = createComponent(HTML);
validateHtml(tb, cmp, el);
});
});
describe('(with CRLF line endings', () => {
beforeEach(waitForAsync(() => configureCompiler(XTB + CRLF_LINE_ENDING_XTB, 'xtb')));
it('should extract from templates (with CRLF line endings)', () => {
const serializer = new Xmb();
const serializedXmb = serializeTranslations(HTML.replace(/\n/g, '\r\n'), serializer);
XMB.forEach(x => {
expect(serializedXmb).toContain(x);
});
expect(serializedXmb).toContain(CRLF_LINE_ENDING_XMB);
});
it('should translate templates (with CRLF line endings)', () => {
const {tb, cmp, el} = createComponent(HTML.replace(/\n/g, '\r\n'));
validateHtml(tb, cmp, el);
});
});
});
const XTB = `
attributs i18n sur les balises
imbriqué
imbriqué
avec des espaces réservés
<div>avec <div>des espaces réservés</div> imbriqués</div>
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, male {homme} female {femme} other {autre}}
{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 {<b>beaucoup</b>} }
{VAR_PLURAL, plural, =0 {Pas de réponse} =1 {Une réponse} other {INTERPOLATION réponses} }
FOO<a>BAR</a>
MAP_NAME
`;
const LF_LINE_ENDING_XTB = ``;
const CRLF_LINE_ENDING_XTB = ``;
const XMB = [
`i18n attribute on tags`,
`nested`,
`nested`,
`<i><i>with placeholders</i></i>`,
`<div><div>with <div><div>nested</div></div> placeholders</div></div>`,
`on not translatable node`,
`<b>bold</b>`,
`on translatable node`,
`{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<b><b>many</b></b>} }`,
`
{sex, select, male {...} female {...} other {...}}{sex, select, male {...} female {...} other {...}}
`,
`{VAR_SELECT, select, male {m} female {f} other {other} }`,
`
{sexB, select, male {...} female {...}}{sexB, select, male {...} female {...}}
`,
`{VAR_SELECT, select, male {m} female {f} }`,
`{{ "count = " + count }}{{ "count = " + count }}`,
`sex = {{ sex }}{{ sex }}`,
`{{ "custom name" //i18n(ph="CUSTOM_NAME") }}{{ "custom name" //i18n(ph="CUSTOM_NAME") }}`,
`in a translatable section`,
`
<h1><h1>Markers in html comments</h1></h1>
<div><div></div></div>
<div><div>{count, plural, =0 {...} =1 {...} =2 {...} other {...}}{count, plural, =0 {...} =1 {...} =2 {...} other {...}}</div></div>
`,
`it <b><b>should</b></b> work`,
`with an explicit ID`,
`{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<b><b>many</b></b>} }`,
`{VAR_PLURAL, plural, =0 {Found no results} =1 {Found one result} other {Found {{response.getItemsList().length}}{{response.getItemsList().length}} results} }`,
`foo<a><a>bar</a></a>`,
`{{ 'test' //i18n(ph="map name") }}{{ 'test' //i18n(ph="map name") }}`
];
const LF_LINE_ENDING_XMB = ``;
const CRLF_LINE_ENDING_XMB = ``;