feat(cli): expose /cdcf/v1/translate-all as first-class scripts/cdcf_api.py command#207
Conversation
…api.py command The REST endpoint has existed since #156 and we hit a real use case for it today (post 1508 Eucharistic Miracles — needed to refire the atomic 5-language fan-out after the publish hook left the polylang group disconnected). The workaround was: scripts/.venv/bin/python scripts/cdcf_api.py --target production \ rest-post cdcf/v1/translate-all --data '{"source_id":1508}' which works but is awkward for a documented endpoint we expect to use repeatedly (admin-authored CPTs that bypass the publish hook, recovery from any future polylang-group disconnect, etc.). The Python client already exposes translate-post (per-language) and link-translations (post-side) and link-term-translations (term-side, from #205); adding translate-all rounds out the translation surface. Changes: - CdcfClient.translate_all(source_id) → POST /cdcf/v1/translate-all - CLI subcommand `translate-all --source-id N` - Help text documents the atomic shape + recovery use cases Usage: scripts/.venv/bin/python scripts/cdcf_api.py --target production \ translate-all --source-id 1508 Scripts-only change — no backend deploy needed. Smoke-tested locally; the existing translate-post / deploy-translation patterns are followed verbatim. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 46 minutes and 28 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ 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. 📝 WalkthroughWalkthroughThis PR adds atomic multi-language translation support to the CDCF client library. A new ChangesTranslate-all API and CLI
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 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 |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
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: 1
🤖 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 `@scripts/cdcf_api.py`:
- Around line 403-420: The translate_all method accepts any integer and can
forward negative IDs that backend absint will coerce to a different positive ID;
add a client-side validation in translate_all to ensure source_id is an int > 0,
raising a clear exception (e.g., ValueError) if the check fails, and only call
self._wp_post("cdcf/v1/translate-all", {"source_id": source_id}) when the value
passes; keep the check inside the translate_all method so CLI callers are
protected as well.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
CodeRabbit on #207 flagged that translate_all accepts any integer and forwards it directly to /cdcf/v1/translate-all. The backend's absint() sanitization silently coerces a negative ID into a different positive ID, which would enqueue translations for the wrong source post — a real silent-data-corruption defect. Adds an explicit `source_id <= 0` guard that raises ValueError with a clear message. The CLI (argparse type=int) already constrained input to integers, but library callers had no protection; this closes that gap. Other client methods that take IDs (link_translations, link_term_translations) are already protected by #205's cdcf_sanitize_translations_map dropping non-positive values — only translate_all sent a single scalar through with no sanitizer in path. Smoke-tested: source_id=0, -1, -1000 all raise ValueError before any HTTP call. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Adds
CdcfClient.translate_all(source_id)+ atranslate-allCLI subcommand that wraps the existing/cdcf/v1/translate-allREST endpoint.Why
The REST endpoint has existed since #156 and we hit a real use case for it today — post 1508 "Eucharistic Miracles" needed to re-fan-out translations after the publish hook left the Polylang group disconnected. The workaround was the generic
rest-post:scripts/.venv/bin/python scripts/cdcf_api.py --target production \ rest-post cdcf/v1/translate-all --data '{"source_id":1508}'which works but is awkward for a documented endpoint we'll likely use repeatedly:
cdcf_enqueue_translations_on_publish(it gates oncdcf_is_public_submission), so admins who want translations need an explicit invocationThe Python client already exposes the per-language
translate-post, the post-sidelink-translations, and the term-sidelink-term-translations(from #205). Addingtranslate-allrounds out the translation REST surface.Test plan
scripts/cdcf_api.py translate-all --helpworks and shows the help textscripts/cdcf_api.py --helpliststranslate-allbetweentranslate-postanddeploy-translationNotes
lib/wordpress/*per CLAUDE.md), so no test changes. The implementation mirrorstranslate_post+deploy_translationverbatim — same pattern, same auth, same error handling via_wp_post.Related
/cdcf/v1/translate-allREST endpoint🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
translate-allCLI command that accepts a--source-idparameter to perform atomic multi-language translation across 5 languages in a single operation.