Skip to content

Optimize label translation to skip already-translated labels - #80

Merged
KallynGowdy merged 1 commit into
mainfrom
claude/relaxed-tesla-llczi5
Oct 7, 2026
Merged

KallynGowdy merged 1 commit into
mainfrom
claude/relaxed-tesla-llczi5

Conversation

@KallynGowdy

Copy link
Copy Markdown
Collaborator

Summary

This change optimizes the documentation translation process by only translating newly added labels, rather than re-translating the entire labels file on every run. Previously, all labels were sent for translation each time, even if they hadn't changed.

Key Changes

  • Modified translateLabels() function to accept an existing parameter containing previously translated labels, allowing the function to skip re-translating unchanged labels
  • Updated label collection logic to only gather strings that don't already have translations, reducing API calls and translation costs
  • Added countMissingLabels() helper function to count how many labels need translation, enabling better user feedback
  • Improved staleness detection in the main translation flow to determine when labels need re-translation:
    • If the English labels file is newer than the translation output, all labels are re-translated (in case existing labels were reworded)
    • If the translation is up-to-date, existing translations are reused and only new labels are translated
    • The --force flag still triggers a full re-translation
  • Enhanced console output to show how many labels were translated, providing visibility into the translation work performed

Implementation Details

  • The collect() and rebuild() functions now traverse both the current labels and existing translations in parallel, comparing keys at each level
  • Empty translation requests are handled gracefully (no API call if no new labels need translation)
  • The logic preserves the hierarchical structure of labels while selectively translating only new entries

https://claude.ai/code/session_01YMDJWsX8SQrGwpxLydExuZ

The translate script skipped docs/<language>/labels.json whenever it was
newer than the English labels.json, so the home, footer and 404 text
added under the existing nav labels was never translated without
--force. It now translates just the labels a translation is missing,
keeping the ones already there, and still translates everything again
with --force or when the English file has been edited since.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YMDJWsX8SQrGwpxLydExuZ
@KallynGowdy
KallynGowdy merged commit b80f20c into main Oct 7, 2026
3 checks passed
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.

2 participants