Skip to content
7 changes: 6 additions & 1 deletion src/server/plugins/engine/components/PaymentField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class PaymentField extends FormComponent {
declare options: PaymentFieldComponent['options']
declare formSchema: ObjectSchema
declare stateSchema: ObjectSchema
declare def: PaymentFieldComponent
isAppendageStateSingleObject = true

constructor(
Expand All @@ -54,6 +55,7 @@ export class PaymentField extends FormComponent {
super(def, props)

this.options = def.options
this.def = def

const paymentStateSchema = joi
.object({
Expand Down Expand Up @@ -110,6 +112,8 @@ export class PaymentField extends FormComponent {
getViewModel(context: RenderContext) {
const { payload } = context
const viewModel = super.getViewModel(context)
const { translator } = context
const { tComponent } = translator

// Payload is pre-populated from state if a payment has already been made
const paymentState = this.isPaymentState(payload[this.name] as unknown)
Expand All @@ -124,7 +128,8 @@ export class PaymentField extends FormComponent {
return {
...viewModel,
amount: formatCurrency(amount),
description: this.options.description,
description:
tComponent(this.def, 'paymentDescription') || this.options.description,
paymentState
}
}
Expand Down
22 changes: 21 additions & 1 deletion src/server/plugins/engine/i18n/createFormTranslator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { type FormDefinition } from '@defra/forms-model'
import {
yesNoListNoItemId,
yesNoListYesItemId,
type FormDefinition
} from '@defra/forms-model'
import { type i18n } from 'i18next'

import { createTranslator } from '~/src/server/plugins/engine/i18n/createTranslator.js'
Expand Down Expand Up @@ -28,6 +32,22 @@ export function loadFormTranslations(def: FormDefinition, i18nInstance: i18n) {
if (formTranslations) {
for (const [lng, resources] of Object.entries(formTranslations)) {
i18nInstance.addResourceBundle(lng, 'form', resources, true, true)

// Temporary workaround - until we develop a better solution
if (lng === 'cy') {
i18nInstance.addResource(
lng,
'form',
`listItems.${yesNoListYesItemId}.text`,
'Ie'
)
i18nInstance.addResource(
lng,
'form',
`listItems.${yesNoListNoItemId}.text`,
'Nage'

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.

Is it Nage or Na? Or even Naddo? Google Translate says Na for Yes/No and my favourite AI reckons it's context sensitive as to which of the three it might be 😂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, Alex asked his AI and the generic Yes/No was the options I've coded. It can change depending on context, hence the temporary fixed solution for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Gemini tells me:

Welsh is famous for not having a single, universal word for "yes" or "no" because it usually repeats the verb used in the question. However, if you just need a generic, "catch-all" option for a quick message that people will understand, here is the best way to do it:
The Generic Option
Yes = Ie (pronounced ee-eh)
No = Nage (pronounced nah-geh, with a hard 'g')

)
}
}
}
}
18 changes: 16 additions & 2 deletions src/server/plugins/engine/i18n/translations/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"body": "Os hoffech dderbyn e-bost prawf, [[link]] yr hoffech i gyflwyniadau ffurflen fynd iddo.",
"linkText": "nodwch y cyfeiriad e-bost (yn agor mewn tab newydd)"
},
"bannerTitle": "Pwysig",
"bannerForce": "Rhagolwg o ffurflen [[previewMode]] yw hon. Peidiwch â rhoi gwybodaeth bersonol.",
"bannerText": "Dyma ragolwg o dudalen ffurflen [[previewMode]] rydych chi'n ei golygu.",
"previousPages": "Mae'n dibynnu ar atebion o dudalennau cynharach yn y ffurflen. Yn y fersiwn fyw, bydd angen i ddefnyddwyr gwblhau'r cwestiynau hynny yn gyntaf."
Expand Down Expand Up @@ -220,7 +221,7 @@

"yesNoField": {
"yes": "Ie",
"no": "Na",
"no": "Nage",
"validation": {
"selectYesNoRequired": "{{#label}} - dewiswch ie neu na"
}
Expand All @@ -245,7 +246,7 @@
},

"paymentField": {
"detailsRequired": "Angen manylion talu",
"detailsRequired": "Angen talu",
"pendingTransaction": "Mae'n bosibl y gwelwch drafodiad ar y gweill yn eich cyfrif banc ond dim ond pan fyddwch yn cyflwyno'r ffurflen y codir tâl arnoch.",
"addPaymentDetails": "Ychwanegu manylion talu",
"cannotTakePayment": "Mae problem ac ni allwn dderbyn taliad. Cysylltwch â ni (manylion yn nhroedyn y ffurflen hon) neu cadwch eich cynnydd a dychwelyd at y ffurflen yn ddiweddarach.",
Expand All @@ -266,6 +267,19 @@
"uploadedFilesHeading": "Ffeiliau a uwchlwythwyd",
"filesCount_one": "Uwchlwythwyd [[count]] ffeil",
"filesCount_other": "Uwchlwythwyd [[count]] ffeil"
},

"characterCount": {
"_comment": "Note the use of %{count} instead of [[count]]. This is because we are passing to the govuk template, not passing to Joi",
"underLimit": {
"one": "Mae gennych %{count} nod ar ôl",
"other": "Mae gennych %{count} nod ar ôl"
Comment on lines +275 to +276

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.

can you just check the syntax for this? I notice in line 268 we use [[count]] whereas here we're using %{count}

},
"atLimit": "Mae gennych 0 nod ar ôl",
"overLimit": {
"one": "Mae gennych %{count} nod yn ormod",
"other": "Mae gennych %{count} nod yn ormod"
Comment on lines +280 to +281

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 above

}
}
}
}
16 changes: 15 additions & 1 deletion src/server/plugins/engine/i18n/translations/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"body": "If you want to receive a test email, [[link]] you want form submissions to go to.",
"linkText": "enter the email address (opens in new tab)"
},
"bannerTitle": "Important",
"bannerForce": "This is a preview of a [[previewMode]] form. Do not enter personal information.",
"bannerText": "This is a preview of a [[previewMode]] form page you are editing.",
"previousPages": "It depends on answers from earlier pages in the form. In the live version, users will need to complete those questions first."
Expand Down Expand Up @@ -245,7 +246,7 @@
},

"paymentField": {
"detailsRequired": "Payment details required",
"detailsRequired": "Payment required",
"pendingTransaction": "You may see a pending transaction in your bank account but you will only be charged when you submit the form.",
"addPaymentDetails": "Add payment details",
"cannotTakePayment": "There is a problem and we cannot take a payment. Contact us (details in the footer of this form) or save your progress and return to the form later.",
Expand All @@ -266,6 +267,19 @@
"uploadedFilesHeading": "Uploaded files",
"filesCount_one": "[[count]] file uploaded",
"filesCount_other": "[[count]] files uploaded"
},

"characterCount": {
"_comment": "Note the use of %{count} instead of [[count]]. This is because we are passing to the govuk template, not passing to Joi",
"underLimit": {
"one": "You have %{count} character remaining",
"other": "You have %{count} characters remaining"
},
"atLimit": "You have 0 characters remaining",
"overLimit": {
"one": "You have %{count} character too many",
"other": "You have %{count} characters too many"
}
}
}
}
1 change: 1 addition & 0 deletions src/server/plugins/engine/i18n/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type FormDefinitionTranslations = Record<
hint: string
content: string
shortDescription: string
paymentDescription: string
}>
>
sections: Record<string, Partial<Pick<Section, 'title'>>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,14 @@ export class QuestionPageController extends PageController {
if (!pageTitle) {
pageTitle = labelOrLegend.text
}
labelOrLegend.text = isOptional
? `${pageTitle} ${t('common.optional')}`
: pageTitle

// The question text may have already appended 'optional' in the relevant language
const optionalWord = t('common.optional')
const optionalAlreadyAppended = pageTitle.endsWith(` ${optionalWord}`)
labelOrLegend.text =
isOptional && !optionalAlreadyAppended
? `${pageTitle} ${optionalWord}`
: pageTitle
}

