diff --git a/packages/localize/src/utils/src/translations.ts b/packages/localize/src/utils/src/translations.ts index 2ad83cd9a075e..4b5c51e3464b4 100644 --- a/packages/localize/src/utils/src/translations.ts +++ b/packages/localize/src/utils/src/translations.ts @@ -68,7 +68,8 @@ export function translate( return message.substitutions[placeholder]; } else { throw new Error( - `No placeholder found with name ${placeholder} in message ${describeMessage(message)}.`); + `There is a placeholder name mismatch with the translation provided for the message ${describeMessage(message)}.\n` + + `The translation contains a placeholder with name ${placeholder}, which does not exist in the message.`); } }) ]; diff --git a/packages/localize/src/utils/test/translations_spec.ts b/packages/localize/src/utils/test/translations_spec.ts index a4f78996596ec..267320534d01e 100644 --- a/packages/localize/src/utils/test/translations_spec.ts +++ b/packages/localize/src/utils/test/translations_spec.ts @@ -88,9 +88,12 @@ describe('utils', () => { it('should throw an error if the translation contains placeholders that are not in the message', () => { - expect(() => doTranslate({'abc': 'a{$PH}bc'}, parts `abc`)) + expect( + () => doTranslate( + {'abc{$INTERPOLATION}def': 'a{$PH}bc'}, parts `abc${1 + 2}:INTERPOLATION:def`)) .toThrowError( - 'No placeholder found with name PH in message "2674653928643152084" ("abc").'); + `There is a placeholder name mismatch with the translation provided for the message "8986527425650846693" ("abc{$INTERPOLATION}def").\n` + + `The translation contains a placeholder with name PH, which does not exist in the message.`); }); it('(with identity translations) should render template literals as-is', () => {