Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@aws-sdk/client-sns": "^3.1079.0",
"@defra/forms-engine-plugin": "^5.0.0-alpha.5",
"@defra/forms-engine-plugin": "^5.0.0-alpha.7",
"@defra/forms-model": "^3.0.686",
"@defra/hapi-tracing": "^1.30.0",
"@elastic/ecs-pino-format": "^1.5.0",
Expand Down
1 change: 1 addition & 0 deletions src/server/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export const PREVIEW_PATH_PREFIX = '/preview'
export const ERROR_PREVIEW_PATH_PREFIX = '/error-preview'
export const FORM_PREFIX = '/form'
export const SAVE_AND_EXIT_PAYLOAD = 'SAVE_AND_EXIT_PAYLOAD'
export const EN_GB = 'en-GB'
3 changes: 2 additions & 1 deletion src/server/i18n/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { type i18n } from 'i18next'
import { LRUCache } from 'lru-cache'

import { EN_GB } from '~/src/server/constants.js'
import {
createFormI18nInstance,
extractMetadataBaseTranslations,
Expand Down Expand Up @@ -107,7 +108,7 @@ export function createFormTranslator(
export function createTranslator(
i18nInstance: i18n,
languages: { name: string; code: string }[],
language = 'en-GB'
language = EN_GB
): Translator {
const t = (key: string, opts?: Record<string, unknown>): string =>
i18nInstance.t(key, { lng: language, ...opts })
Expand Down
5 changes: 2 additions & 3 deletions src/server/i18n/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type FormDefinition } from '@defra/forms-model'
import { type Request } from '@hapi/hapi'
import { type i18n } from 'i18next'

import { EN_GB } from '~/src/server/constants.js'
import { extractTranslations, t } from '~/src/server/i18n/index.js'
import { resolveLanguage } from '~/src/server/utils/utils.js'

Expand Down Expand Up @@ -29,9 +30,7 @@ describe('Runner i18n', () => {
describe('resolveLanguage()', () => {
it('returns the default language', () => {
const blankRequest = {} as unknown as Request
expect(resolveLanguage(blankRequest.query, blankRequest.yar)).toBe(
'en-GB'
)
expect(resolveLanguage(blankRequest.query, blankRequest.yar)).toBe(EN_GB)
})

it('returns the language set in the session', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/server/i18n/translations/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@
"title": "Statws y gwasanaeth"
},
"phaseBanner": {
"alphaStage": "Alffa",
"betaStage": "Beta",
"feedbackLinkNewTab": "rhowch eich adborth (yn agor mewn tab newydd)",
"feedbackLinkEmail": "rhowch eich adborth drwy e-bost",
"text": "Gwasanaeth newydd yw hwn. Helpwch ni i'w wella a [[feedbackLink]]."
Expand Down
2 changes: 2 additions & 0 deletions src/server/i18n/translations/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@
"title": "Service status"
},
"phaseBanner": {
"alphaStage": "Alpha",
"betaStage": "Beta",
"feedbackLinkNewTab": "give your feedback (opens in new tab)",
"feedbackLinkEmail": "give your feedback by email",
"text": "This is a new service. Help us improve it and [[feedbackLink]]."
Expand Down
3 changes: 2 additions & 1 deletion src/server/models/save-and-exit.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EN_GB } from '~/src/server/constants.js'
import { createFormTranslator } from '~/src/server/i18n/form.js'
import { lockedOutViewModel } from '~/src/server/models/save-and-exit.js'

Expand All @@ -12,7 +13,7 @@ describe('Save and exit models', () => {
})

const definition = /** @type {FormDefinition} */ ({})
const translator = createFormTranslator(form, definition, 'en-GB')
const translator = createFormTranslator(form, definition, EN_GB)

test('should construct live resume url', () => {
const link = /** @type {SaveAndExitResumeDetails} */ ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@defra/forms-model'
import { type ResponseObject } from '@hapi/hapi'

import { EN_GB } from '~/src/server/constants.js'
import {
SummaryPageWithConfirmationEmailController,
getUserConfirmationEmailAddress
Expand All @@ -41,7 +42,7 @@ describe('SummaryPageWithConfirmationEmailController', () => {
basePath: 'test'
})

translator = model.createTranslator('en-GB')
translator = model.createTranslator(EN_GB)

// Create a mock page for SummaryPageWithConfirmationEmailController
const mockPage = {
Expand All @@ -61,7 +62,7 @@ describe('SummaryPageWithConfirmationEmailController', () => {
},
query: {},
app: { model }
} as unknown as FormRequest)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

} as FormRequest)
})

describe('handle errors', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/server/plugins/nunjucks/context.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { tmpdir } from 'node:os'

import { config } from '~/src/config/index.js'
import { EN_GB } from '~/src/server/constants.js'
import { context } from '~/src/server/plugins/nunjucks/context.js'

describe('Nunjucks context', () => {
Expand Down Expand Up @@ -123,7 +124,7 @@ describe('Nunjucks context', () => {
query: {},
response: { statusCode: 200 },
state: {},
app: { language: 'en-GB' },
app: { language: EN_GB },
path: '/test',
url: { search: '' },
plugins: {}
Expand Down
3 changes: 2 additions & 1 deletion src/server/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getTraceId } from '@defra/hapi-tracing'

import { config } from '~/src/config/index.js'
import { EN_GB } from '~/src/server/constants.js'

/**
* Returns a set of headers to use in an HTTP request, merging them with any existing headers in options.
Expand Down Expand Up @@ -37,7 +38,7 @@ export function getFeedbackFormLink(formId) {
* @returns {string} - the resolved language code
*/
export function resolveLanguage(query, yar) {
const defaultLang = 'en-GB'
const defaultLang = EN_GB

query ??= {}

Expand Down
3 changes: 2 additions & 1 deletion src/server/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@
{% endif %}
{%- endset %}

{% set stageKey = 'layout.phaseBanner.' + phaseTag + 'Stage' %}
{{ govukPhaseBanner({
tag: { text: phaseTag | capitalize },
tag: { text: tR(stageKey) | capitalize },
html: tR('layout.phaseBanner.text', { feedbackLink: feedbackLinkHtml })
}) }}
{% endif %}
Expand Down
3 changes: 2 additions & 1 deletion test/form/confirmation-email.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ describe('Confirmation email', () => {
repeaters: [],
retrievalKey: 'enrique.chase@defra.gov.uk',
sessionId: expect.any(String),
referenceNumber: expect.any(String)
referenceNumber: expect.any(String),
language: undefined
})

expect(response.statusCode).toBe(StatusCodes.SEE_OTHER)
Expand Down
Loading