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

オープン
#187 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
34
フォーク
5
平均マージ
2日 4時間
マージ済み PR(30日)
41

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

focusreactive/payload-plugins のほかの issue

focusreactive/payload-plugins の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。