From dd68ae3ef18ac43538f0293a97018d3d633f0dbd Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 5 Aug 2016 14:45:47 -0700 Subject: [PATCH] feat(ExtractorMerger): ignore implicit tags in translatable sections --- .../compiler/src/i18n/extractor_merger.ts | 3 +- .../test/i18n/extractor_merger_spec.ts | 47 +++++++++++++------ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/modules/@angular/compiler/src/i18n/extractor_merger.ts b/modules/@angular/compiler/src/i18n/extractor_merger.ts index 71a1f614f3..13e6868f72 100644 --- a/modules/@angular/compiler/src/i18n/extractor_merger.ts +++ b/modules/@angular/compiler/src/i18n/extractor_merger.ts @@ -211,7 +211,8 @@ class _Visitor implements html.Visitor { // Extract only top level nodes with the (implicit) "i18n" attribute if not in a block or an ICU // message const i18nAttr = _getI18nAttr(el); - const isImplicit = this._implicitTags.some((tag: string): boolean => el.name === tag); + const isImplicit = this._implicitTags.some((tag: string): boolean => el.name === tag) && + !this._inIcu && !this._isInTranslatableSection; const isTopLevelImplicit = !wasInImplicitNode && isImplicit; this._inImplicitNode = this._inImplicitNode || isImplicit; diff --git a/modules/@angular/compiler/test/i18n/extractor_merger_spec.ts b/modules/@angular/compiler/test/i18n/extractor_merger_spec.ts index b09da17d4f..ddd8ca8c18 100644 --- a/modules/@angular/compiler/test/i18n/extractor_merger_spec.ts +++ b/modules/@angular/compiler/test/i18n/extractor_merger_spec.ts @@ -54,6 +54,12 @@ export function main() { it('should not create a message for empty elements', () => { expect(extract('
')).toEqual([]); }); + + it('should ignore implicit elements in translatable elements', () => { + expect(extract('

', ['p'])).toEqual([ + [[''], 'm', 'd'] + ]); + }); }); describe('blocks', () => { @@ -68,6 +74,13 @@ export function main() { ]); }); + it('should ignore implicit elements in blocks', () => { + expect(extract('

', ['p'])).toEqual([ + [[''], 'm', 'd'] + ]); + }); + + it('should extract siblings', () => { expect( extract( @@ -141,12 +154,30 @@ export function main() { it('should not extract ICU messages outside of i18n sections', () => { expect(extract('{count, plural, =0 {text}}')).toEqual([]); }); - it('should not extract nested ICU messages', () => { + it('should ignore nested ICU messages', () => { expect(extract('
{count, plural, =0 { {sex, gender, =m {m}} }}
')) .toEqual([ [['{count, plural, =0 {[{sex, gender, =m {[m]}}, ]}}'], 'm', 'd'], ]); }); + + it('should ignore implicit elements in non translatable ICU messages', () => { + expect( + extract( + '
{count, plural, =0 { {sex, gender, =m {

ignore

}} }}
', + ['p'])) + .toEqual([[ + [ + '{count, plural, =0 {[{sex, gender, =m {[ignore]}}, ]}}' + ], + 'm', 'd' + ]]); + }); + + it('should ignore implicit elements in non translatable ICU messages', () => { + expect(extract('{count, plural, =0 { {sex, gender, =m {

ignore

}} }}', ['p'])) + .toEqual([]); + }); }); describe('attributes', () => { @@ -297,20 +328,6 @@ export function main() { ]); }); }); - - describe('implicit elements', () => { - it('should report implicit element in translatable element', () => { - expect(extractErrors(`

`, ['b'])).toEqual([ - ['Could not mark an element as translatable inside a translatable section', ''], - ]); - }); - - it('should report implicit element in translatable blocks', () => { - expect(extractErrors(``, ['b'])).toEqual([ - ['Could not mark an element as translatable inside a translatable section', ''], - ]); - }); - }); }); });