Skip to content

Commit 8dce14f

Browse files
authored
Merge pull request #761 from sanity-io/i18n-obj-to-array-migration-v5
fix(i18n-array): update the migration script to match v5 using langague field
2 parents 9b200aa + 7c3fdff commit 8dce14f

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

.changeset/wacky-animals-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"sanity-plugin-internationalized-array": patch
3+
---
4+
5+
Object to Array Migration script update to match v5

plugins/sanity-plugin-internationalized-array/migrations/transformObjectToArray.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable no-console */
22

3+
import {randomKey} from '@sanity/util/content'
34
import {getCliClient} from 'sanity/cli'
45

56
const client = getCliClient({apiVersion: '2023-06-30'})
@@ -15,8 +16,8 @@ const client = getCliClient({apiVersion: '2023-06-30'})
1516

1617
// To:
1718
// "greeting": [
18-
// { "_key": "en", "value": "hello" },
19-
// { "_key": "fr", "value": "bonjour" },
19+
// { "_key": "abcdefghijkl", "language":"en", "value": "hello" },
20+
// { "_key": "zxyvwxrstqpo", "language":"fr", "value": "bonjour" },
2021
// ]
2122

2223
// This will migrate documents in batches of 100 and continue patching until no more documents are
@@ -44,6 +45,7 @@ const client = getCliClient({apiVersion: '2023-06-30'})
4445

4546
const TYPE = `presenter`
4647
const FIELD_NAME = `title`
48+
const ARRAY_ITEM_TYPE = `internationalizedArrayStringValue`
4749

4850
// 3. Run this script with:
4951
// `npx sanity@latest exec ./migrations/transformObjectToArray.ts --with-user-token`
@@ -66,7 +68,9 @@ const buildPatches = (docs: any[]) =>
6668
[FIELD_NAME]: Object.keys(doc[FIELD_NAME])
6769
.filter((key) => key !== '_type')
6870
.map((key) => ({
69-
_key: key,
71+
_key: randomKey(),
72+
_type: ARRAY_ITEM_TYPE,
73+
language: key,
7074
value: doc[FIELD_NAME][key],
7175
})),
7276
},

0 commit comments

Comments
 (0)