👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

Improving JSON output of portable text field for translation agency

2 replies
Last updated: Oct 25, 2022
Does anyone have advice on improving the JSON output of a portable text field for translation agency?
I was considering when output the JSON - transform the portable text to markdown but didn’t find a plugin for that - but the reverse conversion
rehype-portable-text .
For example this sentence with links and output of the JSON. Attached the screenshot as well :

This is a portable text and in this sentence there are a lot of links.
link 1 , how can I output this field so is easy for translator as the link location varies from languages link 2 . More links in this link 3 .

"subtitle": [
  {
    "_type": "block",
    "_key": "e125fa095c8a",
    "style": "normal",
    "markDefs": [
      {
        "_type": "link",
        "_key": "eb3b55992f09",
        "href": "<https://google.com/link-1>"
      },
      {
        "_type": "link",
        "_key": "2fd67784fee6",
        "href": "<https://google.com/link-2>"
      },
      {
        "_type": "link",
        "_key": "fb569bc0614c",
        "href": "<https://google.com/link-3>"
      }
    ],
    "children": [
      {
        "_type": "span",
        "_key": "63a1b71fbccc",
        "text": "This is a portable text and in this sentence there are a lot of links. ",
        "marks": []
      },
      {
        "_type": "span",
        "_key": "90f230f1d10f",
        "marks": [
          "eb3b55992f09"
        ],
        "text": "link 1"
      },
      {
        "_type": "span",
        "_key": "10e1728b3854",
        "marks": [],
        "text": ", how can I output this field so is easy for translator as the link location varies from languages "
      },
      {
        "_type": "span",
        "_key": "9e74fff5c227",
        "marks": [
          "2fd67784fee6"
        ],
        "text": "link 2"
      },
      {
        "_type": "span",
        "_key": "2dd0ac409b87",
        "marks": [],
        "text": ". More links in this "
      },
      {
        "_type": "span",
        "_key": "de78638bd890",
        "marks": [
          "fb569bc0614c"
        ],
        "text": "link 3."
      }
    ]
  }
]
The problem is that the word order isn’t usually the same in other languages than in English. So for this example,
link 1
are not necessarily the beginning of a sentence. And a sentence are split, it’s impossible for translators to translate text so that it would form correct sentences in a target language.
Oct 23, 2022, 8:52 AM
Hey
user P
! I think the most common practice is to use this plugin to transform portable text for translation.
Oct 24, 2022, 4:44 PM
Thanks will take a look
Oct 25, 2022, 8:54 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?