feat(cli): add fern docs translation generate command for interactive i18n setup#15479
feat(cli): add fern docs translation generate command for interactive i18n setup#15479
fern docs translation generate command for interactive i18n setup#15479Conversation
Co-Authored-By: Deep Singhvi <deep@buildwithfern.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
| const translationsRegex = /^translations:\s*\n(?:\s+-[^\n]*\n?)*/m; | ||
| if (translationsRegex.test(rawContent)) { | ||
| return rawContent.replace(translationsRegex, translationsBlock + "\n"); |
There was a problem hiding this comment.
The regex pattern doesn't correctly match multi-line YAML list items. The pattern (?:\s+-[^\n]*\n?)* only matches lines that start with a dash (-), but YAML list items can have additional indented properties without dashes (like default: true).
For example, this existing block:
translations:
- lang: en
default: true
- lang: esWould only match up to - lang: en\n, stopping at default: true because it lacks a dash. This causes incomplete replacement, leaving orphaned YAML and corrupting the docs.yml file.
Fix: Use a more comprehensive regex that matches the entire YAML block:
const translationsRegex = /^translations:\s*\n(?:(?: |\t)+-[^\n]*\n(?:(?: |\t\t)+[^\n]+\n)*)*(?=\S|$)/m;Or use a YAML parser library to safely manipulate the structure instead of regex replacement.
| const translationsRegex = /^translations:\s*\n(?:\s+-[^\n]*\n?)*/m; | |
| if (translationsRegex.test(rawContent)) { | |
| return rawContent.replace(translationsRegex, translationsBlock + "\n"); | |
| const translationsRegex = /^translations:\s*\n(?:[ \t]+[^\n]*\n?)*/m; | |
| if (translationsRegex.test(rawContent)) { | |
| return rawContent.replace(translationsRegex, translationsBlock + "\n"); | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
…ion generate` Co-Authored-By: Deep Singhvi <deep@buildwithfern.com>
Co-Authored-By: Deep Singhvi <deep@buildwithfern.com>
fern docs translate command for interactive i18n setupfern docs translation generate command for interactive i18n setup
…ssues in CI Co-Authored-By: Deep Singhvi <deep@buildwithfern.com>
Co-Authored-By: Deep Singhvi <deep@buildwithfern.com>
E2E Test ReportBoth tests passed after fixing a bug found during testing. Bug Found & FixedThe regex in Test Results
Test 1: Fresh docs.ymlSetup: Minimal fern project with Assertions:
Test 2: Existing translationsSetup: Fern project with Assertions:
|
Description
Add a new
fern docs translation generatecommand that interactively sets up internationalization for Fern documentation sites.Changes Made
docsTranslate.ts— core command that detects existing translations/languages config, prompts for default and target languages, updatesdocs.yml, and createstranslations/<lang>/directoriesfern docs translation generatesubcommand incli.ts(nested command group)translationsconfig, and legacylanguagesfielddefault: truecontinuation lines)Testing
Link to Devin session: https://app.devin.ai/sessions/ccd7fd9e45ce416287a246d4a0a31b51
Requested by: @dsinghvi