
i18n-array-groq-query-migration
★ 14by sanity-io · part of sanity-io/plugins
Detect and update legacy GROQ patterns where language is read from _key for sanity-plugin-internationalized-array when users mention v4 to v5 migration, or…
This is the playbook your agent receives when the skill activates — you don't need to read it to use the skill, but it's here to audit before installing.
name: i18n-array-groq-query-migration
description: Detect and update legacy GROQ patterns where language is read from _key for sanity-plugin-internationalized-array when users mention v4 to v5 migration, or @sanity/document-internationalization from v5 to v6. GROQ query updates, localized arrays, or patterns like _key == "en" and _key == $language.
Internationalized Array GROQ Migration
Goal
Help users find GROQ queries that still read locale from _key and rewrite them safely for v5.
When To Use
Use this skill when a user asks to:
- migrate
sanity-plugin-internationalized-arrayfrom v4 to v5 - migrate
@sanity/document-internationalizationfrom v5 to v6 alongsidesanity-plugin-internationalized-arraylanguage field changes - find queries that still use
_keyfor language lookup - update GROQ filters like
_key == "en"or_key == $language
Detection Workflow
Detection commands below use grep. If your environment differs, use your editor's global search with equivalent patterns.
- Search for direct language comparisons on
_key:
grep -REn --exclude-dir=node_modules "_key[[:space:]]*==[[:space:]]*(\"[^\"]+\"|'[^']+'|\\$[A-Za-z_][A-Za-z0-9_]*)" .- Search for any localized-array filters that mention
_key:
grep -REn --exclude-dir=node_modules "\[[^]]*_key[^]]*\]" .- Prioritize matches that look like localized-value reads, for example:
field[_key == ...][0].valueselect(...)branches that compare_keyto a language value
-
Check for uses of
groqand verify if they use_keyas the language, if it is using it, update them. -
Explicitly check for template-interpolated language expressions and keep the same operand, for example:
_key == "${language}"_key == "${locale}"
-
Review each match to avoid false positives where
_keyis used for unrelated array item identity.
Rewrite Rules
Use the same language operand from the original query. The language operand can be a string literal (for example "en"), a variable (for example $language), or a template-interpolated expression (for example "${language}").
- Before data migration is executed (backwards compatible):
_key == <languageExpr>->language == <languageExpr> || _key == <languageExpr>
- After migration is complete:
language == <languageExpr> || _key == <languageExpr>->language == <languageExpr>
Examples
Legacy:
*[_type == "person"]{
"greeting": greeting[_key == $language][0].value
}Backwards compatible:
*[_type == "person"]{
"greeting": greeting[language == $language || _key == $language][0].value
}Post-migration final form:
*[_type == "person"]{
"greeting": greeting[language == $language][0].value
}Response Template
When reporting findings to a user:
- List each query location that still uses
_keyas language source. - Show the exact replacement using the same language expression.
- Label each replacement as:
backwards-compatible(pre-migration), orfinal(post-migration complete).
- Label each match category as
runtime,docs/example, orambiguous. - Call out any ambiguous
_keyusage that needs manual review.
npx skills add https://github.com/sanity-io/plugins --skill i18n-array-groq-query-migrationRun this in your project — your agent picks the skill up automatically.
No common issues documented yet. If you hit a problem, the repository's GitHub Issues page is the best place to look.
Licensed under MIT— you can use, modify, and redistribute it under that license's terms.
View the full license file on GitHub →