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:

committed by
atscott

parent
052cae6427
commit
601f87c2ec
@ -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',
|
||||
|
Reference in New Issue
Block a user