// Fallback if still no pageTitle set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@

{% macro MultilineTextField(component) %}
{% if component.model.isCharacterOrWordCount == true %}
{{ govukCharacterCount(component.model) }}
{% set characterParams = component.model | merge({
charactersUnderLimitText: {
one: t('components.characterCount.underLimit.one'),
other: t('components.characterCount.underLimit.other')
},
charactersAtLimitText: t('components.characterCount.atLimit'),
charactersOverLimitText: {
one: t('components.characterCount.overLimit.one'),
other: t('components.characterCount.overLimit.other')
}
} ) %}
{{ govukCharacterCount(characterParams) }}
{% else %}
{{ govukTextarea(component.model) }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h2 class="govuk-heading-m">{{ t('components.paymentField.preAuthorisedTitle') }
<p class="govuk-body">{{ t('components.paymentField.preAuthorisedBody') }}</p>
{% else %}
{# No pre-authorisation - show payment form #}
<h2 class="govuk-heading-m">{{ model.label.text if model.label and model.label.text else t('components.paymentField.detailsRequired') }}</h2>
<h2 class="govuk-heading-m">{{ t('components.paymentField.detailsRequired') }}</h2>

<p class="govuk-body">{{ description }}</p>

Expand Down
4 changes: 3 additions & 1 deletion src/server/plugins/engine/views/partials/preview-banner.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
</p>
{%- endmacro -%}

{% call govukNotificationBanner() %}
{% call govukNotificationBanner({
titleText: t('pages.preview.bannerTitle')
}) %}
{% set previewModeTranslated = t('common.' + previewMode) %}
{% if not context.isForceAccess %}
<p class="govuk-notification-banner__heading govuk-!-margin-bottom-0">
Expand Down
Loading