|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | import {DEFAULT_INTERPOLATION_CONFIG, HtmlParser} from '@angular/compiler';
|
| 10 | +import {MissingTranslationStrategy} from '@angular/core'; |
10 | 11 |
|
11 | 12 | import {digest, serializeNodes as serializeI18nNodes} from '../../src/i18n/digest';
|
12 | 13 | import {extractMessages, mergeTranslations} from '../../src/i18n/extractor_merger';
|
@@ -465,6 +466,31 @@ export function main() {
|
465 | 466 | .toEqual(`<div title="">some element</div>`);
|
466 | 467 | });
|
467 | 468 | });
|
| 469 | + |
| 470 | + describe('no translations', () => { |
| 471 | + it('should remove i18n attributes', () => { |
| 472 | + const HTML = `<p i18n="m|d">foo</p>`; |
| 473 | + expect(fakeNoTranslate(HTML)).toEqual('<p>foo</p>'); |
| 474 | + }); |
| 475 | + |
| 476 | + it('should remove i18n- attributes', () => { |
| 477 | + const HTML = `<p i18n-title="m|d" title="foo"></p>`; |
| 478 | + expect(fakeNoTranslate(HTML)).toEqual('<p title="foo"></p>'); |
| 479 | + }); |
| 480 | + |
| 481 | + it('should remove i18n comment blocks', () => { |
| 482 | + const HTML = `before<!-- i18n --><p>foo</p><span><i>bar</i></span><!-- /i18n -->after`; |
| 483 | + expect(fakeNoTranslate(HTML)).toEqual('before<p>foo</p><span><i>bar</i></span>after'); |
| 484 | + }); |
| 485 | + |
| 486 | + it('should remove nested i18n markup', () => { |
| 487 | + const HTML = |
| 488 | + `<!-- i18n --><span someAttr="ok">foo</span><div>{count, plural, =0 {<p i18n-title title="foo"></p>}}</div><!-- /i18n -->`; |
| 489 | + expect(fakeNoTranslate(HTML)) |
| 490 | + .toEqual( |
| 491 | + '<span someAttr="ok">foo</span><div>{count, plural, =0 {<p title="foo"></p>}}</div>'); |
| 492 | + }); |
| 493 | + }) |
468 | 494 | });
|
469 | 495 | }
|
470 | 496 |
|
@@ -493,10 +519,22 @@ function fakeTranslate(
|
493 | 519 | i18nMsgMap[id] = [new i18n.Text(`**${text}**`, null !)];
|
494 | 520 | });
|
495 | 521 |
|
496 |
| - const translations = new TranslationBundle(i18nMsgMap, null, digest); |
| 522 | + const translationBundle = new TranslationBundle(i18nMsgMap, null, digest); |
| 523 | + const output = mergeTranslations( |
| 524 | + htmlNodes, translationBundle, DEFAULT_INTERPOLATION_CONFIG, implicitTags, implicitAttrs); |
| 525 | + expect(output.errors).toEqual([]); |
| 526 | + |
| 527 | + return serializeHtmlNodes(output.rootNodes).join(''); |
| 528 | +} |
497 | 529 |
|
| 530 | +function fakeNoTranslate( |
| 531 | + content: string, implicitTags: string[] = [], |
| 532 | + implicitAttrs: {[k: string]: string[]} = {}): string { |
| 533 | + const htmlNodes: html.Node[] = parseHtml(content); |
| 534 | + const translationBundle = new TranslationBundle( |
| 535 | + {}, null, digest, undefined, MissingTranslationStrategy.Ignore, console); |
498 | 536 | const output = mergeTranslations(
|
499 |
| - htmlNodes, translations, DEFAULT_INTERPOLATION_CONFIG, implicitTags, implicitAttrs); |
| 537 | + htmlNodes, translationBundle, DEFAULT_INTERPOLATION_CONFIG, implicitTags, implicitAttrs); |
500 | 538 | expect(output.errors).toEqual([]);
|
501 | 539 |
|
502 | 540 | return serializeHtmlNodes(output.rootNodes).join('');
|
|
0 commit comments