From fc4379f3928adebaee2c5e9cd2ca058d87fea009 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Thu, 14 Sep 2023 16:29:15 +0200 Subject: [PATCH] [CL-128] Support placeholders in i18n mock (#6254) --- .../src/form-field/error-summary.stories.ts | 6 +++--- libs/components/src/utils/i18n-mock.service.ts | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libs/components/src/form-field/error-summary.stories.ts b/libs/components/src/form-field/error-summary.stories.ts index 95061df81b..4e1031abaf 100644 --- a/libs/components/src/form-field/error-summary.stories.ts +++ b/libs/components/src/form-field/error-summary.stories.ts @@ -24,7 +24,7 @@ export default { required: "required", inputRequired: "Input is required.", inputEmail: "Input is not an email-address.", - fieldsNeedAttention: "$COUNT$ field(s) above need your attention.", + fieldsNeedAttention: "__$1__ field(s) above need your attention.", }); }, }, @@ -63,12 +63,12 @@ export const Default: StoryObj = { Name - + Email - + diff --git a/libs/components/src/utils/i18n-mock.service.ts b/libs/components/src/utils/i18n-mock.service.ts index 25e9a6db67..1dcc84b4a9 100644 --- a/libs/components/src/utils/i18n-mock.service.ts +++ b/libs/components/src/utils/i18n-mock.service.ts @@ -12,8 +12,20 @@ export class I18nMockService implements I18nService { constructor(private lookupTable: Record string)>) {} t(id: string, p1?: string, p2?: string, p3?: string) { - const value = this.lookupTable[id]; + let value = this.lookupTable[id]; if (typeof value == "string") { + if (value !== "") { + if (p1 != null) { + value = value.split("__$1__").join(p1.toString()); + } + if (p2 != null) { + value = value.split("__$2__").join(p2.toString()); + } + if (p3 != null) { + value = value.split("__$3__").join(p3.toString()); + } + } + return value; } return value(p1, p2, p3);