@sanity/document-internationalization 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -76,10 +76,10 @@ The only required configuration is:
76
76
  ```ts
77
77
  // sanity.config.ts
78
78
 
79
- import {createConfig} from 'sanity'
79
+ import {defineConfig} from 'sanity'
80
80
  import {documentInternationalization} from '@sanity/document-internationalization'
81
81
 
82
- export const createConfig({
82
+ export const defineConfig({
83
83
  // ... all other config
84
84
  plugins: [
85
85
  // ... all other plugins
@@ -102,10 +102,10 @@ The plugin also supports asynchronously retrieving languages from the dataset, m
102
102
  ```ts
103
103
  // sanity.config.ts
104
104
 
105
- import {createConfig} from 'sanity'
105
+ import {defineConfig} from 'sanity'
106
106
  import {documentInternationalization} from '@sanity/document-internationalization'
107
107
 
108
- export const createConfig({
108
+ export const defineConfig({
109
109
  // ... all other config
110
110
  plugins: [
111
111
  // ... all other plugins
@@ -128,21 +128,21 @@ export const createConfig({
128
128
 
129
129
  // Optional
130
130
  // Customizes the name of the language field
131
- languageField: `language` // defauts to "language"
131
+ languageField: `language`, // defauts to "language"
132
132
 
133
133
  // Optional
134
134
  // Keep translation.metadata references weak
135
- weakReferences: true // defaults to false
135
+ weakReferences: true, // defaults to false
136
136
 
137
137
  // Optional
138
138
  // Adds UI for publishing all translations at once. Requires access to the Scheduling API
139
139
  // https://www.sanity.io/docs/scheduling-api
140
- bulkPublish: true // defaults to false
140
+ bulkPublish: true, // defaults to false
141
141
 
142
142
  // Optional
143
143
  // Adds additional fields to the metadata document
144
144
  metadataFields: [
145
- defineField({ name: 'slug', type: 'slug' })
145
+ defineField({ name: 'slug', type: 'slug' }),
146
146
  ],
147
147
 
148
148
  // Optional
@@ -153,7 +153,21 @@ export const createConfig({
153
153
  // Optional
154
154
  // Enable "manage translations" button without creating a translated version. Helpful if you have
155
155
  // pre-existing documents that you need to tie together through the metadata document
156
- allowCreateMetaDoc: true // defaults to false
156
+ allowCreateMetaDoc: true, // defaults to false
157
+
158
+ // Optional
159
+ // Callback function that runs after a translation document has been created
160
+ // Note: Defaults to null
161
+ callback: ({
162
+ sourceDocument, // The document in the original language
163
+ newDocument, // The newly created translation of the source document
164
+ sourceLanguageId, // The id of the original language
165
+ destinationLanguageId, // The id of the destination language
166
+ metaDocumentId, // The id of the meta document referencing the document translations
167
+ client // Sanity client
168
+ }) {
169
+ // Your function implementation
170
+ }
157
171
  })
158
172
  ]
159
173
  })
package/dist/index.d.mts CHANGED
@@ -8,6 +8,8 @@ import type {ObjectSchemaType} from 'sanity'
8
8
  import {Plugin as Plugin_2} from 'sanity'
9
9
  import type {Reference} from 'sanity'
10
10
  import type {SanityClient} from 'sanity'
11
+ import type {SanityDocument} from 'sanity'
12
+ import type {SanityDocumentLike} from 'sanity'
11
13
 
12
14
  export declare const DeleteTranslationAction: DocumentActionComponent
13
15
 
@@ -42,6 +44,20 @@ export declare type Metadata = {
42
44
  translations: TranslationReference[]
43
45
  }
44
46
 
47
+ export declare type MetadataDocument = SanityDocumentLike & {
48
+ schemaTypes: string[]
49
+ translations: TranslationReference[]
50
+ }
51
+
52
+ export declare type PluginCallbackArgs = {
53
+ sourceDocument: SanityDocument
54
+ newDocument: SanityDocument
55
+ sourceLanguageId: string
56
+ destinationLanguageId: string
57
+ metaDocumentId: string
58
+ client: SanityClient
59
+ }
60
+
45
61
  export declare type PluginConfig = {
46
62
  supportedLanguages: SupportedLanguages
47
63
  schemaTypes: string[]
@@ -51,6 +67,7 @@ export declare type PluginConfig = {
51
67
  metadataFields?: FieldDefinition[]
52
68
  apiVersion?: string
53
69
  allowCreateMetaDoc?: boolean
70
+ callback?: ((args: PluginCallbackArgs) => Promise<void>) | null
54
71
  }
55
72
 
56
73
  export declare type PluginConfigContext = Required<PluginConfig> & {
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ import type {ObjectSchemaType} from 'sanity'
8
8
  import {Plugin as Plugin_2} from 'sanity'
9
9
  import type {Reference} from 'sanity'
10
10
  import type {SanityClient} from 'sanity'
11
+ import type {SanityDocument} from 'sanity'
12
+ import type {SanityDocumentLike} from 'sanity'
11
13
 
12
14
  export declare const DeleteTranslationAction: DocumentActionComponent
13
15
 
@@ -42,6 +44,20 @@ export declare type Metadata = {
42
44
  translations: TranslationReference[]
43
45
  }
44
46
 
47
+ export declare type MetadataDocument = SanityDocumentLike & {
48
+ schemaTypes: string[]
49
+ translations: TranslationReference[]
50
+ }
51
+
52
+ export declare type PluginCallbackArgs = {
53
+ sourceDocument: SanityDocument
54
+ newDocument: SanityDocument
55
+ sourceLanguageId: string
56
+ destinationLanguageId: string
57
+ metaDocumentId: string
58
+ client: SanityClient
59
+ }
60
+
45
61
  export declare type PluginConfig = {
46
62
  supportedLanguages: SupportedLanguages
47
63
  schemaTypes: string[]
@@ -51,6 +67,7 @@ export declare type PluginConfig = {
51
67
  metadataFields?: FieldDefinition[]
52
68
  apiVersion?: string
53
69
  allowCreateMetaDoc?: boolean
70
+ callback?: ((args: PluginCallbackArgs) => Promise<void>) | null
54
71
  }
55
72
 
56
73
  export declare type PluginConfigContext = Required<PluginConfig> & {