๐Ÿ”ฎ Sanity Create is here. Writing is reinvented. Try now, no developer setup

Issue with adding translations and multiple languages in Sanity

9 replies
Last updated: Dec 9, 2021
Hello, I have an issue when trying to add translations or multiple language in sanityI follow this official sanity tutorial on youtube:
https://www.youtube.com/watch?v=Rk70FSgTJeQ Minute: 1: 07

On my sanity, it gives an error:


Invalid property value
The property value is stored as a value type that does not match the expected type.


Developer info
The value of this property must be of type object according to the schema.

Mismatching value types typically occur when the schema has recently been changed.

The current value (string)
But type value that I put is already 'object', I'm not sure what else is the issue, this is my schema.js, will appreciate for any help:


{
      name: 'blog',
      type: 'document',
      title: 'Blog',
      fields: [
        {
          name: 'title',
          title: 'Title',
          type: 'object',
          fields: [
            {
              title: 'English',
              name: 'en',
              type: 'string'
            },
            {
              title: 'French',
              name: 'fr',
              type: 'string'
            }
          ]
        },
      ]
}
Dec 6, 2021, 4:52 PM
Hey User! Is this causing your Studio to crash or is it warning you that had already entered text into your
title
field as a string before you changed the schema to an object? If it's the latter, you can just unset the field to continue using your
localeString
.
Dec 6, 2021, 6:08 PM
It shows this when I added the fields for the language and change my type to object, before that everything is fine. I'm not sure what else is missing on my code.
Dec 6, 2021, 6:15 PM
// First, we must import the schema creator
import createSchema from 'part:@sanity/base/schema-creator'

// Then import schema types from any plugins that might expose them
import schemaTypes from 'all:part:@sanity/base/schema-type'

// Then we give our schema to the builder and provide the result to Sanity
export default createSchema({
  // We name our schema
  name: 'default',
  // Then proceed to concatenate our document type
  // to the ones provided by any plugins that are installed
  types: schemaTypes.concat([
    /* Your types here! */
    {
      name: 'author',
      type: 'document',
      title: 'Author',
      fields: [
        {
          name: 'name',
          title: 'Name',
          type: 'string'
        },
        {
          name: 'avatar',
          title: 'Avatar',
          type: 'image'
        }
      ]
    },
    {
      name: 'blog',
      type: 'document',
      title: 'Blog',
      fields: [
        {
          name: 'title',
          title: 'Title',
          type: 'object',
          fields: [
            {
              title: 'English',
              name: 'en',
              type: 'string'
            },
            {
              title: 'French',
              name: 'fr',
              type: 'string'
            }
          ]
        },
        {
          name: 'subtitle',
          type: 'string',
          title: 'Subtitle'
        },
        {
          name: 'coverImage',
          type: 'image',
          title: 'Cover Image',
          fields: [
            {
              type: 'text',
              name: 'alt',
              title: 'Description'
            }
          ],
        },
        {
          name: 'content',
          type: 'array',
          title: 'Content',
          of:[
            {
              type: 'block'
            },
            {
              type: 'image',
              fields: [
                {
                  type: 'text',
                  name: 'alt',
                  title: 'Description',
                  options: {
                    isHighlighted: true
                  }
                }
              ],
              options: {
                hotspot: true
              }
            },
            {
              type: 'code'
            }
          ]
        },
        {
          name: 'date',
          type: 'datetime',
          title: 'Date',
          validation: (Rule) => {return Rule.required()}
        },
        {
          name: 'author',
          type: 'reference',
          title: 'Author',
          to: [{type: 'author'}],
        },
        {
          name: 'slug',
          type: 'slug',
          title: 'Slug',
          validation: (Rule) => {return Rule.required()}
        }
      ]
    }
  ]),
})
Dec 6, 2021, 6:16 PM
Got it. It looks like you entered text into the field before you changed the schema to an
object
. You can click the
Reset Value
button and you'll be able to edit the field.
Dec 6, 2021, 7:11 PM
Thanks, it's fixed, I didnt know we just need to click the reset button, however, in my browser it shows this error now:
Dec 6, 2021, 8:27 PM
I dont know if I need to add internalization, but I follow this youtube video: https://www.youtube.com/watch?v=-bNYOn72c1g
It doesn't work, any input how to fix the error?

Also is there a video documentation that basically shows how to add multiple language or add translation using sanity and Next js? probably better so I can follow the tutorial, please advice
Dec 6, 2021, 8:29 PM
Is that error happening on your frontend? If so, it looks like you're trying to render the entire
title
object instead of
title.en
or
<http://title.fr|title.fr>
. I don't think anyone's ever created a Sanity/Next specific video for i18n. There's a guide on i18n routing here , though.
Dec 6, 2021, 8:32 PM
Is that error happening on your frontend? If so, it looks like you're trying to render the entire
title
object instead of
title.en
or
<http://title.fr|title.fr>
. I don't think anyone's ever created a Sanity/Next specific video for i18n. There's a guide on i18n routing here , though.
Dec 6, 2021, 8:32 PM
user M
I have another question, how should I create translation on the content blog sanity?
Under the content category, I tried to add the EN and FR following the video, but doesn't seem to work.

Also if I want to have 2 images en and fr, how should I add it in my schema?

please advice
๐Ÿ™


        {
          name: 'content',
          type: 'array',
          title: 'Content',
          of:[
            {
              type: 'block'
            },
            {
              name: 'test',
              type: 'object',
              title: 'test',
              fields: [
                {
                  title: 'English',
                  name: 'en',
                  type: 'string'
                },
                {
                  title: 'French',
                  name: 'fr',
                  type: 'string'
                }
              ]
            },
            {
              type: 'image',
              fields: [
                {
                  type: 'text',
                  name: 'alt',
                  title: 'Description',
                  options: {
                    isHighlighted: true
                  }
                }
              ],
              options: {
                hotspot: true
              }
            },
            {
              type: 'code'
            }
          ]
        },
        
Dec 9, 2021, 12:44 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?