Skip to content

Commit

Permalink
Merge branch 'main' into OLH-2437
Browse files Browse the repository at this point in the history
  • Loading branch information
saralk authored Feb 20, 2025
2 parents d8a2064 + b5535dd commit de50c97
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 18 deletions.
2 changes: 1 addition & 1 deletion clients/dfeApplyForTeacherTraining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const dfeApplyForTeacherTraining: Client = {
description: "Apply for a teacher training course to teach in England.",
linkText: "Go to your Apply for teacher training account",
linkUrl:
"https://www.apply-for-teacher-training.service.gov.uk/candidate/",
"https://www.apply-for-teacher-training.service.gov.uk/candidate/account",
},
},
};
Expand Down
9 changes: 9 additions & 0 deletions clients/hmrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ const hmrc: Client = {
header: "A service run by HM Revenue and Customs (HMRC)",
linkText: "Find the HMRC service you need",
linkUrl: "https://www.gov.uk/government/organisations/hm-revenue-customs",
hintText: "For example services about tax, childcare, or state pensions.",
paragraph1:
"At the moment, GOV.UK One Login cannot show you which HMRC service you’ve used.",
paragraph2: "We’re working to make this possible.",
},
cy: {
header: "Gwasanaeth a weithredir gan Gyllid a Thollau EF (CThEF)",
linkText: "Dod o hyd i wasanaeth CThEF rydych ei angen",
linkUrl:
"https://www.gov.uk/government/organisations/hm-revenue-customs.cy",
hintText:
"Er enghraifft gwasanaethau am dreth, gofal plant, neu bensiynau'r wladwriaeth.",
paragraph1:
"Ar hyn o bryd, ni all GOV.UK One Login ddangos i chi pa wasanaeth CThEF rydych wedi'i ddefnyddio.",
paragraph2: "Rydym yn gweithio i wneud hyn yn bosibl.",
},
},
};
Expand Down
3 changes: 3 additions & 0 deletions interfaces/client.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ interface Translations {
description?: string;
linkText: string;
linkUrl: EnvironmentValue<string>;
hintText?: string;
paragraph1?: string;
paragraph2?: string;
}

interface BaseClient {
Expand Down
3 changes: 3 additions & 0 deletions interfaces/translations.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export interface Translation {
description?: string;
link_text: string;
link_href: string;
hint_text?: string;
paragraph1?: string;
paragraph2?: string;
}

export type TranslationsObject = Record<string, Translation>;
11 changes: 4 additions & 7 deletions scripts/generate
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
#!/usr/bin/env bun
import { writeFileSync, readFileSync } from "fs";
import { Client } from "../interfaces/client.interface";
import { Translation } from '../interfaces/translations.interface'
import {
getAllowedAccountListClientIDs,
clientsToShowInSearchProd,
hmrcClientIds,
rsaAllowList,
} from "../../di-account-management-frontend/src/config";

interface Translation {
header: string;
description?: string;
link_text: string;
link_href: string;
}

interface IDs {
production: string;
integration: string;
Expand Down Expand Up @@ -88,6 +82,9 @@ function transformTranslate(
description: client.description,
linkText: client.link_text,
linkUrl: generateLinkObject(ids, language),
...client.hint_text && { hintText: client.hint_text },
...client.paragraph1 && { paragraph1: client.paragraph1 },
...client.paragraph2 && { paragraph2: client.paragraph2 },
};
}

Expand Down
5 changes: 4 additions & 1 deletion src/get-translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const convertToTranslation = (translations: Client["translations"]["en"], enviro
header: translations.header,
link_text: translations.linkText,
link_href: getValueForEnvironment(environment, translations.linkUrl),
description: translations.description || undefined
...translations.description && { description: translations.description },
...translations.hintText && { hint_text: translations.hintText },
...translations.paragraph1 && { paragraph1: translations.paragraph1 },
...translations.paragraph2 && { paragraph2: translations.paragraph2 }
}
}

Expand Down
60 changes: 51 additions & 9 deletions tests/get-translations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jest.mock('../clients', () => ({
header: 'header en',
linkText: 'link text en',
linkUrl: 'link url en',
description: 'description en'
},
cy: {
header: 'header cy',
Expand All @@ -19,7 +18,6 @@ jest.mock('../clients', () => ({
production: 'link url cy production',
nonProduction: 'link url cy non production'
},
description: 'description cy'
}
},
clientId: 'welshClient',
Expand All @@ -45,58 +43,102 @@ jest.mock('../clients', () => ({
isHmrc: false,
isReportSuspiciousActivityEnabled: false,
showInClientSearch: true
},
hmrcClient: {
isAvailableInWelsh: false,
translations: {
en: {
header: 'header en',
linkText: 'link text en',
linkUrl: 'link url en',
description: 'description en',
hintText: 'hint text en',
paragraph1: 'paragraph 1 en',
paragraph2: 'paragraph 2 en'
},
},
clientId: 'englishClient',
clientType: 'account',
isAllowed: true,
isHmrc: false,
isReportSuspiciousActivityEnabled: false,
showInClientSearch: true
}
}));

describe('getTranslations', () => {
test('should return translations in english', async () => {
const translations = getTranslations('test', 'en');
expect(translations).toEqual({
expect(translations).toStrictEqual({
cyClient: {
header: 'header en',
link_text: 'link text en',
link_href: 'link url en',
description: 'description en'
},
enClient: {
header: 'header en',
link_text: 'link text en',
link_href: 'link url en',
description: 'description en'
}
},
hmrcClient: {
description: "description en",
header: "header en",
hint_text: "hint text en",
link_href: "link url en",
link_text: "link text en",
paragraph1: "paragraph 1 en",
paragraph2: "paragraph 2 en",
},
});
});
test('should return transaltions in welsh', async () => {
const translations = getTranslations('test', 'cy');
expect(translations).toEqual({
expect(translations).toStrictEqual({
cyClient: {
header: 'header cy',
link_text: 'link text cy',
link_href: 'link url cy non production',
description: 'description cy'
},
enClient: {
header: 'header en',
link_text: 'link text en',
link_href: 'link url en',
description: 'description en'
},
hmrcClient: {
description: "description en",
header: "header en",
hint_text: "hint text en",
link_href: "link url en",
link_text: "link text en",
paragraph1: "paragraph 1 en",
paragraph2: "paragraph 2 en",
}
});
})
test('should return correct environment varialbes', async () => {
const translations = getTranslations('production', 'cy');
expect(translations).toEqual({
expect(translations).toStrictEqual({
cyClient: {
header: 'header cy',
link_text: 'link text cy',
link_href: 'link url cy production',
description: 'description cy'
},
enClient: {
header: 'header en',
link_text: 'link text en',
link_href: 'link url en',
description: 'description en'
},
hmrcClient: {
description: "description en",
header: "header en",
hint_text: "hint text en",
link_href: "link url en",
link_text: "link text en",
paragraph1: "paragraph 1 en",
paragraph2: "paragraph 2 en",
}
});
})
Expand Down

0 comments on commit de50c97

Please sign in to comment.