fix(ivy): i18n - throw an error if a translation contains an invalid placeholder (#32867)

Previously if a translation contains a placeholder that
does not exist in the message being translated, that
placeholder is evaluated as `undefined`.

Translations should never contain such placeholder names
so now `translate` will throw a helpful error in instead.

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

View File

@ -80,6 +80,18 @@ describe('utils', () => {
});
describe('translate', () => {
it('should throw an error if there is no matching translation', () => {
expect(() => doTranslate({}, parts `abc`))
.toThrowError('No translation found for "2674653928643152084" ("abc").');
});
it('should throw an error if the translation contains placeholders that are not in the message',
() => {
expect(() => doTranslate({'abc': 'a{$PH}bc'}, parts `abc`))
.toThrowError(
'No placeholder found with name PH in message "2674653928643152084" ("abc").');
});
it('(with identity translations) should render template literals as-is', () => {
const translations = {
'abc': 'abc',