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,12 +1,21 @@
|
||||
import type { ArrayField, Field, GroupField } from 'payload'
|
||||
|
||||
import type { AdminText } from '../admin-i18n/define.js'
|
||||
|
||||
import { rowLabel } from '../admin-ui/rowLabel.js'
|
||||
|
||||
/** The default styles. A project may use any names of its own — see `appearances`. */
|
||||
export type LinkAppearance = 'link' | 'primary' | 'secondary'
|
||||
|
||||
/** One style the editor may pick: a value (`'highlight'`) or `{ label, value }` for a friendlier panel label. */
|
||||
export type LinkAppearanceOption = { label: string; value: string } | string
|
||||
export type LinkAppearanceOption = { label: AdminText | string; value: string } | string
|
||||
|
||||
/** Panel names of the default styles, also used when a project lists them by value. */
|
||||
const APPEARANCE_LABELS: Record<string, AdminText> = {
|
||||
link: { en: 'Text link', pl: 'Zwykły link' },
|
||||
primary: { en: 'Main button', pl: 'Przycisk główny' },
|
||||
secondary: { en: 'Second button', pl: 'Przycisk dodatkowy' },
|
||||
}
|
||||
|
||||
export type BuildLinkFieldOptions = {
|
||||
/**
|
||||
@@ -35,6 +44,7 @@ export type BuildLinkFieldOptions = {
|
||||
}
|
||||
|
||||
const URL_PATTERN = /^(?:https?:\/\/|mailto:|tel:|#)/
|
||||
const PAGE_LABEL = { en: 'Page', pl: 'Strona' }
|
||||
|
||||
type SiblingWithType = { type?: string } | undefined
|
||||
|
||||
@@ -71,57 +81,71 @@ export function buildLinkField({
|
||||
type: 'radio',
|
||||
admin: { layout: 'horizontal', width: '50%' },
|
||||
defaultValue: 'internal',
|
||||
label: { en: 'Link type', pl: 'Rodzaj linku' },
|
||||
options: [
|
||||
{ label: 'Page', value: 'internal' },
|
||||
{ label: 'URL', value: 'external' },
|
||||
{ label: 'File', value: 'file' },
|
||||
{ label: { en: 'Page', pl: 'Strona' }, value: 'internal' },
|
||||
{ label: { en: 'Address (URL)', pl: 'Adres (URL)' }, value: 'external' },
|
||||
{ label: { en: 'File', pl: 'Plik' }, value: 'file' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'newTab',
|
||||
type: 'checkbox',
|
||||
admin: { style: { alignSelf: 'flex-end' }, width: '50%' },
|
||||
label: 'Open in new tab',
|
||||
label: { en: 'Open in new tab', pl: 'Otwórz w nowej karcie' },
|
||||
},
|
||||
],
|
||||
},
|
||||
// One collection → plain relation; several (pages + content entries) → polymorphic.
|
||||
typeof relationTo === 'string'
|
||||
? { name: 'page', type: 'relationship', admin: pageAdmin, relationTo, required }
|
||||
: { name: 'page', type: 'relationship', admin: pageAdmin, relationTo: [...relationTo], required },
|
||||
? { name: 'page', type: 'relationship', admin: pageAdmin, label: PAGE_LABEL, relationTo, required }
|
||||
: { name: 'page', type: 'relationship', admin: pageAdmin, label: PAGE_LABEL, relationTo: [...relationTo], required },
|
||||
{
|
||||
name: 'url',
|
||||
type: 'text',
|
||||
admin: {
|
||||
condition: (_: unknown, s: SiblingWithType) => s?.type === 'external',
|
||||
description: 'Full URL (https://…), mailto:, tel: or #section-anchor.',
|
||||
description: {
|
||||
en: 'A full address (https://…), an e-mail (mailto:), a phone (tel:) or #section.',
|
||||
pl: 'Pełny adres (https://…), e-mail (mailto:), telefon (tel:) lub #sekcja.',
|
||||
},
|
||||
},
|
||||
label: { en: 'Address', pl: 'Adres' },
|
||||
required,
|
||||
validate: (v: null | string | undefined) =>
|
||||
!v || URL_PATTERN.test(v) || 'Use https://…, mailto:, tel: or #anchor',
|
||||
validate: (v: null | string | undefined, { req }: { req?: { i18n?: { language?: string } } } = {}) =>
|
||||
!v ||
|
||||
URL_PATTERN.test(v) ||
|
||||
(req?.i18n?.language === 'pl'
|
||||
? 'Wpisz pełny adres, np. https://example.com, albo mailto:, tel: lub #sekcja.'
|
||||
: 'Enter a full address, e.g. https://example.com, or mailto:, tel: or #section.'),
|
||||
},
|
||||
{
|
||||
name: 'file',
|
||||
type: 'upload',
|
||||
admin: {
|
||||
condition: (_: unknown, s: SiblingWithType) => s?.type === 'file',
|
||||
description: 'Upload a PDF / document / image. Never paste a file URL.',
|
||||
description: {
|
||||
en: 'Upload the file here instead of pasting its address.',
|
||||
pl: 'Prześlij plik tutaj zamiast wklejać jego adres.',
|
||||
},
|
||||
},
|
||||
label: { en: 'File', pl: 'Plik' },
|
||||
relationTo: uploadTo,
|
||||
required,
|
||||
},
|
||||
]
|
||||
|
||||
if (!disableLabel) {
|
||||
fields.push({ name: 'label', type: 'text', localized: true, required })
|
||||
fields.push({ name: 'label', type: 'text', label: { en: 'Link text', pl: 'Tekst linku' }, localized: true, required })
|
||||
}
|
||||
|
||||
if (appearances && hasAppearance) {
|
||||
const options = appearances.map((a) => (typeof a === 'string' ? { label: a, value: a } : a))
|
||||
const options = appearances.map((a) => (typeof a === 'string' ? { label: APPEARANCE_LABELS[a] ?? a, value: a } : a))
|
||||
fields.push({
|
||||
name: 'appearance',
|
||||
type: 'select',
|
||||
defaultValue: options[0].value,
|
||||
label: { en: 'Style', pl: 'Styl' },
|
||||
options,
|
||||
})
|
||||
}
|
||||
@@ -132,6 +156,7 @@ export function buildLinkField({
|
||||
admin: { hideGutter: true },
|
||||
fields,
|
||||
interfaceName: interfaceName ?? `CmsLink${hasAppearance ? '' : 'Plain'}${disableLabel ? 'NoLabel' : ''}`,
|
||||
label: { en: 'Link', pl: 'Link' },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +165,7 @@ export type BuildLinksFieldOptions = {
|
||||
* What one row is called in the panel — the add button reads "Add <singular>".
|
||||
* Default { singular: 'Button', plural: 'Buttons' }; e.g. { singular: 'Link', plural: 'Links' } for a link list.
|
||||
*/
|
||||
labels?: { plural: string; singular: string }
|
||||
labels?: { plural: AdminText | string; singular: AdminText | string }
|
||||
/** Max number of buttons. Default 2. */
|
||||
maxRows?: number
|
||||
/** Field name. Default 'links'. */
|
||||
@@ -153,7 +178,7 @@ export type BuildLinksFieldOptions = {
|
||||
*/
|
||||
export function buildLinksField({
|
||||
name = 'links',
|
||||
labels = { plural: 'Buttons', singular: 'Button' },
|
||||
labels = { plural: { en: 'Buttons', pl: 'Przyciski' }, singular: { en: 'Button', pl: 'Przycisk' } },
|
||||
maxRows = 2,
|
||||
...linkOptions
|
||||
}: BuildLinksFieldOptions = {}): ArrayField {
|
||||
|
||||
Reference in New Issue
Block a user