Files
ipal-kit/src/modules/content/archiveFields.ts
T
Radosław SmolińskiandClaude Opus 5.5 6b46bc0c14 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]>
2026-10-27 15:46:25 +01:00

49 lines
2.0 KiB
TypeScript

import type { Field, RelationshipField } from 'payload'
import type { AdminText } from '../admin-i18n/index.js'
import type { ContentOption } from './types.js'
import { archiveFieldName } from './types.js'
/**
* Builds one relationship field per content collection, pointing at the
* client's Pages collection.
*
* Sits alongside the system-page roles (homepage, privacy policy) because it's
* the same idea: a page referenced by function rather than by slug. The
* assignment is locale-agnostic — one page document — while the resulting path
* is locale-aware, since the page's slug is localized. Assign the "Artykuły"
* page once and you get /pl/artykuly and /en/articles from its own slugs.
*/
export function buildArchiveFields(content: ContentOption, pagesSlug: string): Field[] {
return content.collections.map((collection): RelationshipField => {
const name = collectionName(collection.label, collection.slug)
return {
name: archiveFieldName(collection.slug),
type: 'relationship',
admin: {
description: {
en: 'Page that lists the entries; its address (URL) starts the address of each entry.',
pl: 'Strona z listą wpisów; jej adres (URL) rozpoczyna adres każdego wpisu.',
},
},
label: { en: `${name.en} archive`, pl: `Archiwum: ${name.pl}` },
maxDepth: 1,
relationTo: pagesSlug,
}
})
}
/**
* The collection's name in each admin language: the project's `label` (a
* string, or `{ en, pl }`), else the slug made readable (`blog-posts` → "Blog posts").
*/
function collectionName(label: AdminText | string | undefined, slug: string): AdminText {
if (label && typeof label === 'object') {return { en: label.en, pl: label.pl || label.en }}
if (typeof label === 'string' && label.trim()) {return { en: label, pl: label }}
const words = slug.replace(/[-_]+/g, ' ').replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase().trim()
const readable = words.charAt(0).toUpperCase() + words.slice(1)
return { en: readable, pl: readable }
}