fix(ivy): i18n - better translation warnings (#32867)

The missing translation and invalid placeholder warnings now contain the
"meaning" if one was provided.

PR Close #32867
This commit is contained in:
Pete Bacon Darwin
2019-10-02 18:17:56 +01:00
committed by atscott
parent 601f87c2ec
commit 97d5700456
2 changed files with 12 additions and 4 deletions

View File

@ -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})`;
}