diff --git a/packages/localize/src/utils/translations.ts b/packages/localize/src/utils/translations.ts index 4dd5a2ba79..616de96482 100644 --- a/packages/localize/src/utils/translations.ts +++ b/packages/localize/src/utils/translations.ts @@ -6,7 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ import {BLOCK_MARKER} from './constants'; -import {MessageId, TargetMessage, parseMessage} from './messages'; +import {MessageId, ParsedMessage, TargetMessage, parseMessage} from './messages'; + /** * A translation message that has been processed to extract the message parts and placeholders. @@ -49,13 +50,12 @@ export function translate( return message.substitutions[placeholder]; } else { throw new Error( - `No placeholder found with name ${placeholder} in message "${message.messageId}" ("${message.messageString}").`); + `No placeholder found with name ${placeholder} in message ${describeMessage(message)}.`); } }) ]; } else { - throw new Error( - `No translation found for "${message.messageId}" ("${message.messageString}").`); + throw new Error(`No translation found for ${describeMessage(message)}.`); } } @@ -90,3 +90,9 @@ export function makeTemplateObject(cooked: string[], raw: string[]): TemplateStr Object.defineProperty(cooked, 'raw', {value: raw}); return cooked as any; } + + +function describeMessage(message: ParsedMessage): string { + const meaningString = message.meaning && ` - "${message.meaning}"`; + return `"${message.messageId}" ("${message.messageString}"${meaningString})`; +} \ No newline at end of file diff --git a/packages/localize/test/utils/translations_spec.ts b/packages/localize/test/utils/translations_spec.ts index a6ce5083af..89c98884aa 100644 --- a/packages/localize/test/utils/translations_spec.ts +++ b/packages/localize/test/utils/translations_spec.ts @@ -83,6 +83,8 @@ describe('utils', () => { it('should throw an error if there is no matching translation', () => { expect(() => doTranslate({}, parts `abc`)) .toThrowError('No translation found for "2674653928643152084" ("abc").'); + expect(() => doTranslate({}, parts `:meaning|:abc`)) + .toThrowError('No translation found for "1071947593002928768" ("abc" - "meaning").'); }); it('should throw an error if the translation contains placeholders that are not in the message',