Translation files: the form messages of the cms-client package come from nl.json

Block cmsClient.contact holds the field errors, fallback, waiting time (one
and other), too-large, captcha-required, failure and sending label.
src/i18n/cmsClientMessages.ts builds the ContactMessages object for
useContactForm; a test checks that it says the same as the package's own
Dutch defaults, which stay as the fallback.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 00:30:01 +01:00
co-authored by Claude Sonnet 5.5
parent 85370351d0
commit e7bae5edd7
6 changed files with 96 additions and 2 deletions
+4 -2
View File
@@ -4,7 +4,7 @@ The texts of the site live in language files, not in the components. Dutch is th
## Where things are
- `web/src/i18n/nl.json`: all Dutch texts of the site in one file, in blocks per area in the order of the site: `common`, `site`, `home`, `about`, `contact`, `shoots`, `portfolio`, `instagram`, `testimonials`, `seo`. The file is the source of the types. A second language is `web/src/i18n/en.json` with the same keys.
- `web/src/i18n/nl.json`: all Dutch texts of the site in one file, in blocks per area in the order of the site: `common`, `site`, `home`, `about`, `contact`, `shoots`, `portfolio`, `instagram`, `testimonials`, `seo`, `cmsClient`. The file is the source of the types. A second language is `web/src/i18n/en.json` with the same keys.
- `web/src/i18n/index.ts`: `t(key, params?)` for a text, `tList(key)` for a list of texts, `tPlural(key, count, params?)` for a text with a singular and a plural form, `locales`, `locale` and `Messages`.
- `web/src/i18n/compare.ts`: the checks the tests use (same keys and parameters, nothing empty).
- The typed content modules in `web/src/content` keep their structure, images and paths; the words come from the language files.
@@ -40,7 +40,9 @@ Dotted paths: the block (`common`, `home`, ...), then the page or section, then
| `portfolio.json`, `instagram.json`, `testimonials.json` | those pages and sections, with their photo alt texts and reviews |
| `seo.json` | page titles, descriptions and link-preview alt texts per page (`seo.pages.<page>`) |
Not here: the hero, the privacy statement, everything from the CMS, and the form validation messages of the copied `src/cms-client` package (`messages.nl.ts`).
The block `cmsClient` holds the texts of the shared `src/cms-client` package, per part of the package: `cmsClient.contact` has the form's field errors, fallback, waiting time (`rateLimited.one/other` with `{minutes}`), too-large, captcha-required, failure (`{address}`) and the sending label. `src/i18n/cmsClientMessages.ts` builds the `ContactMessages` object from it and `ContactForm` passes it to `useContactForm({ messages })`. The package keeps its own Dutch defaults (`messages.nl.ts`) as a fallback and a test checks that both say the same. Parts that come later (offerings) get their own part of the block.
Not here: the hero, the privacy statement and everything from the CMS.
## Importing the language files
@@ -25,6 +25,7 @@ import {
import { contactClient } from '@/contact/contactClient';
import type { EmailAddress } from '@/content/types';
import useEmailAddress from '@/hooks/useEmailAddress';
import { contactMessages } from '@/i18n/cmsClientMessages';
import { t } from '@/i18n';
import { mailtoLink } from '@/lib/mailLink';
import { trackContactEvent } from '@/lib/trackEvent';
@@ -108,6 +109,8 @@ export default function ContactForm({
token,
refreshToken,
fallbackAddress: address ?? '',
// The texts of the form come from the language file
messages: contactMessages,
onEvent: (event) =>
trackContactEvent(
event === 'sent' ? 'contact-sent' : 'contact-failed',
+33
View File
@@ -0,0 +1,33 @@
import { describe, expect, it } from 'vitest';
import { messagesNl } from '@/cms-client/contact';
import { contactMessages } from './cmsClientMessages';
// The site gives the form its texts from nl.json; the package keeps its own
// Dutch ones as a fallback. They have to say the same.
describe('contactMessages (from nl.json)', () => {
it('has the same field errors, fallback, limits and labels as the package', () => {
expect(contactMessages.fieldErrors).toEqual(messagesNl.fieldErrors);
expect(contactMessages.fallbackFieldError).toBe(
messagesNl.fallbackFieldError,
);
expect(contactMessages.tooLarge).toBe(messagesNl.tooLarge);
expect(contactMessages.captchaRequired).toBe(
messagesNl.captchaRequired,
);
expect(contactMessages.sendingLabel).toBe(messagesNl.sendingLabel);
});
it('says the same about the waiting time, singular and plural', () => {
for (const minutes of [1, 2, 5, 60]) {
expect(contactMessages.rateLimited(minutes)).toBe(
messagesNl.rateLimited(minutes),
);
}
});
it('says the same when sending failed, with the address', () => {
expect(contactMessages.failed('info@voorbeeld.nl')).toBe(
messagesNl.failed('info@voorbeeld.nl'),
);
});
});
+20
View File
@@ -0,0 +1,20 @@
import type { ContactMessages } from '@/cms-client/contact';
import { messages, tPlural, t } from './index.ts';
// The texts of the form of the shared cms-client package, from the language
// file (block cmsClient.contact), in the shape the package asks for
// (useContactForm({ messages })). The package keeps its own Dutch defaults
// (messages.nl.ts) as a fallback; a test checks that these are the same, so
// the two cannot drift apart unseen.
const contact = messages.cmsClient.contact;
export const contactMessages: ContactMessages = {
fieldErrors: contact.fieldErrors,
fallbackFieldError: contact.fallbackFieldError,
rateLimited: (minutes) =>
tPlural('cmsClient.contact.rateLimited', minutes, { minutes }),
tooLarge: contact.tooLarge,
captchaRequired: contact.captchaRequired,
failed: (address) => t('cmsClient.contact.failed', { address }),
sendingLabel: contact.sendingLabel,
};
+1
View File
@@ -96,6 +96,7 @@ describe('nl.json', () => {
'instagram',
'testimonials',
'seo',
'cmsClient',
]);
});
});
+35
View File
@@ -887,5 +887,40 @@
"description": "Lees hoe Andrea Slop Fotografie omgaat met je persoonsgegevens en met de foto's die tijdens een fotoshoot gemaakt worden."
}
}
},
"cmsClient": {
"contact": {
"fieldErrors": {
"name": {
"required": "Vul je naam in.",
"tooLong": "De naam is te lang.",
"invalid": "Deze naam is ongeldig."
},
"email": {
"required": "Vul je e-mailadres in.",
"tooLong": "Het e-mailadres is te lang.",
"invalid": "Dit e-mailadres is ongeldig."
},
"subject": {
"required": "Kies een onderwerp.",
"tooLong": "Dit onderwerp is te lang.",
"invalid": "Kies een onderwerp."
},
"message": {
"required": "Schrijf hier je vraag.",
"tooLong": "Het bericht is te lang.",
"invalid": "Dit bericht bevat ongeldige tekens."
}
},
"fallbackFieldError": "Controleer dit veld.",
"rateLimited": {
"one": "Je hebt net al een bericht gestuurd. Probeer het over {minutes} minuut opnieuw.",
"other": "Je hebt net al een bericht gestuurd. Probeer het over {minutes} minuten opnieuw."
},
"tooLarge": "Je bericht is te groot.",
"captchaRequired": "Bevestig eerst dat je geen robot bent.",
"failed": "Versturen lukte niet. Probeer het later nog eens of mail naar {address}.",
"sendingLabel": "Versturen…"
}
}
}