Admin panel in English and Polish, reworded per docs/dev/admin-ux.md
- 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]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
eeac33ed2f
commit
6b46bc0c14
@@ -1,6 +1,6 @@
|
||||
import type { NotificationTexts } from './types.js'
|
||||
|
||||
import { LIGHTBOX_FALLBACK } from '../lightbox/texts.js'
|
||||
import { LIGHTBOX_FALLBACK, LIGHTBOX_FALLBACK_PL } from '../lightbox/texts.js'
|
||||
|
||||
/**
|
||||
* Built-in English fallbacks, used per field when the Notifications global
|
||||
@@ -10,15 +10,36 @@ import { LIGHTBOX_FALLBACK } from '../lightbox/texts.js'
|
||||
export const NOTIFICATION_FALLBACK: NotificationTexts = {
|
||||
form: {
|
||||
back: 'Back',
|
||||
consent: 'Please accept the privacy policy to continue.',
|
||||
error: 'Something went wrong. Please try again later.',
|
||||
consent: 'Accept the privacy policy to send the form.',
|
||||
error: 'The form could not be sent. Please try again in a moment.',
|
||||
next: 'Next',
|
||||
notFound: 'This form is no longer available.',
|
||||
rateLimited: 'Too many attempts. Please wait a moment and try again.',
|
||||
stepOf: 'Step {current} of {total}',
|
||||
success: 'Thank you — your message has been sent.',
|
||||
turnstile: 'Captcha verification failed. Please try again.',
|
||||
validation: 'Please check the {field} field and try again.',
|
||||
success: 'Thank you. Your message has been sent.',
|
||||
turnstile: 'The spam protection check failed. Please try again.',
|
||||
validation: 'Check the field "{field}".',
|
||||
},
|
||||
lightbox: LIGHTBOX_FALLBACK,
|
||||
}
|
||||
|
||||
/** Polish fallbacks — used on a page whose locale is Polish. */
|
||||
export const NOTIFICATION_FALLBACK_PL: NotificationTexts = {
|
||||
form: {
|
||||
back: 'Wstecz',
|
||||
consent: 'Zaakceptuj politykę prywatności, aby wysłać formularz.',
|
||||
error: 'Nie udało się wysłać formularza. Spróbuj ponownie za chwilę.',
|
||||
next: 'Dalej',
|
||||
notFound: 'Ten formularz nie jest już dostępny.',
|
||||
rateLimited: 'Zbyt wiele prób. Odczekaj chwilę i spróbuj ponownie.',
|
||||
stepOf: 'Krok {current} z {total}',
|
||||
success: 'Dziękujemy. Wiadomość została wysłana.',
|
||||
turnstile: 'Weryfikacja ochrony przed spamem nie powiodła się. Spróbuj ponownie.',
|
||||
validation: 'Sprawdź pole „{field}”.',
|
||||
},
|
||||
lightbox: LIGHTBOX_FALLBACK_PL,
|
||||
}
|
||||
|
||||
/** Fallbacks for a page language: Polish for 'pl' / 'pl-PL', English for anything else. */
|
||||
export const notificationFallback = (locale?: string): NotificationTexts =>
|
||||
locale?.toLowerCase().startsWith('pl') ? NOTIFICATION_FALLBACK_PL : NOTIFICATION_FALLBACK
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { NotificationsData, NotificationTexts } from './types.js'
|
||||
|
||||
import { resolveLightboxTexts } from '../lightbox/texts.js'
|
||||
import { getGlobal } from '../payload/index.js'
|
||||
import { NOTIFICATION_FALLBACK } from './defaults.js'
|
||||
import { notificationFallback } from './defaults.js'
|
||||
|
||||
type GetNotificationTextsArgs = {
|
||||
/** Active locale — selects the language variant of each text. */
|
||||
@@ -13,9 +13,9 @@ type GetNotificationTextsArgs = {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves notification texts from the Notifications global, falling back to
|
||||
* English defaults per field. Mirrors getConsentTexts: one read, per-field
|
||||
* fallback, locale-aware. The frontend maps a submitForm result code to the
|
||||
* Resolves notification texts from the Notifications global, falling back per
|
||||
* field to the defaults in the page's language (Polish for 'pl', else English).
|
||||
* Mirrors getConsentTexts: one read, per-field fallback, locale-aware. The frontend maps a submitForm result code to the
|
||||
* matching text and styles it however it likes (toast, inline, banner).
|
||||
*/
|
||||
export async function getNotificationTexts({
|
||||
@@ -25,7 +25,7 @@ export async function getNotificationTexts({
|
||||
const g = await getGlobal<NotificationsData>(payload, 'notifications', { locale })
|
||||
|
||||
const f = g.form ?? {}
|
||||
const fb = NOTIFICATION_FALLBACK.form
|
||||
const fb = notificationFallback(locale).form
|
||||
|
||||
return {
|
||||
form: {
|
||||
@@ -40,6 +40,6 @@ export async function getNotificationTexts({
|
||||
turnstile: f.turnstile || fb.turnstile,
|
||||
validation: f.validation || fb.validation,
|
||||
},
|
||||
lightbox: resolveLightboxTexts(g.lightbox),
|
||||
lightbox: resolveLightboxTexts(g.lightbox, locale),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { NOTIFICATION_FALLBACK } from './defaults.js'
|
||||
export { NOTIFICATION_FALLBACK, NOTIFICATION_FALLBACK_PL, notificationFallback } from './defaults.js'
|
||||
export { getNotificationTexts } from './getNotificationTexts.js'
|
||||
export { resolveFormMessage } from './resolveFormMessage.js'
|
||||
export type { FormNotificationTexts, NotificationsData, NotificationTexts } from './types.js'
|
||||
|
||||
@@ -3,7 +3,8 @@ import type { FormNotificationTexts } from './types.js'
|
||||
|
||||
/**
|
||||
* Maps a submitForm result to the user-facing message, interpolating {field}
|
||||
* for validation errors. This is the bridge the frontend uses: it gets a result
|
||||
* 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.
|
||||
@@ -24,9 +25,9 @@ export function resolveFormMessage(result: SubmitFormResult, texts: FormNotifica
|
||||
case 'turnstile':
|
||||
return texts.turnstile
|
||||
case 'validation': {
|
||||
// Interpolate {field} with the offending field name when present.
|
||||
const field = 'field' in result && result.field ? result.field : ''
|
||||
return texts.validation.replace('{field}', field)
|
||||
// {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:
|
||||
|
||||
Reference in New Issue
Block a user