i18n-array-groq-query-migration

bởi sanity-io

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…

npx skills add https://github.com/sanity-io/plugins --skill i18n-array-groq-query-migration

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-array from v4 to v5
  • migrate @sanity/document-internationalization from v5 to v6 alongside sanity-plugin-internationalized-array language field changes
  • find queries that still use _key for 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.

  1. Search for direct language comparisons on _key:
grep -REn --exclude-dir=node_modules "_key[[:space:]]*==[[:space:]]*(\"[^\"]+\"|'[^']+'|\\$[A-Za-z_][A-Za-z0-9_]*)" .
  1. Search for any localized-array filters that mention _key:
grep -REn --exclude-dir=node_modules "\[[^]]*_key[^]]*\]" .
  1. Prioritize matches that look like localized-value reads, for example:
  • field[_key == ...][0].value
  • select(...) branches that compare _key to a language value
  1. Check for uses of groq and verify if they use _key as the language, if it is using it, update them.

  2. Explicitly check for template-interpolated language expressions and keep the same operand, for example:

    • _key == "${language}"
    • _key == "${locale}"
  3. Review each match to avoid false positives where _key is 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:

  1. List each query location that still uses _key as language source.
  2. Show the exact replacement using the same language expression.
  3. Label each replacement as:
    • backwards-compatible (pre-migration), or
    • final (post-migration complete).
  4. Label each match category as runtime, docs/example, or ambiguous.
  5. Call out any ambiguous _key usage that needs manual review.

Thêm skills từ sanity-io

performance-optimization
sanity-io
Tối ưu hóa hiệu suất ứng dụng. Sử dụng khi có yêu cầu về hiệu suất, khi nghi ngờ có suy giảm hiệu suất, hoặc khi Core Web Vitals hoặc thời gian tải…
official
rxjs-like-a-pro
sanity-io
Kỹ năng này giúp bạn viết mã RxJS mang tính thành ngữ, dễ kết hợp và tránh các lỗi thường gặp. Triết lý cốt lõi: giữ logic trong chuỗi observable. Mỗi khi bạn dùng .subscribe(), hãy tự hỏi liệu công việc đó có thể được thể hiện như một phép biến đổi bên trong .pipe() hay không.
official
find-skills
sanity-io
Giúp người dùng khám phá và cài đặt các kỹ năng của tác nhân khi họ đặt câu hỏi như "làm thế nào để làm X", "tìm kỹ năng cho X", "có kỹ năng nào có thể...", hoặc diễn đạt…
official
next-cache-components
sanity-io
Next.js 16 Cache Components - PPR, use cache directive, cacheLife, cacheTag, updateTag
official
vercel-react-best-practices
sanity-io
Hướng dẫn tối ưu hiệu suất React và Next.js từ Vercel Engineering. Kỹ năng này nên được sử dụng khi viết, xem xét hoặc tái cấu trúc React/Next.js…
official
frontend-design
sanity-io
Tạo giao diện frontend chất lượng sản xuất, độc đáo với chất lượng thiết kế cao. Sử dụng kỹ năng này khi người dùng yêu cầu xây dựng các thành phần web, trang, hoặc…
official
plugin-transfer
sanity-io
Hướng dẫn agent cách di chuyển một plugin hiện có vào monorepo này bằng quy trình tạo copy-plugin.
official
test-studio-script-runner
sanity-io
Giải thích công cụ Script Runner trong dev/test-studio. Sử dụng khi thêm, chỉnh sửa, chạy hoặc ghi chép các script trong dev/test-studio/src/script-runner, hoặc khi…
official