Watch a live product demo 👀 See how Sanity powers richer commerce experiences

Next.js Blog Starter - How to add a Localized `blockContent` in the `post.js` Schema

9 replies
Last updated: Aug 8, 2022
Hello 👋 I’m a total newbie to Sanity and am currently trying it out for a few hours with the Nextjs Blog starter .

I would like to add a localized
in the
so that users can add body text in two languages.
I successfully localized the title, but can’t do so for the body. After reading about it, I thought duplicating the body field element would be a simple solution

      name: "body",
      title: "English body",
      type: "blockContent",
      name: "body_de",
      title: "German body",
      type: "blockContent",
and then in
using a ternary to pass the respective version into the boilerplate component

<PostBody _content_={lang === "de" ? post.body : post.body_tr} />

However, the
content does not make it into the post payload.

What would be the easiest solution do the above? It doesn’t have to be fancy at all, the resulting site will be most simple.
Thanks a lot for any suggestions!
Aug 6, 2022, 7:19 PM
I will answer on Monday with more if nobody else chimes in, but in your case I would check out these plugins (the first 2 are my favs) 🙂
Aug 6, 2022, 7:24 PM
Oh, I should have checked out the plugins page, nice! All looking very good, and so far the experience with Sanity is fantastic btw.
user J
Aug 6, 2022, 7:26 PM
So, do these plugins answer your question? If yes, I would mark this thread as
Aug 8, 2022, 12:41 PM
They do, thanks 👍, even though setting up Document Internationalization has been a little challenge for me so far.
I’m not really sure how to customize Desk Structure (as
explained here ), but I guess I need to read through all the docs regarding it in order to really understand how this example can be applied to the Post schema of the Nextjs Blog Starter .
Aug 8, 2022, 1:35 PM
Desk Structure is one of my strengths now 😉 so I can help.
Aug 8, 2022, 1:52 PM
I have examples of custom desk structures here , which might help you along. But reading through the docs is still necessary, to get your stuff done correctly 🙂
Aug 8, 2022, 1:55 PM
Oh cool, lucky me 🙂
So I guess I’m struggling to understand if/how I should build a custom structure if I wanted to localize a Post type document (so that in Studio, the language select button shows my two languages - right now it’s there, but disabled).

Building on the starter kit, I thought that this would do the trick (which it isn’t, it breaks Studio). But like I said, I haven’t had the time to extensively read the docs on this part

import S from "@sanity/desk-tool/structure-builder";

export default () =>
        .filter('_type == "string" && __i18n_lang == $baseLanguage')
        .params({ baseLanguage: `de_DE` })
Aug 8, 2022, 1:58 PM
oh yeah, you need to look at the complete folder 😉You need a
to see a
So look at
and then you will understand the structure you need to build.
Aug 8, 2022, 2:24 PM
You will have to read some guide or the docs to understand what I am doing (which is more of a “look how clean SB code can look!“). A good start is this guide .
Aug 8, 2022, 2:26 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the 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.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing