Skip to content

Tell processors when forms have been submitted in Welsh#1855

Merged
thomasiles merged 12 commits intomainfrom
add-lang-submissions
Jan 29, 2026
Merged

Tell processors when forms have been submitted in Welsh#1855
thomasiles merged 12 commits intomainfrom
add-lang-submissions

Conversation

@thomasiles
Copy link
Contributor

@thomasiles thomasiles commented Jan 22, 2026

Add language to submission email, json, and CSV

Important

I've added some commits to this since it was reviewed to make the 'language' field in CSV and JSON submissions only show when the form has a welsh version.

Trello card: https://trello.com/c/uTDx5owN/2761-needed-before-launch-update-form-submission-templates-for-welsh-forms

This PR adds:

  • a message to submission emails when fillers have completed a form in Welsh
  • a "Language" field in CSVs which is either 'en' or 'cy'
  • a "Language" attribute to JSON submissions with a value of either 'en' or 'cy'

The Language fields in the CSV and JSON appear for every submission, English and Welsh. The message in the submission email only shows in Welsh submissions.

To decide if a submission was in Welsh, we check if any questions have been answered in the Welsh locale. This is a simple test which captures how many teams deal with Welsh submissions in their current services. It will probably be refined as we learn more about how processors work with Welsh forms.

Changing session and submission code can break fillers half-way through a session. I've tried to avoid this by making the session code and submission_locale methods work even when they don't have any values set. I've also tested email and s3 submissions in dev to make sure nothing has broken.

The JSON schema kept in the product pages needs to be updated when this is released. I'll create a PR when this one has passed review to update it.

How it looks in the Email

image

The CSV

image

The JSON

{
  "$schema": "https://dev.forms.service.gov.uk/json-submissions/v1/schema",
  "form_name": "a test welsh form",
  "submission_reference": "CV3KS2C3",
  "submitted_at": "2026-01-22T17:01:10.625Z",
  "language": "cy",
  "answers": [
    {
      "question_id": "MgMQgZtq",
      "question_text": "What's the highest number you can count to?",
      "answer_text": "123"
    },
    {
      "question_id": "ehEDgsgq",
      "question_text": "Whats the next number after that?",
      "answer_text": "234"
    }
  ]
}

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Do the end to end tests need updating before these changes will pass?
  • Has all relevant documentation been updated?

@thomasiles thomasiles force-pushed the add-lang-submissions branch 2 times, most recently from 3a84895 to e4ac9e4 Compare January 23, 2026 11:31
@thomasiles thomasiles changed the title Add lang submissions Tell processors when forms have been submitted in Welsh Jan 23, 2026
@thomasiles thomasiles marked this pull request as ready for review January 23, 2026 12:26
DavidBiddle
DavidBiddle previously approved these changes Jan 26, 2026
Copy link
Contributor

@DavidBiddle DavidBiddle left a comment

Choose a reason for hiding this comment

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

Really nice and readable PR, and well broken up 🎉

All works for me when testing locally - if at least one answer is entered on a Welsh screen, the email contains the line about Welsh and the JSON/CSV include the welshlanguage flag.

@thomasiles thomasiles force-pushed the add-lang-submissions branch from e4ac9e4 to 2a2a38b Compare January 27, 2026 09:29
@thomasiles thomasiles added this pull request to the merge queue Jan 27, 2026
@thomasiles thomasiles removed this pull request from the merge queue due to a manual request Jan 27, 2026
Copy link
Contributor

@DavidBiddle DavidBiddle left a comment

Choose a reason for hiding this comment

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

Code looks good 🎉

I've tested locally and can see what I think is the correct behaviour:

  • monolingual form:
    • no message in the email text
    • no language field in the JSON or CSV
  • bilingual form answered entirely on the English routes:
    • no message in the email text
    • language set to en in the JSON and CSV
  • bilingual form answered partly on the Welsh routes:
    • message in the email text
    • language set to cy in the JSON and CSV

Add a new column, submission_locale, to the submissions table.

We will use this to store the language the form was submitted in.
We are going to store the locales used when filling in a form in the session answer store.

They will be stored in an array under the key `locales`, form_id, in the store.

We clear the locales when the form is submitted at the same time we
clear the answers.
We add a method which will decide the locale of a submission.

We choose based on the locale the filler was using when submitting an
answer.

If they submitted any answer in Welsh, we choose :cy. Otherwise we choose
:en.
The S3 submission service needs to know the locale of the
submission to be able to generate the CSV and JSON files.

We pass the submission_locale decided by the form
submission_service to the S3 submission service.
When we create a Submission, which is used to store a submission for
delivery by email, we need to know the locale of the submission.

This commit adds the decided submission locale to the Submission created
when the form is submitted.
We add a language field to the end of the submission CSV.

We change the CSV generator to use the submission locale and pass in the
value when generating the CSV for S3 and SES.
Add a language property to the JSON submission.

We add language to our JSON schema or at least the version we keep in
this repository for testing.

JSON
When a form is submitted in Welsh, we include a message in the email to
inform the processor.
The CSV generator used to take submission_locale as an argument, and
always include it in the CSV in the language field.

Now, only submissions for forms with Welsh will have language set
to en or cy.

This means all current forms won't include a language field unless they
have a Welsh translation added. When the CSV is generated the language
field will be set to nil.

The argument name has been changed to language as it's more direct and
shows what's being set in the CSV.
The JSON generator used to take submission_locale as an argument, and
always include it in the JSON.

Now, only submissions for forms with Welsh will have language set
to en or cy.

This means all current forms won't include a language field unless they
have a Welsh translation added. When the JSON is generated the language
field will be set to nil and the field won't be included.

The argument name has been changed to language as it's more direct and
shows what's being set in the JSON.
We change the submission services which call the CSV and JSON generators
to pass the language instead of locale.

This allows us to decide whether to include language, as taken from
submission locale or pass nil to not include it at all.

Only forms which have more than one language, currently only Welsh
forms, will have language set.
We are not updating the JSON schema for submissions. So the changes we
made to this test fixture are no longer valid.

We'll update the schema here and the one in the product pages properly
when we have a process for doing so.
@thomasiles thomasiles force-pushed the add-lang-submissions branch from 38358c4 to 6fe0262 Compare January 29, 2026 09:07
@sonarqubecloud
Copy link

@github-actions
Copy link
Contributor

🎉 A review copy of this PR has been deployed! It is made of up two components

  1. A review copy of forms-runner
  2. A production copy of forms-admin

Important

Not all of the functionality of forms-runner is present in review apps.
Functionality such as sending emails, file upload, and S3 submission types are
deliberately disabled for the sake of simplifying review apps.

You should use the full dev environment to test the functionality which is disabled here.

It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready
after 5 minutes, there may be something wrong with the ECS task. You will need to go to the integration AWS account
to debug, or otherwise ask an infrastructure person.

For the sign in details and more information, see the review apps wiki page.

@thomasiles thomasiles added this pull request to the merge queue Jan 29, 2026
Merged via the queue into main with commit 7ce5cab Jan 29, 2026
6 checks passed
@thomasiles thomasiles deleted the add-lang-submissions branch January 29, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants