Skip to content

Fix structured text translation for soft line breaks, links, and inline blocks - #79

Open
thales-goncalves wants to merge 2 commits into
voorhoede:mainfrom
thales-goncalves:fix/soft-line-break-translation
Open

thales-goncalves wants to merge 2 commits into
voorhoede:mainfrom
thales-goncalves:fix/soft-line-break-translation

Conversation

@thales-goncalves

@thales-goncalves thales-goncalves commented Apr 9, 2026 •

Copy link
Copy Markdown

Summary

Root causes and fixes

Soft line breaks (#77): getValueType misclassified text containing \n as markdown (matched markdownparagraph regex), and getStructuredTextTranslation only translated PathType.text spans. Fix: check path.key === 'text' instead of path.type === PathType.text.

Node type handling (#73): isStructuredTextText used rigid key-count checks that only matched nodes with exact key combinations (type + children, optionally level/style). Nodes like link (has url), itemLink (has item), and inlineBlock were not recognized. Fix:

  • Broadened isStructuredTextText to recognize any node with type + children (excluding blocks, inline items, and code)
  • Extended isStructuredTextBlock to also handle inlineBlock nodes
  • Added item key to the ID protection list in getValueType

Node types now handled

Node type Status
softBreak (\n in text) Fixed — text now translated
link Fixed — text translated, URL preserved
itemLink Fixed — text translated, item reference preserved
inlineBlock Fixed — handled like block
inlineItem Already worked
block Already worked

Test plan

  • 8 new tests added (105 total, all passing)
  • Soft line break text spans are translated
  • Link text translated, URLs preserved
  • itemLink text translated, item references preserved
  • inlineItem nodes preserved without crash
  • block nodes preserved without crash
  • inlineBlock nodes handled correctly
  • All existing tests still pass

…tion

Spans with \n were misclassified as markdown, causing them to be skipped.

Fixes voorhoede#77
@netlify

netlify Bot commented Apr 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for datocms-plugin-translate-fields ready!

Name Link
🔨 Latest commit 7caf1c5
🔍 Latest deploy log https://app.netlify.com/projects/datocms-plugin-translate-fields/deploys/69d7d78ce7fb35000872e60f
😎 Deploy Preview https://deploy-preview-79--datocms-plugin-translate-fields.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

…lock)

Fixes voorhoede#73

- Broaden isStructuredTextText to recognize any node with type + children
- Extend isStructuredTextBlock to handle inlineBlock nodes
- Add item key to ID protection list
@thales-goncalves thales-goncalves changed the title Fix structured text spans with soft line breaks skipped during translation Fix structured text translation for soft line breaks, links, and inline blocks Apr 9, 2026
@Siilwyn

Siilwyn commented Apr 15, 2026

Copy link
Copy Markdown
Member

🌊 Thanks you for your contribution! I like the concept of this change, but I briefly discussed this with @velomovies and we are afraid this might introduce other bugs regarding field detection.
Instead of duck typing the field types we're thinking of using Dato's schema to handle the different types of fields to translate.
Looks like Dato's own AI translation plugin does this mainly here:
https://github.com/datocms/plugins/blob/master/ai-translations/src/utils/schemaRepository.ts

What do you think of this? Perhaps you'd rather use their plugin, I'm curious if you prefer our plugin for a specific reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants