gt-sanity 0.0.5

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.
Files changed (44) hide show
  1. package/LICENSE.md +138 -0
  2. package/README.md +100 -0
  3. package/dist/index.d.mts +241 -0
  4. package/dist/index.d.ts +241 -0
  5. package/dist/index.js +2119 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +2099 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +92 -0
  10. package/sanity.json +8 -0
  11. package/src/adapter/core.ts +44 -0
  12. package/src/adapter/createTask.ts +41 -0
  13. package/src/adapter/getLocales.ts +13 -0
  14. package/src/adapter/getTranslation.ts +20 -0
  15. package/src/adapter/getTranslationTask.ts +31 -0
  16. package/src/adapter/index.ts +13 -0
  17. package/src/components/LanguageStatus.tsx +65 -0
  18. package/src/components/NewTask.tsx +249 -0
  19. package/src/components/ProgressBar.tsx +38 -0
  20. package/src/components/TaskView.tsx +255 -0
  21. package/src/components/TranslationContext.tsx +19 -0
  22. package/src/components/TranslationView.tsx +82 -0
  23. package/src/components/TranslationsTab.tsx +177 -0
  24. package/src/configuration/README.md +8 -0
  25. package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.ts +108 -0
  26. package/src/configuration/baseDocumentLevelConfig/helpers/createI18nDocAndPatchMetadata.ts +47 -0
  27. package/src/configuration/baseDocumentLevelConfig/helpers/createTranslationMetadata.ts +43 -0
  28. package/src/configuration/baseDocumentLevelConfig/helpers/getOrCreateTranslationMetadata.ts +77 -0
  29. package/src/configuration/baseDocumentLevelConfig/helpers/getTranslationMetadata.ts +15 -0
  30. package/src/configuration/baseDocumentLevelConfig/helpers/index.ts +5 -0
  31. package/src/configuration/baseDocumentLevelConfig/helpers/patchI18nDoc.ts +25 -0
  32. package/src/configuration/baseDocumentLevelConfig/index.ts +129 -0
  33. package/src/configuration/baseDocumentLevelConfig/legacyDocumentLevelPatch.ts +69 -0
  34. package/src/configuration/baseFieldLevelConfig.ts +118 -0
  35. package/src/configuration/index.ts +18 -0
  36. package/src/configuration/utils/checkSerializationVersion.ts +13 -0
  37. package/src/configuration/utils/findDocumentAtRevision.ts +22 -0
  38. package/src/configuration/utils/findLatestDraft.ts +16 -0
  39. package/src/configuration/utils/index.ts +3 -0
  40. package/src/hooks/useClient.ts +5 -0
  41. package/src/hooks/useSecrets.ts +33 -0
  42. package/src/index.ts +120 -0
  43. package/src/types.ts +124 -0
  44. package/v2-incompatible.js +11 -0
