seo: the translations option is merged but never read, so the panel is hardcoded English

Aperta
#187 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start with packages/payload-plugin-seo/src/translations/en.ts and src/utils/config/mergeTranslations.ts, then trace string rendering in the components and engine areas named in the issue. Run the package tests with bun run test; extend the merge and component tests to cover nested overrides, legacy keys, language fallback, and rendered strings. Done means all listed strings use Payload translations, English remains unchanged, and the acceptance criteria pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

What happens

The README documents translations as the way to "Override the English UI strings (merged with defaults)" (README.md#L226-L227), and the plugin merges it into Payload's i18n (plugin.ts#L43-L51). No component reads it back: there is no useTranslation or t() call under src, and 217 user-facing strings in 39 files are literals. Passing translations changes nothing on screen, and an admin switched to another language still shows the SEO button, drawer and field components in English.

It also blocks a common setup. A host that labels the mapped fields in its own words, say "Search title" and "Search description" for meta.title and meta.description, still gets check rows named "SEO title width" and "Meta description length" (labels.ts#L52-L59), so an editor looks for fields that do not exist under those names, and there is no config to rename them.

Expected

Every string the plugin renders comes from Payload's i18n under a seo namespace, the translations option overrides any of them per language, and a language with no overrides shows the English defaults rather than raw keys.

Reproduction

apps/cms installs the plugin on page and posts with meta.title and meta.description mapped (plugins/index.ts#L236-L264) and enables en and es in the admin (payload.config.ts#L87-L89).

  1. In apps/cms, fill .env from .env.example (DATABASE_URL, PAYLOAD_SECRET) and run bun run dev (port 3333)
  2. Open an existing post and click the gauge button next to the document controls. The drawer reads "SEO Analytics", with tabs "Keyphrase", "On-page SEO" and so on
  3. Switch your account's admin language to Español. The rest of the admin turns Spanish, the drawer stays English
  4. Add translations: { en: { "seo:title": "SEO" } } to the seoAnalysisPlugin options and restart. The heading still reads "SEO Analytics"

apps/dev also installs the plugin, but its collection entry has no extractContentPath (payload.config.ts#L158-L175), so the plugin skips registration there (plugin.ts#L23-L38). The steps above are read from the config and the source, not clicked through.

Root cause

Fix

  • src/translations/en.ts: nest the defaults under seo, keep the existing keys (seo:title, seo:tab:keyphrase and the rest) and add one key per string. Data-driven strings key on the id the code already has: seo:check:<checkId>:name and :tip, seo:status:<good|warn|bad>, seo:recommendation:<checkId>:<status>. Everything else goes under one area per component folder (seo:keyphrase:*, seo:headings:*, seo:field:* and so on). The close button reuses Payload's general:close. Counts use Payload's _one and _other suffixes with {{count}}. Export the shape as SeoTranslations
  • src/utils/config/mergeTranslations.ts: for every language in i18n.supportedLanguages (Payload's default is en) plus every language in the option, deep-merge the host's translations with { seo: en.seo + option[language] }, using deepMergeSimple from payload/shared. Normalise legacy flat keys such as "seo:title" into the nested shape, so configs written against the README keep working
  • Option type: translations?: Record<string, DeepPartial<SeoTranslations>>, keyed by language, values without the seo wrapper, the same contract as the comments plugin, plus the legacy flat form
  • Components: const { t } = useTranslation() from @payloadcms/ui, every literal replaced. CheckRow keeps today's fallback for a check id with no key: render the id
  • Engine: return { key, vars } instead of sentences for recommendations, inclusive category names, drill-down nouns, units and captions, and translate where they render. The engine types are not exported from the package (index.ts#L1-L11), so no public type changes

Existing users see no change: every English default is today's literal, word for word. Minor version bump.

Acceptance criteria

  • Every string in the brief's inventory (217, linked below) renders through t(), and the English panel is unchanged word for word
  • translations: { en: { check: { titleWidth: { name: "Search title width" } } } } renames that one row, and every other check name keeps its default
  • The legacy translations: { en: { "seo:title": "SEO" } } changes the drawer heading to "SEO"
  • With the admin in es and no Spanish strings passed, the panel shows the English defaults and no raw seo: key anywhere
  • With translations: { es: { title: "Analítica SEO" } }, the heading reads "Analítica SEO" in the Spanish admin and "SEO Analytics" in the English one
  • Recommendation lines, inclusive category names and drill-down labels follow the admin language the same way
  • A host's own translations in other namespaces (the sso strings in apps/cms) still resolve

Test plan

  • Unit tests in packages/payload-plugin-seo/tests (vitest, bun run test). Extend tests/utils/mergeTranslations.test.ts: an override of one check name keeps the others, flat keys are normalised, English is seeded into every supported language, a host's other namespace survives. Add a test that runs Payload's own t from @payloadcms/translations against the merged object for one key per area, so a wrong shape fails in CI rather than in the browser
  • Component tests mock @payloadcms/ui (for example tests/components/Header.test.tsx). Add useTranslation to those mocks through one shared helper that resolves keys from en, so the existing English assertions keep passing unchanged, plus one Header test with an override
  • Manual in apps/cms: reproduction steps 2 to 4, then the Spanish admin with and without an es override

Seen on 1.10.1, unchanged on main at b645ef0c.

The long-form brief lists every hardcoded string by file and line with its proposed key, and carries the merge sketch and the edge cases.

Lingua principale
TypeScript
Stelle
34
Fork
5
Merge medio
2g 4h
PR unite (30g)
41

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di focusreactive/payload-plugins

Tutte le issue di focusreactive/payload-plugins

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.