Skip to content

feat(cli): expose /cdcf/v1/translate-all as first-class scripts/cdcf_api.py command#207

Merged
JohnRDOrazio merged 2 commits into
mainfrom
feat/python-client-translate-all
Jun 11, 2026
Merged

feat(cli): expose /cdcf/v1/translate-all as first-class scripts/cdcf_api.py command#207
JohnRDOrazio merged 2 commits into
mainfrom
feat/python-client-translate-all

Conversation

@JohnRDOrazio

@JohnRDOrazio JohnRDOrazio commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary

Adds CdcfClient.translate_all(source_id) + a translate-all CLI subcommand that wraps the existing /cdcf/v1/translate-all REST endpoint.

scripts/.venv/bin/python scripts/cdcf_api.py --target production translate-all --source-id 1508

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:

  • Admin-authored CPTs bypass cdcf_enqueue_translations_on_publish (it gates on cdcf_is_public_submission), so admins who want translations need an explicit invocation
  • Recovery from any future Polylang-group disconnect (the today-incident scenario)
  • Re-running translations when the source was edited and you want all siblings refreshed

The Python client already exposes the per-language translate-post, the post-side link-translations, and the term-side link-term-translations (from #205). Adding translate-all rounds out the translation REST surface.

Test plan

  • scripts/cdcf_api.py translate-all --help works and shows the help text
  • scripts/cdcf_api.py --help lists translate-all between translate-post and deploy-translation
  • After merge: verify against a test source post on local docker (or production if there's a real need)

Notes

  • Scripts-only change — no backend code touched, no theme deploy needed. Standard merge → done.
  • The Python client has no test suite (Vitest only covers lib/wordpress/* per CLAUDE.md), so no test changes. The implementation mirrors translate_post + deploy_translation verbatim — same pattern, same auth, same error handling via _wp_post.

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a translate-all CLI command that accepts a --source-id parameter to perform atomic multi-language translation across 5 languages in a single operation.

…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>
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@JohnRDOrazio, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 616050f3-f256-4aa7-bb4a-c7d6bb504af3

📥 Commits

Reviewing files that changed from the base of the PR and between e913967 and 0818d18.

📒 Files selected for processing (1)
  • scripts/cdcf_api.py
📝 Walkthrough

Walkthrough

This PR adds atomic multi-language translation support to the CDCF client library. A new translate_all() API method POSTs to cdcf/v1/translate-all with a source document ID, triggering a coordinated 5-language translation fan-out. The CLI is wired with a new translate-all command to expose this functionality to users.

Changes

Translate-all API and CLI

Layer / File(s) Summary
API client translate-all method
scripts/cdcf_api.py
CdcfClient.translate_all(source_id) method posts to cdcf/v1/translate-all with detailed docstring describing atomic fan-out behavior and use cases.
CLI command and dispatch
scripts/cdcf_api.py
CLI argument parser adds translate-all subcommand accepting --source-id, and command dispatch handler routes the command to client.translate_all(args.source_id).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • CatholicOS/cdcf-website#195: Both PRs wire up the same "translate-all" flow: the main PR adds CdcfClient.translate_all()/CLI support to POST cdcf/v1/translate-all, while the retrieved PR implements that POST /cdcf/v1/translate-all handler that performs the atomic pll_save_post_translations() fan-out.

Poem

🐰 A whisker-twitch of joy! One method hops,
Five languages translate without a stop,
The CLI cheers with args held tight,
Atomic magic in the night! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.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 change: exposing the /cdcf/v1/translate-all endpoint as a first-class CLI command in scripts/cdcf_api.py, which aligns with the primary objective of adding a new client method and subcommand.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/python-client-translate-all

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

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

@codacy-production

codacy-production Bot commented Jun 11, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 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

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 87adf1f7-c6bb-4014-abcb-89333c1b060e

📥 Commits

Reviewing files that changed from the base of the PR and between bcdac84 and e913967.

📒 Files selected for processing (1)
  • scripts/cdcf_api.py

Comment thread scripts/cdcf_api.py
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>
@JohnRDOrazio JohnRDOrazio merged commit a13dde5 into main Jun 11, 2026
10 checks passed
@JohnRDOrazio JohnRDOrazio deleted the feat/python-client-translate-all branch June 11, 2026 13:19
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.

1 participant