package/LICENSE.md ADDED
@@ -0,0 +1,138 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2025 General Translation, Inc.
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
106
+
107
+ ## Additional Code
108
+
109
+ The following files of the Software are adapted from https://github.com/sanity-io/sanity-translations-tab.
110
+ These portions are licensed under the license of the original software, listed below.
111
+
112
+ - src/components/\*\*
113
+ - src/configuration/\*\*
114
+ - src/hooks/\*\*
115
+ - src/types.ts
116
+ - src/utils/\*\*
117
+
118
+ MIT License
119
+
120
+ Copyright (c) 2025 Sanity.io
121
+
122
+ Permission is hereby granted, free of charge, to any person obtaining a copy
123
+ of this software and associated documentation files (the "Software"), to deal
124
+ in the Software without restriction, including without limitation the rights
125
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
126
+ copies of the Software, and to permit persons to whom the Software is
127
+ furnished to do so, subject to the following conditions:
128
+
129
+ The above copyright notice and this permission notice shall be included in all
130
+ copies or substantial portions of the Software.
131
+
132
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
133
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
134
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
135
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
136
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
137
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
138
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # @generaltranslation/sanity
2
+
3
+ > This is a **Sanity Studio v3** plugin.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install @generaltranslation/sanity
9
+ ```
10
+
11
+ Then, create a [GT project](https://generaltranslation.com/dashboard) and get a production API key and project ID.
12
+
13
+ In your Studio folder, create a file called `populateSecrets.js` with the following content:
14
+
15
+ ```javascript
16
+ // ./populateSecrets.js
17
+ // Do not commit this file to your repository
18
+
19
+ import { getCliClient } from 'sanity/cli';
20
+
21
+ const client = getCliClient({ apiVersion: '2025-09-15' });
22
+
23
+ client.createOrReplace({
24
+ // The `.` in this _id will ensure the document is private
25
+ // even in a public dataset!
26
+ _id: 'generaltranslation.secrets',
27
+ _type: 'generaltranslationSettings',
28
+ // replace these with your values
29
+ project: '<GT_PROJECT_ID>',
30
+ secret: '<GT_API_KEY>',
31
+ });
32
+ ```
33
+
34
+ Run the script:
35
+
36
+ ```sh
37
+ npx sanity exec populateSecrets.js --with-user-token
38
+ ```
39
+
40
+ Verify that the document was created using the Vision Tool in the Studio and query `*[_id == 'generaltranslation.secrets']`. Note: If you have multiple datasets, you'll have to do this across all of them.
41
+
42
+ If the document was found in your dataset(s), delete `populateSecrets.js`.
43
+
44
+ If you have concerns about this being exposed to authenticated users of your studio, you can control access to this path with [role-based access control](https://www.sanity.io/docs/access-control).
45
+
46
+ ## Usage
47
+
48
+ Add it as a plugin in `sanity.config.ts` (or .js):
49
+
50
+ ```ts
51
+ import { defineConfig } from 'sanity';
52
+ import { gtPlugin } from '@generaltranslation/sanity';
53
+
54
+ export default defineConfig({
55
+ //...
56
+ plugins: [
57
+ gtPlugin({
58
+ sourceLocale: 'en',
59
+ // Specify your locales here
60
+ locales: ['es', 'fr'],
61
+ }),
62
+ ],
63
+ });
64
+ ```
65
+
66
+ Add the Translation View to your document structure:
67
+
68
+ ```ts
69
+ // ./structure.ts
70
+ import type { DefaultDocumentNodeResolver } from 'sanity/structure';
71
+ import { TranslationsTab } from '@generaltranslation/sanity';
72
+ import { defaultDocumentLevelConfig } from '@generaltranslation/sanity';
73
+ export const defaultDocumentNode: DefaultDocumentNodeResolver = (
74
+ S,
75
+ { schemaType }
76
+ ) => {
77
+ // Replace 'translatable' with your schema type(s)
78
+ if (schemaType === 'translatable') {
79
+ return S.document().views([
80
+ S.view.form(),
81
+ S.view
82
+ .component(TranslationsTab)
83
+ .title('General Translation')
84
+ .options(defaultDocumentLevelConfig),
85
+ ]);
86
+ }
87
+ };
88
+ ```
89
+
90
+ ## License
91
+
92
+ [FSL-1.1-ALv2](LICENSE.md) © General Translation, Inc.
93
+
94
+ ## Develop & test
95
+
96
+ This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
97
+ with default configuration for build & watch scripts.
98
+
99
+ See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
100
+ on how to run this plugin with hotreload in the studio.
@@ -0,0 +1,241 @@
1
+ import { BaseDocumentDeserializer } from 'sanity-naive-html-serializer';
2
+ import { BaseDocumentMerger } from 'sanity-naive-html-serializer';
3
+ import { BaseDocumentSerializer } from 'sanity-naive-html-serializer';
4
+ import { CustomMapping } from 'generaltranslation/types';
5
+ import { customSerializers } from 'sanity-naive-html-serializer';
6
+ import { defaultStopTypes } from 'sanity-naive-html-serializer';
7
+ import { DeserializerRule } from '@sanity/block-tools';
8
+ import { JSX } from 'react';
9
+ import { Plugin as Plugin_2 } from 'sanity';
10
+ import { PortableTextTypeComponent } from '@portabletext/to-html';
11
+ import { SanityClient } from 'sanity';
12
+ import { SanityDocument } from 'sanity';
13
+ import { Schema } from 'sanity';
14
+ import { SerializedDocument } from 'sanity-naive-html-serializer';
15
+ import { TypedObject } from 'sanity';
16
+
17
+ export declare interface Adapter {
18
+ getLocales: (secrets: Secrets | null) => Promise<TranslationLocale[]>;
19
+ getTranslationTask: (
20
+ document: GTFile,
21
+ secrets: Secrets | null
22
+ ) => Promise<TranslationTask>;
23
+ createTask: (
24
+ documentInfo: GTFile,
25
+ serializedDocument: GTSerializedDocument,
26
+ localeIds: string[],
27
+ secrets: Secrets | null,
28
+ workflowUid?: string,
29
+ callbackUrl?: string
30
+ ) => Promise<TranslationTask>;
31
+ getTranslation: (
32
+ document: GTFile,
33
+ localeId: string,
34
+ secrets: Secrets | null
35
+ ) => Promise<any | null>;
36
+ }
37
+
38
+ export { BaseDocumentDeserializer };
39
+
40
+ export { BaseDocumentMerger };
41
+
42
+ export { BaseDocumentSerializer };
43
+
44
+ declare interface ConfigOptions {
45
+ adapter: Adapter;
46
+ secretsNamespace: string | null;
47
+ exportForTranslation: (
48
+ docInfo: GTFile,
49
+ context: TranslationFunctionContext
50
+ ) => Promise<GTSerializedDocument>;
51
+ importTranslation: (
52
+ docInfo: GTFile,
53
+ localeId: string,
54
+ doc: string,
55
+ context: TranslationFunctionContext
56
+ ) => Promise<void>;
57
+ }
58
+
59
+ export { customSerializers };
60
+
61
+ export declare const defaultDocumentLevelConfig: ConfigOptions;
62
+
63
+ export declare const defaultFieldLevelConfig: ConfigOptions;
64
+
65
+ export { defaultStopTypes };
66
+
67
+ export declare const documentLevelPatch: (
68
+ docInfo: GTFile,
69
+ translatedFields: SanityDocument,
70
+ localeId: string,
71
+ client: SanityClient,
72
+ languageField?: string,
73
+ mergeWithTargetLocale?: boolean
74
+ ) => Promise<void>;
75
+
76
+ export declare type ExportForTranslation = (
77
+ documentInfo: GTFile,
78
+ context: TranslationFunctionContext,
79
+ serializationOptions?: {
80
+ additionalStopTypes?: string[];
81
+ additionalSerializers?: Record<
82
+ string,
83
+ PortableTextTypeComponent | undefined
84
+ >;
85
+ },
86
+ languageField?: string
87
+ ) => Promise<GTSerializedDocument>;
88
+
89
+ export declare const fieldLevelPatch: (
90
+ docInfo: GTFile,
91
+ translatedFields: SanityDocument,
92
+ localeId: string,
93
+ client: SanityClient,
94
+ mergeWithTargetLocale?: boolean
95
+ ) => Promise<void>;
96
+
97
+ export declare const findLatestDraft: (
98
+ documentId: string,
99
+ client: SanityClient
100
+ ) => Promise<SanityDocument>;
101
+
102
+ export declare const GTAdapter: Adapter;
103
+
104
+ declare type GTFile = {
105
+ documentId: string;
106
+ versionId?: string;
107
+ };
108
+
109
+ /**
110
+ * Usage in `sanity.config.ts` (or .js)
111
+ *
112
+ * ```ts
113
+ * import {defineConfig} from 'sanity'
114
+ * import {gtPlugin} from '@generaltranslation/sanity'
115
+ *
116
+ * export default defineConfig({
117
+ * // ...
118
+ * plugins: [gtPlugin()],
119
+ * })
120
+ * ```
121
+ */
122
+ export declare const gtPlugin: Plugin_2<
123
+ Omit<
124
+ {
125
+ apiKey?: string;
126
+ devApiKey?: string;
127
+ sourceLocale?: string;
128
+ targetLocale?: string;
129
+ locales?: string[];
130
+ projectId?: string;
131
+ baseUrl?: string;
132
+ customMapping?: CustomMapping;
133
+ },
134
+ 'locales'
135
+ > & {
136
+ locales: string[];
137
+ }
138
+ >;
139
+
140
+ declare type GTSerializedDocument = Omit<SerializedDocument, 'name'> & GTFile;
141
+
142
+ export declare type ImportTranslation = (
143
+ documentInfo: GTFile,
144
+ localeId: string,
145
+ document: string,
146
+ context: TranslationFunctionContext,
147
+ serializationOptions?: {
148
+ additionalDeserializers?: Record<
149
+ string,
150
+ (value: HTMLElement) => TypedObject
151
+ >;
152
+ additionalBlockDeserializers?: DeserializerRule[];
153
+ },
154
+ languageField?: string,
155
+ mergeWithTargetLocale?: boolean
156
+ ) => Promise<void>;
157
+
158
+ export declare const legacyDocumentLevelConfig: ConfigOptions;
159
+
160
+ export declare const legacyDocumentLevelPatch: (
161
+ docInfo: GTFile,
162
+ translatedFields: SanityDocument,
163
+ localeId: string,
164
+ client: SanityClient
165
+ ) => Promise<void>;
166
+
167
+ export declare type Secrets = {
168
+ organization: string;
169
+ project: string;
170
+ token?: string;
171
+ secret?: string;
172
+ username?: string;
173
+ password?: string;
174
+ proxy?: string;
175
+ };
176
+
177
+ export { SerializedDocument };
178
+
179
+ export declare interface TranslationFunctionContext {
180
+ client: SanityClient;
181
+ schema: Schema;
182
+ }
183
+
184
+ declare type TranslationLocale = {
185
+ localeId: string;
186
+ description: string;
187
+ enabled?: boolean;
188
+ };
189
+
190
+ export declare const TranslationsTab: (
191
+ props: TranslationTabProps
192
+ ) => JSX.Element;
193
+
194
+ export declare type TranslationsTabConfigOptions = {
195
+ adapter: Adapter;
196
+ secretsNamespace: string | null;
197
+ exportForTranslation: ExportForTranslation;
198
+ importTranslation: ImportTranslation;
199
+ serializationOptions?: {
200
+ additionalStopTypes?: string[];
201
+ additionalSerializers?: Record<
202
+ string,
203
+ PortableTextTypeComponent | undefined
204
+ >;
205
+ additionalDeserializers?: Record<
206
+ string,
207
+ (value: HTMLElement) => TypedObject
208
+ >;
209
+ additionalBlockDeserializers?: DeserializerRule[];
210
+ };
211
+ workflowOptions?: WorkflowIdentifiers[];
212
+ localeIdAdapter?: (id: string) => string;
213
+ languageField?: string;
214
+ callbackUrl?: string;
215
+ mergeWithTargetLocale?: boolean;
216
+ };
217
+
218
+ declare type TranslationTabProps = {
219
+ document: {
220
+ displayed: SanityDocument;
221
+ };
222
+ options: TranslationsTabConfigOptions;
223
+ };
224
+
225
+ declare type TranslationTask = {
226
+ document: GTFile;
227
+ locales: TranslationTaskLocaleStatus[];
228
+ linkToVendorTask?: string;
229
+ };
230
+
231
+ declare type TranslationTaskLocaleStatus = {
232
+ localeId: string;
233
+ progress: number;
234
+ };
235
+
236
+ declare type WorkflowIdentifiers = {
237
+ workflowUid: string;
238
+ workflowName: string;
239
+ };
240
+
241
+ export {};
@@ -0,0 +1,241 @@
1
+ import { BaseDocumentDeserializer } from 'sanity-naive-html-serializer';
2
+ import { BaseDocumentMerger } from 'sanity-naive-html-serializer';
3
+ import { BaseDocumentSerializer } from 'sanity-naive-html-serializer';
4
+ import { CustomMapping } from 'generaltranslation/types';
5
+ import { customSerializers } from 'sanity-naive-html-serializer';
6
+ import { defaultStopTypes } from 'sanity-naive-html-serializer';
7
+ import { DeserializerRule } from '@sanity/block-tools';
8
+ import { JSX } from 'react';
9
+ import { Plugin as Plugin_2 } from 'sanity';
10
+ import { PortableTextTypeComponent } from '@portabletext/to-html';
11
+ import { SanityClient } from 'sanity';
12
+ import { SanityDocument } from 'sanity';
13
+ import { Schema } from 'sanity';
14
+ import { SerializedDocument } from 'sanity-naive-html-serializer';
15
+ import { TypedObject } from 'sanity';
16
+
17
+ export declare interface Adapter {
18
+ getLocales: (secrets: Secrets | null) => Promise<TranslationLocale[]>;
19
+ getTranslationTask: (
20
+ document: GTFile,
21
+ secrets: Secrets | null
22
+ ) => Promise<TranslationTask>;
23
+ createTask: (
24
+ documentInfo: GTFile,
25
+ serializedDocument: GTSerializedDocument,
26
+ localeIds: string[],
27
+ secrets: Secrets | null,
28
+ workflowUid?: string,
29
+ callbackUrl?: string
30
+ ) => Promise<TranslationTask>;
31
+ getTranslation: (
32
+ document: GTFile,
33
+ localeId: string,
34
+ secrets: Secrets | null
35
+ ) => Promise<any | null>;
36
+ }
37
+
38
+ export { BaseDocumentDeserializer };
39
+
40
+ export { BaseDocumentMerger };
41
+
42
+ export { BaseDocumentSerializer };
43
+
44
+ declare interface ConfigOptions {
45
+ adapter: Adapter;
46
+ secretsNamespace: string | null;
47
+ exportForTranslation: (
48
+ docInfo: GTFile,
49
+ context: TranslationFunctionContext
50
+ ) => Promise<GTSerializedDocument>;
51
+ importTranslation: (
52
+ docInfo: GTFile,
53
+ localeId: string,
54
+ doc: string,
55
+ context: TranslationFunctionContext
56
+ ) => Promise<void>;
57
+ }
58
+
59
+ export { customSerializers };
60
+
61
+ export declare const defaultDocumentLevelConfig: ConfigOptions;
62
+
63
+ export declare const defaultFieldLevelConfig: ConfigOptions;
64
+
65
+ export { defaultStopTypes };
66
+
67
+ export declare const documentLevelPatch: (
68
+ docInfo: GTFile,
69
+ translatedFields: SanityDocument,
70
+ localeId: string,
71
+ client: SanityClient,
72
+ languageField?: string,
73
+ mergeWithTargetLocale?: boolean
74
+ ) => Promise<void>;
75
+
76
+ export declare type ExportForTranslation = (
77
+ documentInfo: GTFile,
78
+ context: TranslationFunctionContext,
79
+ serializationOptions?: {
80
+ additionalStopTypes?: string[];
81
+ additionalSerializers?: Record<
82
+ string,
83
+ PortableTextTypeComponent | undefined
84
+ >;
85
+ },
86
+ languageField?: string
87
+ ) => Promise<GTSerializedDocument>;
88
+
89
+ export declare const fieldLevelPatch: (
90
+ docInfo: GTFile,
91
+ translatedFields: SanityDocument,
92
+ localeId: string,
93
+ client: SanityClient,
94
+ mergeWithTargetLocale?: boolean
95
+ ) => Promise<void>;
96
+
97
+ export declare const findLatestDraft: (
98
+ documentId: string,
99
+ client: SanityClient
100
+ ) => Promise<SanityDocument>;
101
+
102
+ export declare const GTAdapter: Adapter;
103
+
104
+ declare type GTFile = {
105
+ documentId: string;
106
+ versionId?: string;
107
+ };
108
+
109
+ /**
110
+ * Usage in `sanity.config.ts` (or .js)
111
+ *
112
+ * ```ts
113
+ * import {defineConfig} from 'sanity'
114
+ * import {gtPlugin} from '@generaltranslation/sanity'
115
+ *
116
+ * export default defineConfig({
117
+ * // ...
118
+ * plugins: [gtPlugin()],
119
+ * })
120
+ * ```
121
+ */
122
+ export declare const gtPlugin: Plugin_2<
123
+ Omit<
124
+ {
125
+ apiKey?: string;
126
+ devApiKey?: string;
127
+ sourceLocale?: string;
128
+ targetLocale?: string;
129
+ locales?: string[];
130
+ projectId?: string;
131
+ baseUrl?: string;
132
+ customMapping?: CustomMapping;
133
+ },
134
+ 'locales'
135
+ > & {
136
+ locales: string[];
137
+ }
138
+ >;
139
+
140
+ declare type GTSerializedDocument = Omit<SerializedDocument, 'name'> & GTFile;
141
+
142
+ export declare type ImportTranslation = (
143
+ documentInfo: GTFile,
144
+ localeId: string,
145
+ document: string,
146
+ context: TranslationFunctionContext,
147
+ serializationOptions?: {
148
+ additionalDeserializers?: Record<
149
+ string,
150
+ (value: HTMLElement) => TypedObject
151
+ >;
152
+ additionalBlockDeserializers?: DeserializerRule[];
153
+ },
154
+ languageField?: string,
155
+ mergeWithTargetLocale?: boolean
156
+ ) => Promise<void>;
157
+
158
+ export declare const legacyDocumentLevelConfig: ConfigOptions;
159
+
160
+ export declare const legacyDocumentLevelPatch: (
161
+ docInfo: GTFile,
162
+ translatedFields: SanityDocument,
163
+ localeId: string,
164
+ client: SanityClient
165
+ ) => Promise<void>;
166
+
167
+ export declare type Secrets = {
168
+ organization: string;
169
+ project: string;
170
+ token?: string;
171
+ secret?: string;
172
+ username?: string;
173
+ password?: string;
174
+ proxy?: string;
175
+ };
176
+
177
+ export { SerializedDocument };
178
+
179
+ export declare interface TranslationFunctionContext {
180
+ client: SanityClient;
181
+ schema: Schema;
182
+ }
183
+
184
+ declare type TranslationLocale = {
185
+ localeId: string;
186
+ description: string;
187
+ enabled?: boolean;
188
+ };
189
+
190
+ export declare const TranslationsTab: (
191
+ props: TranslationTabProps
192
+ ) => JSX.Element;
193
+
194
+ export declare type TranslationsTabConfigOptions = {
195
+ adapter: Adapter;
196
+ secretsNamespace: string | null;
197
+ exportForTranslation: ExportForTranslation;
198
+ importTranslation: ImportTranslation;
199
+ serializationOptions?: {
200
+ additionalStopTypes?: string[];
201
+ additionalSerializers?: Record<
202
+ string,
203
+ PortableTextTypeComponent | undefined
204
+ >;
205
+ additionalDeserializers?: Record<
206
+ string,
207
+ (value: HTMLElement) => TypedObject
208
+ >;
209
+ additionalBlockDeserializers?: DeserializerRule[];
210
+ };
211
+ workflowOptions?: WorkflowIdentifiers[];
212
+ localeIdAdapter?: (id: string) => string;
213
+ languageField?: string;
214
+ callbackUrl?: string;
215
+ mergeWithTargetLocale?: boolean;
216
+ };
217
+
218
+ declare type TranslationTabProps = {
219
+ document: {
220
+ displayed: SanityDocument;
221
+ };
222
+ options: TranslationsTabConfigOptions;
223
+ };
224
+
225
+ declare type TranslationTask = {
226
+ document: GTFile;
227
+ locales: TranslationTaskLocaleStatus[];
228
+ linkToVendorTask?: string;
229
+ };
230
+
231
+ declare type TranslationTaskLocaleStatus = {
232
+ localeId: string;
233
+ progress: number;
234
+ };
235
+
236
+ declare type WorkflowIdentifiers = {
237
+ workflowUid: string;
238
+ workflowName: string;
239
+ };
240
+
241
+ export {};