@sanity/document-internationalization 3.2.1 → 3.3.1

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Sanity.io
3
+ Copyright (c) 2025 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -128,21 +128,21 @@ export const defineConfig({
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 defineConfig({
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> & {