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
@@ -9,7 +9,7 @@ import { APIError } from 'payload'
|
||||
* phone photo or the raw 300 MB video, and asks before touching anything.
|
||||
*
|
||||
* - JPG / PNG over the limits → upload is stopped with an explanation; the
|
||||
* editor ticks "Optimize this upload" and saves again → converted to WebP,
|
||||
* editor ticks "Optimise large image" and saves again → converted to WebP,
|
||||
* resized to maxImageWidth, auto-rotated, metadata (EXIF/GPS) removed.
|
||||
* - Video over maxVideoBytes → stopped with export instructions (never
|
||||
* transcoded — that needs ffmpeg and minutes of CPU per file).
|
||||
@@ -39,7 +39,12 @@ export type OptimizeUploadOptions = {
|
||||
|
||||
const OPTIMIZABLE = new Set(['image/jpeg', 'image/png'])
|
||||
const MB = 1024 * 1024
|
||||
const fmt = (bytes: number) => `${(bytes / MB).toFixed(1)} MB`
|
||||
/** Size in MB with one decimal, in the admin language's number format. */
|
||||
const fmt = (bytes: number, language: string) =>
|
||||
`${new Intl.NumberFormat(language, { maximumFractionDigits: 1, minimumFractionDigits: 1 }).format(bytes / MB)} MB`
|
||||
|
||||
/** Label of the consent checkbox — the error messages name it. */
|
||||
const CONSENT_LABEL = { en: 'Optimise large image', pl: 'Optymalizuj duży obraz' }
|
||||
|
||||
/**
|
||||
* Consent checkbox for the upload collection's sidebar. Unticked by default;
|
||||
@@ -50,12 +55,14 @@ export function buildOptimizeUploadField(name = 'optimizeOnUpload'): CheckboxFie
|
||||
name,
|
||||
type: 'checkbox',
|
||||
admin: {
|
||||
description:
|
||||
'Only used when an image is too large: converts it to WebP, resizes it and removes metadata (EXIF/GPS). Prepared files are never changed.',
|
||||
description: {
|
||||
en: 'Used only for an image that is too large: makes it smaller and removes hidden photo data, such as location.',
|
||||
pl: 'Działa tylko dla zbyt dużego obrazu: zmniejsza go i usuwa ukryte dane zdjęcia, np. lokalizację.',
|
||||
},
|
||||
position: 'sidebar',
|
||||
},
|
||||
defaultValue: false,
|
||||
label: 'Optimize this upload',
|
||||
label: CONSENT_LABEL,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,16 +98,20 @@ export function buildOptimizeUploadHook(
|
||||
if (!file) {return}
|
||||
|
||||
const data = (args as { data?: Record<string, unknown> }).data
|
||||
const pl = req.i18n?.language === 'pl'
|
||||
const lang = pl ? 'pl' : 'en'
|
||||
const consent = Boolean(data?.[consentField])
|
||||
const size = file.size || file.data?.length || 0
|
||||
|
||||
// --- Video: limit only, never transcoded ---
|
||||
if (file.mimetype.startsWith('video/')) {
|
||||
if (maxVideoBytes !== false && size > maxVideoBytes) {
|
||||
// Export hint for the developer / log: MP4 (H.264), 720p–1080p, about 2–4 Mbit/s,
|
||||
// no audio track for background videos, "web optimized" / fast start (HandBrake preset "Web").
|
||||
throw new APIError(
|
||||
`Video is ${fmt(size)} (limit ${fmt(maxVideoBytes)}). Export it before uploading: ` +
|
||||
'MP4 (H.264), 720p–1080p, about 2–4 Mbit/s, no audio track for background videos, ' +
|
||||
'"web optimized" / fast start enabled (e.g. HandBrake preset "Web").',
|
||||
pl
|
||||
? `Film ma ${fmt(size, lang)} (limit ${fmt(maxVideoBytes, lang)}). Wyeksportuj mniejszy plik, np. MP4 w 1080p, i prześlij go ponownie.`
|
||||
: `The video is ${fmt(size, lang)} (limit ${fmt(maxVideoBytes, lang)}). Export a smaller file, e.g. MP4 at 1080p, and upload it again.`,
|
||||
400,
|
||||
undefined,
|
||||
true,
|
||||
@@ -134,16 +145,17 @@ export function buildOptimizeUploadHook(
|
||||
if (!tooHeavy && !tooWide) {return}
|
||||
|
||||
const problem = [
|
||||
tooHeavy ? `${fmt(size)} (limit ${fmt(maxImageBytes)})` : null,
|
||||
tooWide ? `${width} px wide (limit ${maxImageWidth} px)` : null,
|
||||
tooHeavy ? `${fmt(size, lang)} (limit ${fmt(maxImageBytes, lang)})` : null,
|
||||
tooWide ? (pl ? `${width} px szerokości (limit ${maxImageWidth} px)` : `${width} px wide (limit ${maxImageWidth} px)`) : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(', ')
|
||||
|
||||
if (!consent) {
|
||||
throw new APIError(
|
||||
`Image is ${problem}. Tick "Optimize this upload" in the sidebar and save again to convert it ` +
|
||||
`to WebP (max ${maxImageWidth} px wide, metadata removed), or upload a smaller file.`,
|
||||
pl
|
||||
? `Obraz ma ${problem}. Zaznacz „${CONSENT_LABEL.pl}” w panelu bocznym i zapisz ponownie albo prześlij mniejszy plik.`
|
||||
: `The image is ${problem}. Tick "${CONSENT_LABEL.en}" in the sidebar and save again, or upload a smaller file.`,
|
||||
400,
|
||||
undefined,
|
||||
true,
|
||||
@@ -151,8 +163,11 @@ export function buildOptimizeUploadHook(
|
||||
}
|
||||
|
||||
if (!sharp) {
|
||||
req.payload.logger?.error?.('[ipal] Image optimisation needs sharp: pass it to buildConfig({ sharp }) in payload.config.ts.')
|
||||
throw new APIError(
|
||||
'Image optimization needs sharp: pass it to buildConfig({ sharp }) in payload.config.ts.',
|
||||
pl
|
||||
? 'Optymalizacja obrazów nie jest dostępna na tym serwerze. Zapytaj administratora.'
|
||||
: 'Image optimisation is not available on this server. Ask your administrator.',
|
||||
500,
|
||||
undefined,
|
||||
true,
|
||||
|
||||
Reference in New Issue
Block a user