Display localized field titles in Sanity Studio with custom schema
I can help you with displaying localized titles in Sanity Studio! The key is using the preview configuration with the prepare function to extract and display the correct language from your localized string object.
When you're using field-level translations, your localized strings are stored as objects (like {en: "English Title", fr: "French Title"}). To display these properly in Studio lists and references, you need to configure the preview in your schema to extract the appropriate language.
Here's how to handle this in your page.js schema:
// page.js
import { localeString } from './localeString'
export default {
name: 'page',
type: 'document',
fields: [
{
name: 'title',
type: 'localeString', // your custom localized string type
},
// ... other fields
],
preview: {
select: {
title: 'title', // This will select the entire localeString object
},
prepare({ title }) {
// Extract the language you want to display (e.g., 'en')
// You can make this dynamic based on user preference
return {
title: title?.en || title?.fr || 'Untitled', // Fallback through languages
}
}
}
}If you want to make it more sophisticated and show which languages have translations, you could do:
preview: {
select: {
title: 'title',
},
prepare({ title }) {
const languages = Object.keys(title || {}).join(', ')
return {
title: title?.en || Object.values(title || {})[0] || 'Untitled',
subtitle: languages ? `Available in: ${languages}` : 'No translations'
}
}
}The preview configuration works by:
select: Grabs the fields you need from the documentprepare: Transforms that data into what Studio displays (title, subtitle, media)
Since your localeString is a custom type, the preview on the page document needs to handle the object structure that type creates. The prepare function is where you "unwrap" the localized object and choose which language to display.
This approach is cleaner than trying to pass down the title from localeString.js because each document type controls its own preview display, and the page needs to decide how to present its localized content in lists.
If you're still having issues, make sure your localeString.js type is properly structured as an object type with fields for each language you're supporting. You can find more details about field-level localization in the Sanity docs.
Show original thread4 replies
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.