Understanding the use of the _translations query in internationalisation plugin readme
The _translations query serves a different purpose than your base query with language == $language. Here's why you need it:
Your initial query *[_type == "lesson" && language == $language] only fetches documents in one specific language. The _translations part is what gives you access to all the other language versions of that same content.
Think of it this way:
- The base query finds all lessons in, say, English (
$language = "en") - The
_translationssubquery then looks up and includes the Spanish, French, German, etc. versions of each lesson
The Document Internationalization plugin creates separate documents for each language version, linked together through a special translation.metadata document. The query pattern you're seeing:
"_translations": *[_type == "translation.metadata" && references(^._id)].translations[].value->Does three things:
- Finds the metadata document that references the current lesson (
references(^._id)) - Gets all translation references from that metadata document (
.translations[]) - Resolves those references to get the actual translated documents (
.value->)
Why is this useful? It lets you build language switchers, show "Available in: EN, ES, FR" indicators, or prefetch alternate language versions for better UX. Without the _translations query, you'd only have the English lessons with no way to know which other languages exist or how to link to them.
So you're not replacing language == $language with _translations – you're using both together. The first filters to your current language, the second connects you to all the alternatives.
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.