This repository was archived by the owner on Feb 3, 2026. It is now read-only.
Closed
Conversation
…hema validation Phase 1 of _key to language pivot: - Add `language: string` field to Value type (src/types.ts) - Add `language: string` field to InternationalizedValue type - Update array.ts validation to check `language` instead of `_key` - Add hidden `language` field to object schema definition - Update object preview to display `language` as subtitle Key design decisions: - `_key` remains for Sanity's array item tracking (UUID) - `language` is the new semantic identifier for language matching - Error paths still use `_key` for Sanity to locate items 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Address review feedback from @sapphire: - Add explicit check for missing or empty `language` field - Clear error message: "Language is required for each array item" - Checks before invalid language validation (fail-fast) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ition - Add migrations/keyToLanguage.ts with full structure - Configurable document types and field names - Batch processing with optimistic locking (ifRevisionID) - Dry run mode enabled by default for safety - Idempotent GROQ query finds docs without language field - Transform logic copies _key to language, generates new nanoid _key The transformation logic is complete but will be tested once all phases are merged into the feature branch.
- Update intro to reference language field instead of _key - Update 'Shape of stored data' section with new format - Update 'Querying data' section with language-based queries - Add 'Migrate from v3 to v4' section with migration guide - Update table of contents - Update @sanity/language-filter example for new data structure
Phase 3 (Utils - from @charlie): - createAddLanguagePatches.ts: Use nanoid() for _key, add language field - checkAllLanguagesArePresent.ts: Check v.language instead of v._key - fieldActions/index.ts: Update disabled check to use item.language Phase 2 (Components - from @charlie): - InternationalizedArray.tsx: Update 4 _key references to language - InternationalizedInput.tsx: Update 7 _key references to language - DocumentAddButtons.tsx: Add nanoid import, use language for checks - getDocumentsToTranslate.ts: Add language to interface Shared: - package.json: Add nanoid ^5.0.7 dependency - keyToLanguage.ts: Fix lint issues with eslint-disable Note: Pre-existing type error in schema/array.ts:35 is unrelated to these changes.
The stricter Value type (with required `language` field) surfaced a latent type mismatch between InternationalizedArray's ArrayOfObjectsInputProps and defineField's expected ArrayOfPrimitivesInputProps. The component works correctly at runtime - this is a type system limitation where Sanity's types can't express that our array contains objects, not primitives. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Member
|
This plugin has moved to a new plugins monorepo: https://github.com/sanity-io/plugins/tree/main/plugins/sanity-plugin-internationalized-array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors how language identification is stored in internationalized array items. Previously, the language ID was stored in the array item's
_keyfield. Now, a dedicatedlanguagefield is used, and_keycontains a random identifier generated by nanoid.Before (v3.x)
{ "greeting": [ { "_key": "en", "value": "hello" }, { "_key": "fr", "value": "bonjour" } ] }After (v4.x)
{ "greeting": [ { "_key": "abc123", "language": "en", "value": "hello" }, { "_key": "def456", "language": "fr", "value": "bonjour" } ] }Motivation
The
_keyfield in Sanity arrays is meant for tracking item identity across edits, not for storing semantic data. Using it for language IDs caused issues with:_keyto track which items moved/changedBy moving the language identifier to a dedicated field,
_keycan fulfill its intended purpose as a stable, random identifier.Changes
Phase 1: Core Type & Schema Changes
src/types.ts- Addedlanguage: stringto theValueinterfacesrc/schema/object.ts- Added hiddenlanguagefield definition, updated preview to showlanguageinstead of_keysrc/schema/array.ts- Updated validation logic:languagevalueslanguagevalues (not in configured languages)languagevaluesPhase 2: Component Updates
src/components/InternationalizedInput.tsx- 7 changes from_keytolanguage:languageKeysInUsenow mapsv.languagekeyIsValidchecksvalue.languagehandleKeyChangesets['language']path instead of['_key']value.languageisDefaultcheck usesvalue.languagevalue.languagesrc/components/InternationalizedArray.tsx- 4 changes:handleRestoreOrderusesv.languagefor reorderingallKeysAreLanguageschecksv.languagelanguagesInUsefilters byv.languagelanguagesOutOfOrdercompares byv.languagesrc/components/DocumentAddButtons.tsx- Updated to generate new format:nanoidimport{ _key: languageId }to{ _key: nanoid(), language: languageId }alreadyTranslatedcheck usestranslation.languagePhase 3: Utility Updates
src/utils/createAddLanguagePatches.ts- Core change for new item creation:nanoidimport_key: idto_key: nanoid(), language: idsrc/utils/checkAllLanguagesArePresent.ts- Changedv._keytov.languagesrc/fieldActions/index.ts- Updated disabled check fromitem._keytoitem.languagesrc/utils/getDocumentsToTranslate.ts- Addedlanguage: stringtoDocumentsToTranslateinterfacePhase 4: Migration & Documentation
migrations/keyToLanguage.ts- New migration script that:languagefield_keyvalue to newlanguagefield_keyusing nanoidifRevisionID) for safe concurrent executionREADME.md- Updated documentation:language == "en"instead of_key == "en"@sanity/language-filterexample for new data shapeDependencies
package.json- Addednanoid: ^5.0.7as a production dependencyGROQ Query Migration
Users will need to update their GROQ queries:
Migration Guide for Users
languageinstead of_keymigrations/keyToLanguage.tswith your document types and field namesDRY_RUN = truefirst to previewDRY_RUN = falseto apply changesTest Plan
{ _key: nanoid(), language: id }format@sanity/language-filterintegration worksBreaking Changes
This is a breaking change for users upgrading from v3:
_key == "lang"tolanguage == "lang"_keybeing the language ID needs updatingA migration script and guide are included to help users upgrade.
🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com