Unlock seamless workflows and faster delivery with our latest releases – get the details

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
blockContent
in the
post.js
schema,
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
[slug.js]
using a ternary to pass the respective version into the boilerplate component

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

However, the
body_de
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.
Thanks
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 () =>
  S.listItem()
    .title(`Post`)
    .child(
      S.documentList()
        .title(`Title`)
        .schemaType("string")
        .filter('_type == "string" && __i18n_lang == $baseLanguage')
        .params({ baseLanguage: `de_DE` })
        .canHandleIntent(S.documentTypeList("string").getCanHandleIntent())
    );
Aug 8, 2022, 1:58 PM
oh yeah, you need to look at the complete folder 😉You need a
.list()
to see a
.listItem()
!
So look at
…/deskStructure/index.js
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

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?