Skip to content

docs: relocalize stale locale links#61796

Merged
hxy91819 merged 12 commits into
mainfrom
fix-docs-localized-links
Apr 6, 2026
Merged

docs: relocalize stale locale links#61796
hxy91819 merged 12 commits into
mainfrom
fix-docs-localized-links

Conversation

@hxy91819

@hxy91819 hxy91819 commented Apr 6, 2026

Copy link
Copy Markdown
Member

Summary

  • switch docs i18n to a single locale-link postprocess stage instead of localizing links both during per-page translation and again afterward
  • scope postprocessing to only the localized files successfully emitted in the current run
  • add regression tests covering stale index-page links and scoped postprocess behavior
  • add a pipeline-level regression test that runs the docs-i18n main flow with a fake translator and asserts the final localized page links are corrected
  • touch the gateway runbook copy so zh-CN and ja-JP regenerate and pick up the fixed localized links

Verification trigger

  • the tiny wording-only change in docs/gateway/index.md is intentional
  • it forces the /gateway locale pages back through the publish/translation pipeline so we can verify the stale locale-link fix actually propagates in openclaw/docs
  • this keeps the validation tied to the real generated locale flow instead of relying only on local fixtures

Test plan

  • go test ./... in scripts/docs-i18n

Root cause

  • the existing pipeline previously localized links while translating each individual page
  • files are processed in path-sorted order (scripts/docs-i18n/order.go), so index pages like gateway/index.md can be translated before locale child pages such as gateway/troubleshooting.md exist
  • link localization only prefixes a route when the localized target page already exists in localizedRoutes (scripts/docs-i18n/localized_links.go)
  • doc-mode skip logic only compares the English source hash (scripts/docs-i18n/doc_mode.go), so once a page is written with stale English links it will usually be skipped on later runs unless the English source changes

Design

Current design before this PR:

flowchart TD
    A[Collect changed English docs] --> B[Sort files by relative path]
    B --> C[Translate one page]
    C --> D[Try to localize links immediately]
    D --> E{Does localized target page already exist?}
    E -- yes --> F[Write locale-prefixed link]
    E -- no --> G[Keep English root-relative link]
    F --> H[Write localized page]
    G --> H
    H --> I[Future runs compare only source_hash]
    I --> J[Page usually skipped unless English source changes]
Loading

Redesigned flow in this PR:

flowchart TD
    A[Collect changed English docs] --> B[Sort files by relative path]
    B --> C[Translate one page]
    C --> D[Write localized page without link rewriting]
    D --> E{Page write succeeded?}
    E -- yes --> F[Add output path to successful file set]
    E -- no --> G[Return run error]
    F --> H[Repeat for remaining pages]
    G --> I[Stop translation loop]
    H --> J[Save translation memory]
    I --> J
    J --> K[Build route index from full locale tree]
    K --> L[Postprocess only files in successful file set]
    L --> M[Rewrite links using final localized route set]
    M --> N[Exit success or return original run error]

    classDef highlight fill:#ffe8a3,stroke:#b7791f,stroke-width:2px,color:#111;
    classDef success fill:#d9f99d,stroke:#4d7c0f,stroke-width:2px,color:#111;
    class F,L,M highlight;
    class E success;
Loading

What changed in the design

  • removed duplicate link-localization logic from the translation path
  • made localization order-independent by rewriting links only after the target locale tree exists
  • kept localized_links.go as the single place that decides whether a route should gain a locale prefix
  • scoped postprocessing to the files successfully emitted in the current run, so failed runs do not rewrite unrelated localized docs
  • preserved partial-run correctness by still postprocessing files that were successfully written before a later failure

Context

  • fixes stale localized links like /zh-CN/gateway and /ja-JP/gateway pointing some body links at English routes even when localized target pages exist
  • also explains why pages like /zh-CN/providers could already look correct: those links were localized successfully because their target locale pages already existed when that page was translated

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: S maintainer Maintainer-authored PR labels Apr 6, 2026
@greptile-apps

greptile-apps Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a longstanding ordering bug in the docs i18n pipeline where index pages translated before their child locale pages existed would retain stale English links instead of locale-prefixed ones. The fix decouples link localization from the per-page translation step and instead runs a single postprocess pass (postprocessLocalizedDocs) over the full locale tree after all translations are written — ensuring localizeBodyLinks always sees the complete route index.

Key changes:

  • Removed the routes *routeIndex parameter from processFileDoc, processFile, and their callers — link rewriting no longer happens during translation
  • Added relocalize.go with postprocessLocalizedDocs, which loads the route index after the full locale tree exists and rewrites any remaining English-root links that now have localized targets
  • Moved loadRouteIndex from main() startup to inside postprocessLocalizedDocs, so it always executes against the final translated file set
  • Changed error handling in main() from early-exit fatal calls to a deferred runErr variable so that tm.Save() and the postprocess step always run even when translation partially fails
  • Added a regression test that creates a stale zh-CN gateway/index.md with an English link, creates the localized troubleshooting.md, runs postprocessLocalizedDocs, and asserts both front matter integrity and link rewriting — directly addressing the concerns raised in the previous review round

Confidence Score: 5/5

Safe to merge; the redesign is correct and all prior review concerns have been addressed in this revision.

The previous P1 concern about missing newline before the closing front-matter delimiter is resolved: the reconstruction in relocalize.go uses '"---
" + frontMatter + "
---

"', which correctly separates the YAML block from the body. The follow-up concern about the test not validating front matter structure is also addressed — the test now asserts the exact front-matter string. The core logic is sound: deferring loadRouteIndex to run after translation completes makes link-rewriting fully order-independent. No P0 or P1 issues remain; only a trivial stdlib-vs-helper style nit on stringsJoin.

No files require special attention.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: scripts/docs-i18n/relocalize_test.go
Line: 50-58

Comment:
**Redundant `stringsJoin` helper**

This helper is functionally identical to `strings.Join(lines, "\n")` from the standard library. Replacing it keeps the test helpers minimal and avoids dead code.

```suggestion
func stringsJoin(lines ...string) string {
	return strings.Join(lines, "\n")
}
```

How can I resolve this? If you propose a fix, please make it concise.

Greploops — Automatically fix all review issues by running /greploops in Claude Code. It iterates: fix, push, re-review, repeat until 5/5 confidence.
Use the Greptile plugin for Claude Code to query reviews, search comments, and manage custom context directly from your terminal.

Reviews (2): Last reviewed commit: "docs: relocalize partial docs runs" | Re-trigger Greptile

Comment thread scripts/docs-i18n/relocalize.go Outdated
Comment thread scripts/docs-i18n/relocalize_test.go

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

Copy link
Copy Markdown
Contributor

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: dfb90dde2c

ℹ️ 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 scripts/docs-i18n/relocalize.go Outdated

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

Copy link
Copy Markdown
Contributor

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: b71837c365

ℹ️ 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 scripts/docs-i18n/main.go Outdated
@hxy91819

hxy91819 commented Apr 6, 2026

Copy link
Copy Markdown
Member Author

@greptile-apps review
@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ 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".

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

Copy link
Copy Markdown
Contributor

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: 56b80002cd

ℹ️ 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 scripts/docs-i18n/relocalize.go Outdated
@hxy91819

hxy91819 commented Apr 6, 2026

Copy link
Copy Markdown
Member Author

@codex review

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

Copy link
Copy Markdown
Contributor

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: e31e1dc59b

ℹ️ 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 scripts/docs-i18n/main.go Outdated
@hxy91819 hxy91819 self-assigned this Apr 6, 2026
@hxy91819
hxy91819 force-pushed the fix-docs-localized-links branch from dea1f52 to 3c90456 Compare April 6, 2026 11:36
@hxy91819

hxy91819 commented Apr 6, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Delightful!

ℹ️ 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".

@hxy91819
hxy91819 force-pushed the fix-docs-localized-links branch 4 times, most recently from 3082ae7 to 11e5d14 Compare April 6, 2026 14:14
@hxy91819

hxy91819 commented Apr 6, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ 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".

@hxy91819
hxy91819 force-pushed the fix-docs-localized-links branch 2 times, most recently from 236c5b5 to 5b69b22 Compare April 6, 2026 14:28
@hxy91819
hxy91819 force-pushed the fix-docs-localized-links branch from 5b69b22 to faa6890 Compare April 6, 2026 14:34
@hxy91819
hxy91819 merged commit 9b0ea7c into main Apr 6, 2026
9 checks passed
@hxy91819
hxy91819 deleted the fix-docs-localized-links branch April 6, 2026 14:37

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

