Skip to content

feat!(i18n-array): Move language identifier from _key to dedicated language field#567

Open
pedrobonamin wants to merge 41 commits intomainfrom
i18n-plugin/language-field
Open

feat!(i18n-array): Move language identifier from _key to dedicated language field#567
pedrobonamin wants to merge 41 commits intomainfrom
i18n-plugin/language-field

Conversation

@pedrobonamin
Copy link
Contributor

@pedrobonamin pedrobonamin commented Feb 11, 2026

Description

fixes #528
fixes #571

New major versions for @sanity/document-internationalization and **sanity-internationalized-array**

This PR migrates both sanity-plugin-internationalized-array and @sanity/document-internationalization to store the language identifier in a dedicated language field instead of using _key for this purpose.

When a field has outdated data a warning banner will render to alert users.
image

Why

Sanity uses _key internally for array item identity, diffing, and reordering. Storing the language ID there caused issues with:

  • Array reordering and diffing in the Studio
  • Portable Text operations that rely on stable keys
  • Copy/paste operations between documents where keys could collide

Data format change

Before (v4):

{"_key": "en", "_type": "internationalizedArrayStringValue", "value": "hello"}

After (v5):

{"_key": "abc123", "_type": "internationalizedArrayStringValue", "language": "en", "value": "hello"}

How to upgrade

  1. Update GROQ queries from _key == "en" to language == "en" || _key == "en" until the migration is completed.

  2. Run the new bundled migration helper to update existing documents. Create a migration file in your project that imports from sanity-plugin-internationalized-array/migrations, configures your documentTypes, and exports the migration:

    // ./migrations/migrateToLanguageField.ts
    import {migrateToLanguageField} from 'sanity-plugin-internationalized-array/migrations'
    export default migrateToLanguageField(['yourType'])
    
    npx sanity migration run migrateToLanguageField
    

    Verify everything looks as expected

    npx sanity migration run migrateToLanguageField  --dry-run=false
    
  3. Update any custom code that reads _key as the language identifier to use the language field instead.

  4. Remove _key == "en" from your queries once migration is complete, since language is now stored in language.

We have also added a SKILL to guide your AI agents helping you to migrate your queries and usage of the _key identifier to a language.
See the skill here

What to review

Testing

@vercel
Copy link

vercel bot commented Feb 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
plugins-studio Ready Ready Preview, Comment Feb 19, 2026 10:30am

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 11, 2026

🦋 Changeset detected

Latest commit: 9daaaad

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@sanity/document-internationalization Major
sanity-plugin-internationalized-array Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@socket-security
Copy link

socket-security bot commented Feb 12, 2026

@pedrobonamin pedrobonamin changed the title feat!(i18n-array)I: use dedicated language field for i18n array plugin feat!(i18n-array): use dedicated language field for i18n array plugin Feb 13, 2026
@pedrobonamin pedrobonamin force-pushed the i18n-plugin/language-field branch from f91c4f0 to 1b14e54 Compare February 13, 2026 16:42
@pedrobonamin pedrobonamin changed the base branch from main to feat/document-i18n-tests February 13, 2026 16:43
@pedrobonamin pedrobonamin changed the base branch from feat/document-i18n-tests to main February 13, 2026 16:44
@pedrobonamin pedrobonamin changed the title feat!(i18n-array): use dedicated language field for i18n array plugin feat!(i18n-array): Move language identifier from _key to dedicated language field Feb 16, 2026
@pedrobonamin pedrobonamin force-pushed the i18n-plugin/language-field branch from 0b72f2c to a095500 Compare February 16, 2026 12:09
@pedrobonamin pedrobonamin changed the title feat!(i18n-array): Move language identifier from _key to dedicated language field feat!(i18n-array): Move language identifier from _key to dedicated language field Feb 16, 2026
@pedrobonamin pedrobonamin changed the title feat!(i18n-array): Move language identifier from _key to dedicated language field feat!(i18n-array): Move locale identifier from _key to dedicated language field Feb 16, 2026
@pedrobonamin pedrobonamin changed the title feat!(i18n-array): Move locale identifier from _key to dedicated language field feat!(i18n-array): Move language identifier from _key to dedicated language field Feb 16, 2026
@github-actions
Copy link

github-actions bot commented Feb 19, 2026

Preview this PR with pkg.pr.new

pnpm logo Using pnpm
📦 sanity-plugin-internationalized-array
pnpm install https://pkg.pr.new/sanity-io/plugins/sanity-plugin-internationalized-array@9daaaade093d295f9eb42ec07138b7276c637b6c
📦 @sanity/document-internationalization
pnpm install https://pkg.pr.new/sanity-io/plugins/@sanity/document-internationalization@9daaaade093d295f9eb42ec07138b7276c637b6c
npm logo Using npm
📦 sanity-plugin-internationalized-array
npm install https://pkg.pr.new/sanity-io/plugins/sanity-plugin-internationalized-array@9daaaade093d295f9eb42ec07138b7276c637b6c
📦 @sanity/document-internationalization
npm install https://pkg.pr.new/sanity-io/plugins/@sanity/document-internationalization@9daaaade093d295f9eb42ec07138b7276c637b6c

View Commit (9daaaad)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Impossible to copy internationalized fields Copy/Paste Issue: Translated Fields Lose _key Assignment

2 participants

Comments