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
@@ -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…"
}
}
}