Skip to content

fix(i18n): drop doubled locale prefix in Governance TOC links#57

Merged
JohnRDOrazio merged 1 commit intomainfrom
fix/governance-toc-double-locale
May 1, 2026
Merged

fix(i18n): drop doubled locale prefix in Governance TOC links#57
JohnRDOrazio merged 1 commit intomainfrom
fix/governance-toc-double-locale

Conversation

@JohnRDOrazio
Copy link
Copy Markdown
Member

@JohnRDOrazio JohnRDOrazio commented May 1, 2026

Closes #53.

Summary

GovernanceTOC was passing Polylang's already-locale-prefixed uri directly to next-intl's <Link>, which then prepended the locale again — Italian links became https://catholicdigitalcommons.org/it/it/governance-2/governanza-del-progetto.

This switches getChildPages to derive the EN canonical slug from each child's translations field (one extra GraphQL field per child, no extra round-trip) and passes it through to GovernanceTOC, which now composes the URL from the parent's path plus the EN slug. next-intl adds the locale prefix exactly once, matching the existing Header.tsx convention.

URLs continue to use EN slugs site-wide; switching to translated slugs in URLs is the bigger refactor tracked in #55, which depends on the slug strategy decision in discussion #56.

Files changed

  • lib/wordpress/queries.tsGET_CHILD_PAGES now requests translations { language { code } slug } instead of the unused uri.
  • lib/wordpress/api.tsWPChildPage exposes enSlug (EN canonical) instead of uri/slug. For EN locale, enSlug is the page's own slug; otherwise it's read off the EN translation.
  • app/[lang]/[[...slug]]/page.tsx — passes the current path as parentPath to PageRenderer.
  • components/sections/PageRenderer.tsx — forwards parentPath to renderGovernanceTOC<GovernanceTOC />. Drops unused page param from renderBlog (drive-by, clears a TS6133 LSP warning).
  • components/sections/GovernanceTOC.tsx — composes href as \${base}/${page.enSlug}`instead of consumingpage.uri`.

Test plan

  • Visit /it/governance → cards show Italian titles, link to /it/governance/<en-child-slug> (single locale prefix).
  • Visit /governance (EN default, no prefix) → cards link to /<en-child-slug> directly.
  • Repeat for /es/governance, /fr/governance, /pt/governance, /de/governance — each shows a single locale prefix and EN child slugs.
  • Click into a child page → loads correctly with locale-appropriate content (validates the URL still matches getPage's URI lookup).

Out of scope

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved multilingual page slug handling for governance sections
    • Enhanced parent-child page path navigation logic
    • Optimized child page data structure for consistent link generation across language variants

GovernanceTOC was passing Polylang's locale-prefixed `uri` directly
to next-intl's `<Link>`, which prepended the locale again — Italian
links became `/it/it/governance-2/governanza-del-progetto`.

Change `getChildPages` to derive the EN canonical slug from
`translations` (querying WPGraphQL+Polylang once) and pass it
through to GovernanceTOC, which now composes the URL from the
parent's path plus the EN slug. next-intl adds the locale prefix
exactly once, matching what Header.tsx already does.

URLs continue to use EN slugs site-wide; consuming the locale's
own translated slugs is tracked separately in #55.

Drive-by: drop unused `page` parameter on `renderBlog` to clear
a TS6133 LSP warning.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dad9ebd5-28b9-44e8-81f4-afaddf4efffc

📥 Commits

Reviewing files that changed from the base of the PR and between 92646d8 and bcb0f4a.

📒 Files selected for processing (5)
  • app/[lang]/[[...slug]]/page.tsx
  • components/sections/GovernanceTOC.tsx
  • components/sections/PageRenderer.tsx
  • lib/wordpress/api.ts
  • lib/wordpress/queries.ts

📝 Walkthrough

Walkthrough

Removes reliance on Polylang's uri field for child page links and instead uses computed enSlug derived from translation data. Threads parentPath context through PageRenderer to GovernanceTOC for proper link construction and lets next-intl handle locale-prefixing exactly once.

Changes

Cohort / File(s) Summary
Page rendering entry point
app/[lang]/[[...slug]]/page.tsx
Passes computed pageSlug as parentPath prop to PageRenderer invocation.
GovernanceTOC component
components/sections/GovernanceTOC.tsx
Added required parentPath prop to interface; now uses page.enSlug for keys and URL generation instead of page.slug/page.uri; constructs base prefix from parentPath (empty if /, otherwise /${parentPath}).
PageRenderer component
components/sections/PageRenderer.tsx
Accepts optional parentPath prop (defaults to /); threads it into GovernanceTOC rendering; simplified blog rendering by removing unused page argument to renderBlog.
Data fetching layer
lib/wordpress/api.ts, lib/wordpress/queries.ts
Removed uri field from GraphQL query; fetch per-node translation data with language codes. getChildPages now returns objects with computed enSlug (derived from English translation or fallback to node slug), title, and modified instead of uri.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • Issue #54: Addresses the same root cause pattern—misuse of locale-prefixed uri from Polylang vs. using slug/translation data for routing.
  • Issue #55: Directly related to translated-slug handling and navigation routing that this PR implements.

Poem

🐰 A double /it brought us such fright,
Polylang's uri wasn't quite right!
Now enSlug shines clear, with translations in tow,
One locale prefix—that's how we go!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: preventing doubled locale prefixes in Governance TOC links by shifting from Polylang URIs to slug-based routing.
Linked Issues check ✅ Passed All coding requirements from #53 are met: URIs removed from queries, enSlug computed from translations, parentPath threaded through components, and links composed to let next-intl add locale prefix once.
Out of Scope Changes check ✅ Passed All changes directly address the double-locale prefix bug in #53; no unrelated modifications detected. Minor cleanup of unused renderBlog parameter is incidental and appropriate.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/governance-toc-double-locale

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 12 complexity · 0 duplication

Metric Results
Complexity 12
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JohnRDOrazio JohnRDOrazio merged commit 9f482ac into main May 1, 2026
10 checks passed
@JohnRDOrazio JohnRDOrazio deleted the fix/governance-toc-double-locale branch May 1, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(i18n): double locale prefix in Governance TOC links

1 participant