- admin-i18n module: AdminText { en, pl }, component texts under the ipal
namespace (project translations win), en + pl admin languages when the
project sets none (project's supportedLanguages wins)
- every plugin label, description, option, tab and group as { en, pl };
explicit labels instead of auto-labels; sentence case; glossary terms
- visible renames (slugs, names, data unchanged): Cookie banner, Form
messages, Privacy group, Search engines, Maintenance, Spam protection,
E-mail sending, stats nav link Overview (hidden without access)
- Polish visitor defaults by page locale: cookie banner, form messages,
validators, lightbox, accessibility widget; {field} uses the label
- fixes: e-mail status banner used Turnstile wording; developer words and
env var names out of editor messages; stats numbers/dates in the admin
language; test e-mail no longer says ipal-kit
- test/adminUx.test.ts: length limits, en + pl present, no developer words
Co-Authored-By: Claude Opus 5.5 <[email protected]>
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import type { SubmitFormResult } from '../forms/index.js'
|
|
import type { FormNotificationTexts } from './types.js'
|
|
|
|
/**
|
|
* Maps a submitForm result to the user-facing message, interpolating {field}
|
|
* with the field's label (its key when the form has no label) for validation
|
|
* errors. This is the bridge the frontend uses: it gets a result
|
|
* code from submitForm and the resolved texts from getNotificationTexts, and
|
|
* this turns them into one string to display. Keeping the mapping here means the
|
|
* frontend never hard-codes messages or knows about result codes.
|
|
*
|
|
* Never surfaces raw backend/exception detail — 'error' maps to a friendly
|
|
* generic message, not the thrown error's text (which could leak internals).
|
|
*/
|
|
export function resolveFormMessage(result: SubmitFormResult, texts: FormNotificationTexts): string {
|
|
if (result.success) {return texts.success}
|
|
|
|
switch (result.reason) {
|
|
case 'consent':
|
|
return texts.consent
|
|
case 'not_found':
|
|
return texts.notFound
|
|
case 'rate_limited':
|
|
return texts.rateLimited
|
|
case 'turnstile':
|
|
return texts.turnstile
|
|
case 'validation': {
|
|
// {field} → the label the visitor sees; no single field at fault → the generic error.
|
|
const field = result.label || result.field
|
|
return field ? texts.validation.replace('{field}', field) : texts.error
|
|
}
|
|
case 'error':
|
|
default:
|
|
return texts.error
|
|
}
|
|
}
|