Field level translation for Media Plugin alt text and descriptions
Hey there from Sanity land! 👋
This is definitely doable, but there are some important considerations for applying field-level translation to the media plugin's asset metadata.
The good news: Alt text and descriptions are simple string fields, which makes them good candidates for field-level localization. Field-level translation works well for straightforward fields like strings and numbers.
How to approach this:
You'll likely need to customize the media plugin's schema to support field-level translations. The typical pattern would be structuring your alt text and description fields like this:
{
altText: {
en: "English alt text",
da: "Dansk alt tekst",
// other languages
},
description: {
en: "English description",
da: "Dansk beskrivelse"
}
}Since the sanity-plugin-media allows for custom asset fields, you should be able to extend the schema to support this structure. You might need to create custom input components to make the editing experience cleaner.
Important caveat: If you were planning to use Portable Text (rich text) for descriptions, field-level localization is explicitly not recommended due to attribute limit issues. But for simple strings, you're in the clear!
Alternative approach: If you run into limitations with the media plugin, you could also consider using document-level localization where you create separate asset documents per language, though that's probably overkill for just alt text and descriptions.
The Language Filter plugin could also help with the UI if you go the field-level route, making it easier to switch between languages while editing.
Not a bad idea at all for your use case – alt text and descriptions are exactly the kind of simple metadata that field-level translation handles well! 🇩🇰
Show original thread14 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.