diff --git a/packages/compiler/src/i18n/extractor_merger.ts b/packages/compiler/src/i18n/extractor_merger.ts index 99de2bd10a..4d3ac5a7d8 100644 --- a/packages/compiler/src/i18n/extractor_merger.ts +++ b/packages/compiler/src/i18n/extractor_merger.ts @@ -347,12 +347,13 @@ class _Visitor implements html.Visitor { // translate the attributes of an element and remove i18n specific attributes private _translateAttributes(el: html.Element): html.Attribute[] { const attributes = el.attrs; - const i18nAttributeMeanings: {[name: string]: string} = {}; + const i18nParsedMessageMeta: + {[name: string]: {meaning: string, description: string, id: string}} = {}; attributes.forEach(attr => { if (attr.name.startsWith(_I18N_ATTR_PREFIX)) { - i18nAttributeMeanings[attr.name.slice(_I18N_ATTR_PREFIX.length)] = - _parseMessageMeta(attr.value).meaning; + i18nParsedMessageMeta[attr.name.slice(_I18N_ATTR_PREFIX.length)] = + _parseMessageMeta(attr.value); } }); @@ -364,9 +365,9 @@ class _Visitor implements html.Visitor { return; } - if (attr.value && attr.value != '' && i18nAttributeMeanings.hasOwnProperty(attr.name)) { - const meaning = i18nAttributeMeanings[attr.name]; - const message: i18n.Message = this._createI18nMessage([attr], meaning, '', ''); + if (attr.value && attr.value != '' && i18nParsedMessageMeta.hasOwnProperty(attr.name)) { + const {meaning, description, id} = i18nParsedMessageMeta[attr.name]; + const message: i18n.Message = this._createI18nMessage([attr], meaning, description, id); const nodes = this._translations.get(message); if (nodes) { if (nodes.length == 0) { @@ -377,12 +378,12 @@ class _Visitor implements html.Visitor { } else { this._reportError( el, - `Unexpected translation for attribute "${attr.name}" (id="${this._translations.digest(message)}")`); + `Unexpected translation for attribute "${attr.name}" (id="${id || this._translations.digest(message)}")`); } } else { this._reportError( el, - `Translation unavailable for attribute "${attr.name}" (id="${this._translations.digest(message)}")`); + `Translation unavailable for attribute "${attr.name}" (id="${id || this._translations.digest(message)}")`); } } else { translatedAttributes.push(attr); diff --git a/packages/compiler/test/i18n/extractor_merger_spec.ts b/packages/compiler/test/i18n/extractor_merger_spec.ts index 4ded1d5864..39f6d31288 100644 --- a/packages/compiler/test/i18n/extractor_merger_spec.ts +++ b/packages/compiler/test/i18n/extractor_merger_spec.ts @@ -430,6 +430,11 @@ export function main() { expect(fakeTranslate(HTML)).toEqual('
'); }); + it('should merge attributes with ids', () => { + const HTML = ``; + expect(fakeTranslate(HTML)).toEqual(''); + }); + it('should merge nested attributes', () => { const HTML = `