Copy link
Copy Markdown
Contributor

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: faa6890309

ℹ️ 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 on lines 77 to +78
output := updatedFront + translatedBody
return false, os.WriteFile(outputPath, []byte(output), 0o644)
return false, outputPath, os.WriteFile(outputPath, []byte(output), 0o644)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Avoid finalizing doc output before relocalize succeeds

This writes the translated file (including a fresh x-i18n.source_hash) before link relocalization runs in runDocsI18N, so if the later postprocessLocalizedDocs step errors (for example on route-index/file I/O), the doc is left with stale English-root links but will be treated as up-to-date on retry with --overwrite=false via shouldSkipDoc. That makes a failed run sticky: reruns can skip the broken file indefinitely unless the source changes or overwrite is forced.

Useful? React with 👍 / 👎.

steipete pushed a commit to leoleedev/openclaw that referenced this pull request Apr 6, 2026
* docs: relocalize stale locale links

* docs: unify locale link postprocessing

* docs: preserve relocalized frontmatter

* docs: relocalize partial docs runs

* docs: scope locale link postprocessing

* docs: continue scoped relocalization

* docs: drain parallel i18n results

* docs: add i18n pipeline link regression tests

* docs: clarify i18n pipeline regression test intent

* docs: update provider references in i18n tests to use example-provider

* fix: note docs i18n link relocalization

* docs: rephrase gateway local ws sentence
Mlightsnow pushed a commit to Mlightsnow/openclaw that referenced this pull request Apr 6, 2026
* docs: relocalize stale locale links

* docs: unify locale link postprocessing

* docs: preserve relocalized frontmatter

* docs: relocalize partial docs runs

* docs: scope locale link postprocessing

* docs: continue scoped relocalization

* docs: drain parallel i18n results

* docs: add i18n pipeline link regression tests

* docs: clarify i18n pipeline regression test intent

* docs: update provider references in i18n tests to use example-provider

* fix: note docs i18n link relocalization

* docs: rephrase gateway local ws sentence
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
* docs: relocalize stale locale links

* docs: unify locale link postprocessing

* docs: preserve relocalized frontmatter

* docs: relocalize partial docs runs

* docs: scope locale link postprocessing

* docs: continue scoped relocalization

* docs: drain parallel i18n results

* docs: add i18n pipeline link regression tests

* docs: clarify i18n pipeline regression test intent

* docs: update provider references in i18n tests to use example-provider

* fix: note docs i18n link relocalization

* docs: rephrase gateway local ws sentence
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
* docs: relocalize stale locale links

* docs: unify locale link postprocessing

* docs: preserve relocalized frontmatter

* docs: relocalize partial docs runs

* docs: scope locale link postprocessing

* docs: continue scoped relocalization

* docs: drain parallel i18n results

* docs: add i18n pipeline link regression tests

* docs: clarify i18n pipeline regression test intent

* docs: update provider references in i18n tests to use example-provider

* fix: note docs i18n link relocalization

* docs: rephrase gateway local ws sentence
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
* docs: relocalize stale locale links

* docs: unify locale link postprocessing

* docs: preserve relocalized frontmatter

* docs: relocalize partial docs runs

* docs: scope locale link postprocessing

* docs: continue scoped relocalization

* docs: drain parallel i18n results

* docs: add i18n pipeline link regression tests

* docs: clarify i18n pipeline regression test intent

* docs: update provider references in i18n tests to use example-provider

* fix: note docs i18n link relocalization

* docs: rephrase gateway local ws sentence
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* docs: relocalize stale locale links

* docs: unify locale link postprocessing

* docs: preserve relocalized frontmatter

* docs: relocalize partial docs runs

* docs: scope locale link postprocessing

* docs: continue scoped relocalization

* docs: drain parallel i18n results

* docs: add i18n pipeline link regression tests

* docs: clarify i18n pipeline regression test intent

* docs: update provider references in i18n tests to use example-provider

* fix: note docs i18n link relocalization

* docs: rephrase gateway local ws sentence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant