Issue with adding translations and multiple languages in Sanity
This is a common issue when migrating existing content to a new internationalized schema structure. The error occurs because you already have documents in your dataset where title was stored as a simple string, but your new schema expects title to be an object with en and fr properties.
Here's what's happening: When you change a field from type: 'string' to type: 'object', Sanity doesn't automatically migrate your existing data. Any blog documents created before the schema change still have title: "some string value" instead of title: { en: "...", fr: "..." }.
Solutions
Option 1: Use Sanity's document internationalization plugin (Recommended)
Instead of manually creating nested object structures, use the @sanity/document-internationalization plugin. This is the official, supported approach for document-level translations and creates separate documents per language with proper references:
npm install @sanity/document-internationalizationThen configure it in your sanity.config.ts:
import {documentInternationalization} from '@sanity/document-internationalization'
export default defineConfig({
plugins: [
documentInternationalization({
supportedLanguages: [
{id: 'en', title: 'English'},
{id: 'fr', title: 'French'}
],
schemaTypes: ['blog']
})
]
})Your schema would then have a simple language field:
{
name: 'blog',
type: 'document',
title: 'Blog',
fields: [
{
name: 'title',
title: 'Title',
type: 'string' // Back to a simple string
},
{
name: 'language',
type: 'string',
readOnly: true,
hidden: true
}
]
}Option 2: Keep your object approach but migrate existing data
If you prefer the nested object structure from the tutorial, you need to migrate your existing documents. You can do this through the Vision plugin in your Studio or create a migration script:
- Temporarily revert
titletotype: 'string'to access your old data - Create a migration to convert
title: "Old Title"totitle: { en: "Old Title", fr: "" } - Update your schema back to the object structure
Option 3: Start fresh
If you're still in development without important content:
- Delete the existing blog documents from your dataset
- Keep your new schema
- Create new documents with the correct structure
Option 4: Use a different field name
Add a new field like localizedTitle with your object structure, leaving the old title field intact. This lets you gradually migrate content without breaking existing documents.
The tutorial approach works for new projects, but the document internationalization plugin is generally more robust for production use as it provides better querying capabilities, clearer separation between language versions, and works well with features like AI Assist for translation.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.