feat(submissions): let submitters choose the content language#231
Conversation
Public submission forms (Submit Project, Refer Community Project, Refer Local Group) get a "Content language" dropdown at the top that defaults to the page's current locale via useLocale(). The selected language flows through the Next.js API route and lands on the WP REST handler, which validates against CDCF_LOCALE_NAMES and calls pll_set_post_language($post_id, $language) instead of the old hardcoded 'en'. Result: a Spanish-speaking submitter on /es/proyectos who clicks "Referir un proyecto comunitario" gets a form preselected to Spanish, submits Spanish content that lands as a Spanish post in WordPress, and the auto-translation worker (combined with the now-language- agnostic submission-publish pipeline shipped in PR #227/#228/#230) fans out to the OTHER 5 languages with the Polylang group linked end-to-end. No more manual "change to Spanish" step in wp-admin. Server-side validation rejects any language not in CDCF_LOCALE_NAMES with a 400, so a tampered request can't land posts in an unconfigured Polylang language. Defaults to 'en' when the field is absent so legacy callers keep working unchanged. Strings live under common.submissionLanguage / common.submissionLanguageHint in all 6 message files. The LanguageSwitcher's local localeLabels map moves to a new shared src/i18n/locale-labels.ts module so the modals can reuse it. Tests: 3 shared scenarios added to SubmissionHandlerTestBase (provided-honored, default-to-en, reject-unsupported) — 9 RED first across the 3 handlers, 9 GREEN after wiring cdcf_validate_submission_language. Full theme suite 588/588. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 50 minutes and 27 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. 📝 WalkthroughWalkthroughAdds an end-to-end submission language field across three public submission modals (refer community project, refer local group, submit project). A new shared ChangesSubmission Language Field (End-to-End)
Sequence Diagram(s)sequenceDiagram
participant User
participant SubmissionModal as SubmissionModal (React)
participant NextRoute as Next.js API Route
participant WPRest as WordPress REST API
participant Polylang
User->>SubmissionModal: selects language, submits form
SubmissionModal->>NextRoute: POST {fields..., language: "es"}
NextRoute->>WPRest: proxied POST {fields..., language: "es"}
WPRest->>WPRest: cdcf_validate_submission_language("es")
alt valid language
WPRest->>WPRest: wp_insert_post(pending)
WPRest->>Polylang: pll_set_post_language(post_id, "es")
WPRest-->>NextRoute: 200 OK
NextRoute-->>SubmissionModal: success
else invalid language
WPRest-->>NextRoute: 400 WP_Error(invalid_language)
NextRoute-->>SubmissionModal: error response
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 5 |
| Duplication | 12 |
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.
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@components/sections/ReferCommunityProjectModal.tsx`:
- Line 57: The language field is being collected in the
ReferCommunityProjectModal component at line 57 but is not being forwarded by
the send-code proxy route. Update the send-code route handler in
app/api/refer-community-project/send-code/route.ts to include the language field
when constructing the payload to proxy to WordPress, ensuring the language value
is preserved end-to-end throughout the entire workflow.
In `@src/i18n/locale-labels.ts`:
- Around line 6-8: The locale label values for Spanish, French, and Portuguese
in the locale-labels configuration are missing their standard diacritical marks,
making them incorrect spellings of the language autonyms. For the es property,
add the accent to spell the language name correctly. For the fr property, add
the accent to the language name. For the pt property, add the accent to the
language name. These corrections ensure the user-visible language labels display
proper spelling with appropriate diacritics.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b4f29ed8-93d8-4d48-bf2f-d293f0d0d30c
📒 Files selected for processing (20)
app/api/refer-community-project/route.tsapp/api/refer-local-group/route.tsapp/api/submit-project/route.tscomponents/LanguageSwitcher.tsxcomponents/sections/ReferCommunityProjectModal.tsxcomponents/sections/ReferLocalGroupModal.tsxcomponents/sections/SubmitProjectModal.tsxmessages/de.jsonmessages/en.jsonmessages/es.jsonmessages/fr.jsonmessages/it.jsonmessages/pt.jsonsrc/i18n/locale-labels.tswordpress/themes/cdcf-headless/functions.phpwordpress/themes/cdcf-headless/includes/handlers/refer-community-project.phpwordpress/themes/cdcf-headless/includes/handlers/refer-local-group.phpwordpress/themes/cdcf-headless/includes/handlers/submit-project.phpwordpress/themes/cdcf-headless/includes/security.phpwordpress/themes/cdcf-headless/tests/SubmissionHandlerTestBase.php
Locale labels migrated from LanguageSwitcher.tsx had been ASCII-stripped (Espanol / Francais / Portugues) — restore the proper autonyms (Español / Français / Português) so the language dropdown in the submission modals and the existing language switcher display the correctly-spelled native names. Per CodeRabbit review on PR #231. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Public submission forms (Submit Project, Refer Community Project, Refer Local Group) now expose a "Content language" dropdown at the top of the form. It defaults to the page's current locale via
useLocale(). The value flows: dropdown → modal body → Next.js API route → WP REST handler, which validates againstCDCF_LOCALE_NAMESand callspll_set_post_language($post_id, $language)instead of the old hardcoded'en'.Result: a Spanish-speaking submitter on
/es/proyectosclicks the referral button, gets a form preselected to Spanish, submits Spanish content that lands as a Spanish post in WordPress, and the auto-translation worker (now language-agnostic after #227/#228/#230) fans out to the other 5 languages with the Polylang group linked end-to-end. No more manual "change language to Spanish" step in wp-admin.Why
The 2026-06-16 "Enciclopedia Católica" regression exposed three independent hardcoded-EN bugs in the submission-publish pipeline (PRs #227, #228, #230) — but the underlying root cause was that the submission flow forced every post into EN at creation time, so reviewers had to manually re-tag the language in wp-admin to recover Spanish/Italian/etc. content. This closes the loop: the language is correct from creation.
Changes
wordpress/themes/cdcf-headless/includes/security.php— newcdcf_validate_submission_language()helper (empty →'en', allowlist viaCDCF_LOCALE_NAMES, returnsWP_Error invalid_language 400otherwise)refer-community-project.php,refer-local-group.php,submit-project.php) — validate up front, pass the resolved language topll_set_post_languagefunctions.php) — declarelanguagearg withsanitize_text_fieldanddefault => ''body.languagethrough to WP<select name="language">defaulting touseLocale(), with the 6 options sourced from a new sharedsrc/i18n/locale-labels.tsmodule (extracted fromLanguageSwitcher.tsx)common.submissionLanguage+common.submissionLanguageHintadded to all 6 message files (translated)Test plan
composer test --working-dir=wordpress/themes/cdcf-headless— 588/588 pass (+9 new tests inSubmissionHandlerTestBase: provided-honored, default-to-en, reject-unsupported × 3 handlers)npm run build— compiles successfully/es/proyectos, opened the Refer Community Project modal — dropdown shows "Idioma del contenido" with "Espanol" preselected and the translated hint below/es/proyectos, approve in wp-admin, verify the source post is ES (no manual re-tag), then watch the worker auto-translate to the other 5 with the Polylang group linked🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests