Skip to content

[codex] fix translated internal links#644

Merged
riderx merged 3 commits into
mainfrom
codex/fix-translated-internal-links
May 6, 2026
Merged

[codex] fix translated internal links#644
riderx merged 3 commits into
mainfrom
codex/fix-translated-internal-links

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented May 6, 2026

Summary

Fix translated pages so internal links are rewritten to the active locale path during the translation-worker metadata/link pass.

Root cause

The previous link rewrite only handled root-relative paths like /pricing. Auto-translated HTML could still keep same-site absolute URLs, protocol-relative URLs, and relative links pointing at the default language route.

Changes

  • Localize same-host href and action values across root-relative, relative, protocol-relative, and same-site http(s) forms.
  • Leave external links, same-page anchors, non-http schemes, and static/asset paths unchanged.
  • Bump the translation cache version so cached translated pages regenerate with corrected links.
  • Add parser coverage for internal and non-internal link rewrite behavior.

Validation

  • bunx prettier --write apps/translation-worker/src/index.ts apps/translation-worker/scripts/verify-parser.ts
  • bun run ci:verify:translation
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Improved URL localization for metadata and links, with enhanced handling of root‑relative, absolute, protocol‑relative and relative paths; form actions, anchors, and asset references are now more reliably locale-aware.
  • Tests

    • Added validation tests that verify metadata and link localization for the French locale across various link types.
  • Chores

    • Bumped translation cache version and made minor internal alignment improvements to URL handling.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@riderx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 17 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c384dbab-0b90-42f5-b061-141ef1238bfb

📥 Commits

Reviewing files that changed from the base of the PR and between 5fbf7b7 and da98f19.

📒 Files selected for processing (2)
  • apps/translation-worker/scripts/verify-parser.ts
  • apps/translation-worker/src/index.ts
📝 Walkthrough

Walkthrough

Introduces context-aware URL localization in the translation worker: adds scheme/url helpers and a request-aware localizeHref, updates tag-attribute localization to use it, bumps the translation cache version, exposes rewriteMetadataAndLinks on the test API, and adds a FR localization test for metadata and links.

Changes

URL Localization Improvements

Layer / File(s) Summary
Data / Constants
apps/translation-worker/src/index.ts
TRANSLATION_CACHE_VERSION updated to a new "localized-links" v6 value.
URL Utility Functions
apps/translation-worker/src/index.ts
Added hasUrlScheme() and isHttpUrl() helpers; implemented localizeHref(value, locale, requestUrl) with scheme validation and host-aware handling.
Core Localization Integration
apps/translation-worker/src/index.ts
Replaced prior shouldLocalizeHref/old localizeHref logic; localizeTagUrlAttributes() updated to call the new 3-argument localizeHref() and handle alternate link cases.
Public Test Export
apps/translation-worker/src/index.ts
Added rewriteMetadataAndLinks to the __translationWorkerTest export object.
Tests
apps/translation-worker/scripts/verify-parser.ts
New FR test block exercising rewriteMetadataAndLinks and asserting localization/rewrites for many link types (root-relative, absolute same-site, protocol-relative, relative, anchors, external, mail, assets, form actions).

Sequence Diagram(s)

(Skipped — changes are targeted utility and integration updates without a multi-component sequential flow that requires visualization.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Cap-go/website#633: Both PRs modify apps/translation-worker/src/index.ts and update the TRANSLATION_CACHE_VERSION constant.
  • Cap-go/website#609: Overlapping changes to URL localization and metadata handling in apps/translation-worker/src/index.ts.
  • Cap-go/website#620: Related modifications to translation-worker tests and parser verification tooling; both expose/expand test APIs.

Poem

🐰 I hop through links both near and far,
I give each href a localized star.
With schemes and hosts checked by light,
FR paths appear just right.
Cache bumped, tests hum — translation’s on par!

🚥 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 '[codex] fix translated internal links' directly aligns with the main objective—fixing translated pages so internal links are rewritten to the active locale path during translation-worker processing.
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 codex/fix-translated-internal-links

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

@riderx riderx force-pushed the codex/fix-translated-internal-links branch from cc1c34c to 9cd7a51 Compare May 6, 2026 11:32
@riderx riderx marked this pull request as ready for review May 6, 2026 11:37
@riderx
Copy link
Copy Markdown
Member Author

riderx commented May 6, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

✅ Actions performed

Review triggered.

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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9cd7a51e61

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/translation-worker/src/index.ts
@riderx
Copy link
Copy Markdown
Member Author

riderx commented May 6, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

✅ Actions performed

Review triggered.

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.

@riderx
Copy link
Copy Markdown
Member Author

riderx commented May 6, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

✅ Actions performed

Review triggered.

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/translation-worker/scripts/verify-parser.ts (1)

58-93: ⚡ Quick win

Add an explicit http:// same-site regression case.

This block covers https:// and // inputs, but the new logic also has a dedicated same-site http(s) path. Adding one http://capgo.app/... assertion would keep that branch from regressing silently.

Proposed test addition
   <body>
     <a href="/pricing">Pricing</a>
+    <a href="http://capgo.app/changelog">Changelog</a>
     <a href="https://capgo.app/docs/">Docs</a>
     <a href="//capgo.app/plugins">Plugins</a>
     <a href="features">Features</a>
@@
 assert(localizedLinksHtml.includes('hreflang="fr" href="https://capgo.app/fr/blog/post"'), 'Link rewrite changed the French hreflang alternate')
 assert(localizedLinksHtml.includes('href="/fr/pricing"'), 'Link rewrite did not localize root-relative internal links')
+assert(localizedLinksHtml.includes('href="http://capgo.app/fr/changelog"'), 'Link rewrite did not localize absolute same-site http links')
 assert(localizedLinksHtml.includes('href="https://capgo.app/fr/docs/"'), 'Link rewrite did not localize absolute same-site links')
 assert(localizedLinksHtml.includes('href="//capgo.app/fr/plugins"'), 'Link rewrite did not localize protocol-relative same-site links')
🤖 Prompt for 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.

In `@apps/translation-worker/scripts/verify-parser.ts` around lines 58 - 93, Add
an explicit HTTP same-site case: include an anchor like <a
href="http://capgo.app/docs/">HTTP Docs</a> in the HTML passed to
rewriteMetadataAndLinks and add an assertion that
localizedLinksHtml.includes('href="http://capgo.app/fr/docs/"') to ensure the
http:// same-site branch in rewriteMetadataAndLinks (the function under test) is
exercised and does not regress; reference the localizedLinksHtml variable and
rewriteMetadataAndLinks call to locate where to add the input and assertion.
🤖 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.

Nitpick comments:
In `@apps/translation-worker/scripts/verify-parser.ts`:
- Around line 58-93: Add an explicit HTTP same-site case: include an anchor like
<a href="http://capgo.app/docs/">HTTP Docs</a> in the HTML passed to
rewriteMetadataAndLinks and add an assertion that
localizedLinksHtml.includes('href="http://capgo.app/fr/docs/"') to ensure the
http:// same-site branch in rewriteMetadataAndLinks (the function under test) is
exercised and does not regress; reference the localizedLinksHtml variable and
rewriteMetadataAndLinks call to locate where to add the input and assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7cb3642a-80a9-4529-bb57-afa60d89e0bf

📥 Commits

Reviewing files that changed from the base of the PR and between 9cd7a51 and 5fbf7b7.

📒 Files selected for processing (2)
  • apps/translation-worker/scripts/verify-parser.ts
  • apps/translation-worker/src/index.ts

@riderx riderx merged commit 8445d91 into main May 6, 2026
8 checks passed
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2026

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