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:
Radosław Smoliński
2026-10-27 15:46:25 +01:00
co-authored by Claude Opus 5.5
parent eeac33ed2f
commit 6b46bc0c14
108 changed files with 2806 additions and 981 deletions
+142 -4
View File
@@ -3,6 +3,7 @@ import type { Block, Field, Plugin } from 'payload'
import { fields as builtinBlocks, formBuilderPlugin } from '@payloadcms/plugin-form-builder'
import type { AdminText } from '../admin-i18n/define.js'
import type { FormsOption } from './types.js'
import { userMeetsRole } from '../access/predicates.js'
@@ -11,6 +12,139 @@ import { buildEmailLayoutHook } from './emailLayout.js'
type AccessArgs = { req: { user?: unknown } }
/**
* Panel wording for form-builder's own fields, by its translation key. Its
* labels are functions (`({ t }) => t('plugin-form-builder:name')`); these
* replace them with `{ en, pl }` text — labels only, names and data unchanged.
* Keys not listed keep form-builder's own text.
*/
const FORM_BUILDER_TEXTS: Record<string, AdminText> = {
name: { en: 'Field key', pl: 'Klucz pola' },
bcc: { en: 'BCC', pl: 'UDW' },
cc: { en: 'CC', pl: 'DW' },
checkboxPlural: { en: 'Checkboxes', pl: 'Pola wyboru' },
checkboxSingular: { en: 'Checkbox', pl: 'Pole wyboru' },
checkedByDefault: { en: 'Checked by default', pl: 'Domyślnie zaznaczone' },
chooseConfirmationType: {
en: 'Show a message or go to another page after the form is sent.',
pl: 'Pokaż komunikat lub przejdź na inną stronę po wysłaniu formularza.',
},
confirmationMessage: { en: 'Confirmation message', pl: 'Komunikat potwierdzenia' },
confirmationType: { en: 'After sending', pl: 'Po wysłaniu' },
countryPlural: { en: 'Country fields', pl: 'Pola kraju' },
countrySingular: { en: 'Country', pl: 'Kraj' },
customURL: { en: 'Address (URL)', pl: 'Adres (URL)' },
datePlural: { en: 'Date fields', pl: 'Pola daty' },
dateSingular: { en: 'Date', pl: 'Data' },
defaultValue: { en: 'Default value', pl: 'Wartość domyślna' },
documentToLinkTo: { en: 'Page', pl: 'Strona' },
emailFrom: { en: 'From', pl: 'Od' },
emailPlural: { en: 'E-mail fields', pl: 'Pola e-mail' },
emailsDescription: {
en: 'Sent after each submission; use {{email}} for a field value and {{*:table}} for all values.',
pl: 'Wysyłane po każdym zgłoszeniu; {{email}} wstawia wartość pola, a {{*:table}} wszystkie wartości.',
},
emailSingular: { en: 'E-mail', pl: 'E-mail' },
emailTo: { en: 'To', pl: 'Do' },
field: { en: 'Field', pl: 'Pole' },
fields: { en: 'Fields', pl: 'Pola' },
fieldWidth: { en: 'Width (%)', pl: 'Szerokość (%)' },
internalLink: { en: 'Page', pl: 'Strona' },
label: { en: 'Label', pl: 'Etykieta' },
message: { en: 'Message', pl: 'Wiadomość' },
messageDescription: { en: 'Text of the e-mail.', pl: 'Treść wiadomości e-mail.' },
messagePlural: { en: 'Text blocks', pl: 'Bloki tekstu' },
messageSingular: { en: 'Text block', pl: 'Blok tekstu' },
numberPlural: { en: 'Number fields', pl: 'Pola liczbowe' },
numberSingular: { en: 'Number', pl: 'Liczba' },
optionPlural: { en: 'Options', pl: 'Opcje' },
optionSingular: { en: 'Option', pl: 'Opcja' },
placeholder: { en: 'Placeholder', pl: 'Tekst podpowiedzi' },
radioOptions: { en: 'Options', pl: 'Opcje' },
radioPlural: { en: 'Single choice fields', pl: 'Pola jednokrotnego wyboru' },
radioSingular: { en: 'Single choice', pl: 'Jednokrotny wybór' },
redirect: { en: 'Redirect', pl: 'Przekierowanie' },
replyTo: { en: 'Reply to', pl: 'Odpowiedź do' },
required: { en: 'Required', pl: 'Wymagane' },
selectOptions: { en: 'Options', pl: 'Opcje' },
selectPlural: { en: 'Dropdown fields', pl: 'Listy rozwijane' },
selectSingular: { en: 'Dropdown', pl: 'Lista rozwijana' },
statePlural: { en: 'Region fields', pl: 'Pola regionu' },
stateSingular: { en: 'Region', pl: 'Region' },
subject: { en: 'Subject', pl: 'Temat' },
submitButton: { en: 'Button text', pl: 'Tekst przycisku' },
textareaPlural: { en: 'Long text fields', pl: 'Pola długiego tekstu' },
textareaSingular: { en: 'Long text', pl: 'Długi tekst' },
textPlural: { en: 'Text fields', pl: 'Pola tekstowe' },
textSingular: { en: 'Text', pl: 'Tekst' },
title: { en: 'Title', pl: 'Tytuł' },
urlToRedirectTo: { en: 'Address (URL)', pl: 'Adres (URL)' },
value: { en: 'Value', pl: 'Wartość' },
}
/** `({ t }) => t('plugin-form-builder:<key>')` → our `{ en, pl }`; anything else unchanged. */
function formBuilderText<V>(value: V): AdminText | V {
if (typeof value !== 'function') {return value}
try {
const key = String((value as (args: unknown) => unknown)({ i18n: {}, t: (k: string) => k }))
return FORM_BUILDER_TEXTS[key.replace(/^plugin-form-builder:/, '')] ?? value
} catch {
return value
}
}
/** Replaces form-builder's labels, descriptions and option labels, deep (blocks, arrays, rows, groups). */
function localizeFormBuilder<T>(node: T): T {
if (Array.isArray(node)) {return node.map(localizeFormBuilder) as T}
if (!node || typeof node !== 'object') {return node}
const f = node as Record<string, unknown>
const out: Record<string, unknown> = { ...f }
if ('label' in f) {out.label = formBuilderText(f.label)}
// The text block's rich text has no label of its own.
if (f.type === 'richText' && f.name === 'message' && !f.label) {out.label = { en: 'Text', pl: 'Treść' }}
if (f.labels && typeof f.labels === 'object') {
const labels = f.labels as Record<string, unknown>
out.labels = { ...labels, plural: formBuilderText(labels.plural), singular: formBuilderText(labels.singular) }
}
if (f.admin && typeof f.admin === 'object' && 'description' in f.admin) {
const admin = f.admin as Record<string, unknown>
out.admin = { ...admin, description: formBuilderText(admin.description) }
}
if (Array.isArray(f.options)) {out.options = f.options.map((o) => (o && typeof o === 'object' ? { ...o, label: formBuilderText((o as { label?: unknown }).label) } : o))}
for (const key of ['fields', 'blocks', 'tabs'] as const) {
if (Array.isArray(f[key])) {out[key] = localizeFormBuilder(f[key])}
}
return out as T
}
/** Labels for the submission fields form-builder leaves unlabelled. */
const SUBMISSION_LABELS: Record<string, AdminText> = {
form: { en: 'Form', pl: 'Formularz' },
submissionData: { en: 'Answers', pl: 'Odpowiedzi' },
submissionUploads: { en: 'Files', pl: 'Pliki' },
}
const SUBMISSION_ROW_LABELS: Record<string, AdminText> = {
field: { en: 'Field key', pl: 'Klucz pola' },
value: { en: 'Value', pl: 'Wartość' },
}
function labelSubmissionFields(fields: Field[]): Field[] {
return fields.map((field) => {
if (!('name' in field) || !SUBMISSION_LABELS[field.name] || field.label) {return field}
const labelled = { ...field, label: SUBMISSION_LABELS[field.name] } as Field
if (labelled.type === 'array') {
return {
...labelled,
fields: labelled.fields.map((sub) =>
'name' in sub && SUBMISSION_ROW_LABELS[sub.name] && !sub.label ? ({ ...sub, label: SUBMISSION_ROW_LABELS[sub.name] } as Field) : sub,
),
labels: labelled.labels ?? { plural: { en: 'Answers', pl: 'Odpowiedzi' }, singular: { en: 'Answer', pl: 'Odpowiedź' } },
} as Field
}
return labelled
})
}
/** A built-in form-builder block with "Show only when" added (full block — form-builder merges arrays by replacing). */
const builtin = (key: 'checkbox' | 'date' | 'email' | 'message' | 'number' | 'radio' | 'select' | 'text' | 'textarea') =>
withShowWhen(builtinBlocks[key] as Block)
@@ -65,7 +199,7 @@ function hideEmails(fields: Field[]): Field[] {
* really needs public REST submissions can override `formSubmissionOverrides.access.create`.
*/
export function buildFormsPlugin(forms: FormsOption): Plugin {
const adminGroup = forms.adminGroup === undefined ? 'Forms' : forms.adminGroup
const adminGroup = forms.adminGroup === undefined ? { en: 'Forms', pl: 'Formularze' } : forms.adminGroup
const group = adminGroup ? { group: adminGroup } : {}
const layout = forms.emailLayout ? buildEmailLayoutHook({ formsSlug: forms.formOverrides?.slug ?? 'forms' }) : undefined
const beforeEmail: BeforeEmail | undefined =
@@ -109,7 +243,7 @@ export function buildFormsPlugin(forms: FormsOption): Plugin {
// Tidy panel by default: both collections under one sidebar group with plain
// labels — no per-project overrides needed just to sort the sidebar.
formOverrides: {
labels: { plural: 'Forms', singular: 'Form' },
labels: { plural: { en: 'Forms', pl: 'Formularze' }, singular: { en: 'Form', pl: 'Formularz' } },
...forms.formOverrides,
access: {
create: staffAccess,
@@ -120,12 +254,12 @@ export function buildFormsPlugin(forms: FormsOption): Plugin {
},
admin: { ...group, ...forms.formOverrides?.admin },
fields: ({ defaultFields }) => {
const protectedFields = hideEmails(defaultFields)
const protectedFields = hideEmails(localizeFormBuilder(defaultFields))
return forms.formOverrides?.fields ? forms.formOverrides.fields({ defaultFields: protectedFields }) : protectedFields
},
},
formSubmissionOverrides: {
labels: { plural: 'Submissions', singular: 'Submission' },
labels: { plural: { en: 'Submissions', pl: 'Zgłoszenia' }, singular: { en: 'Submission', pl: 'Zgłoszenie' } },
...forms.formSubmissionOverrides,
access: {
create: submissionsCreateAccess,
@@ -134,6 +268,10 @@ export function buildFormsPlugin(forms: FormsOption): Plugin {
...forms.formSubmissionOverrides?.access,
},
admin: { ...group, defaultColumns: ['form', 'createdAt'], ...forms.formSubmissionOverrides?.admin },
fields: ({ defaultFields }) => {
const labelled = labelSubmissionFields(defaultFields)
return forms.formSubmissionOverrides?.fields ? forms.formSubmissionOverrides.fields({ defaultFields: labelled }) : labelled
},
},
})
}