@braze/sanity-plugin-ai-translation 0.2.39 → 0.2.52
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 +16 -54
- package/dist/index.d.ts +52 -4
- package/dist/index.js +1371 -1509
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- 🤖 **AI-Powered Translation** - Uses Sanity Agent Actions to translate documents between languages
|
|
8
|
-
-
|
|
8
|
+
- 📦 **Content Releases** - Translations are created in Content Releases for staged publishing
|
|
9
9
|
- 🔗 **Reference Translation** - Optionally translate referenced documents recursively with configurable depth
|
|
10
10
|
- 🎯 **Custom Translation Prompts** - Configure global and locale-specific translation instructions
|
|
11
11
|
- 📚 **Translation Glossary** - Define term-specific translations to ensure consistency
|
|
12
12
|
- 🛡️ **Protected Phrases** - Specify terms that should never be translated (e.g., brand names, product names)
|
|
13
|
-
- 💬 **Feedback System** - AI-powered feedback analysis that automatically improves translation settings
|
|
14
13
|
- ⚙️ **Flexible Configuration** - Control concurrent translation jobs, reference depth, and translation behavior
|
|
15
14
|
- 🔍 **Debug Mode** - Comprehensive logging for troubleshooting translation issues
|
|
16
15
|
|
|
@@ -90,7 +89,7 @@ export default defineConfig({
|
|
|
90
89
|
|
|
91
90
|
### OpenAI Integration (Optional)
|
|
92
91
|
|
|
93
|
-
The plugin supports optional OpenAI integration for enhanced translation capabilities, including
|
|
92
|
+
The plugin supports optional OpenAI integration for enhanced translation capabilities, including direct OpenAI translation with no character limits.
|
|
94
93
|
|
|
95
94
|
#### Setup
|
|
96
95
|
|
|
@@ -103,7 +102,7 @@ aiTranslationPlugin({
|
|
|
103
102
|
reasoningEffort: 'medium', // Optional: 'minimal' | 'low' | 'medium' | 'high'
|
|
104
103
|
verbosity: 'medium', // Optional: 'low' | 'medium' | 'high'
|
|
105
104
|
enabled: true, // Optional, defaults to false
|
|
106
|
-
defaultMode: '
|
|
105
|
+
defaultMode: 'openai-only', // Optional, defaults to 'sanity-only'
|
|
107
106
|
}
|
|
108
107
|
})
|
|
109
108
|
```
|
|
@@ -117,7 +116,7 @@ OPENAI_API_KEY=sk-...your-key-here...
|
|
|
117
116
|
|
|
118
117
|
#### Translation Modes
|
|
119
118
|
|
|
120
|
-
When OpenAI is enabled, users can select from
|
|
119
|
+
When OpenAI is enabled, users can select from two translation modes:
|
|
121
120
|
|
|
122
121
|
1. **Sanity Agent Only** (Default)
|
|
123
122
|
- Uses Sanity's built-in translation agent
|
|
@@ -125,21 +124,15 @@ When OpenAI is enabled, users can select from three translation modes:
|
|
|
125
124
|
- No additional API costs
|
|
126
125
|
- 2000 character style guide limit
|
|
127
126
|
|
|
128
|
-
2. **
|
|
129
|
-
- Direct translation via
|
|
127
|
+
2. **OpenAI Only** (Beta)
|
|
128
|
+
- Direct translation via OpenAI
|
|
130
129
|
- 1 million token context window
|
|
131
130
|
- Full style guide capacity
|
|
132
131
|
- Incurs OpenAI API costs
|
|
133
132
|
|
|
134
|
-
|
|
135
|
-
- Sanity translation reviewed and refined by GPT-5
|
|
136
|
-
- Best quality results
|
|
137
|
-
- Approximately 2x processing time
|
|
138
|
-
- Incurs OpenAI API costs
|
|
139
|
-
|
|
140
|
-
#### GPT-5 Features
|
|
133
|
+
#### OpenAI Features
|
|
141
134
|
|
|
142
|
-
|
|
135
|
+
OpenAI models provide:
|
|
143
136
|
- **1M token context window** - Handle very large documents and style guides
|
|
144
137
|
- **Advanced reasoning** - Configurable reasoning effort for quality vs. speed tradeoff
|
|
145
138
|
- **Verbosity control** - Adjust response length to optimize token usage
|
|
@@ -148,7 +141,7 @@ GPT-5 (released August 2025) provides:
|
|
|
148
141
|
#### Cost Considerations
|
|
149
142
|
|
|
150
143
|
OpenAI modes incur API costs based on token usage:
|
|
151
|
-
- **
|
|
144
|
+
- **OpenAI**: ~$0.002 per 1k input tokens, ~$0.010 per 1k output tokens, ~$0.005 per 1k reasoning tokens
|
|
152
145
|
- **Typical article** (2000 words): ~$0.05-0.15 per translation
|
|
153
146
|
- The plugin shows real-time cost estimates and usage summaries
|
|
154
147
|
|
|
@@ -158,8 +151,8 @@ OpenAI modes incur API costs based on token usage:
|
|
|
158
151
|
|--------|------|---------|-------------|
|
|
159
152
|
| `apiKey` | `string` | - | OpenAI API key (required if OpenAI enabled) |
|
|
160
153
|
| `model` | `'gpt-5' \| 'gpt-4o' \| 'gpt-4-turbo' \| 'gpt-4'` | `'gpt-5'` | Model to use for translation/review |
|
|
161
|
-
| `reasoningEffort` | `'minimal' \| 'low' \| 'medium' \| 'high'` | `'medium'` |
|
|
162
|
-
| `verbosity` | `'low' \| 'medium' \| 'high'` | `'medium'` |
|
|
154
|
+
| `reasoningEffort` | `'minimal' \| 'low' \| 'medium' \| 'high'` | `'medium'` | OpenAI reasoning effort (affects speed and quality) |
|
|
155
|
+
| `verbosity` | `'low' \| 'medium' \| 'high'` | `'medium'` | OpenAI response verbosity |
|
|
163
156
|
| `enabled` | `boolean` | `false` | Enable OpenAI features |
|
|
164
157
|
| `defaultMode` | `TranslationMode` | `'sanity-only'` | Default translation mode when dialog opens |
|
|
165
158
|
|
|
@@ -205,19 +198,6 @@ Once configured, a "Translate" action will appear on all documents of types list
|
|
|
205
198
|
- **Max reference depth** - How deep to traverse references (if enabled)
|
|
206
199
|
5. Click "Translate" to start
|
|
207
200
|
|
|
208
|
-
### Translation States
|
|
209
|
-
|
|
210
|
-
The plugin tracks three translation states:
|
|
211
|
-
|
|
212
|
-
- **Fresh** ✅ - Translation is up-to-date with source
|
|
213
|
-
- **Stale** ⚠️ - Source document revision changed (trivial changes)
|
|
214
|
-
- **Drifted** 🔴 - Source document content changed significantly
|
|
215
|
-
|
|
216
|
-
Based on state:
|
|
217
|
-
- **Fresh** translations are skipped (unless "Overwrite fresh" is enabled)
|
|
218
|
-
- **Stale** translations can use diff-based translation (if "Translate only diffs" is enabled)
|
|
219
|
-
- **Drifted** translations are fully re-translated
|
|
220
|
-
|
|
221
201
|
### Translation Settings
|
|
222
202
|
|
|
223
203
|
Create a `translationSettings` document to customize translation behavior:
|
|
@@ -263,34 +243,16 @@ Create `translationGlossaryTerm` documents for specific term mappings:
|
|
|
263
243
|
}
|
|
264
244
|
```
|
|
265
245
|
|
|
266
|
-
### Give Translation Feedback
|
|
267
|
-
|
|
268
|
-
The plugin includes an AI-powered feedback system that learns from corrections:
|
|
269
|
-
|
|
270
|
-
1. Open a translated document
|
|
271
|
-
2. Click "Give Translation Feedback" action
|
|
272
|
-
3. Provide feedback and/or enable "Include edits" to analyze changes
|
|
273
|
-
4. Review AI-generated suggestions:
|
|
274
|
-
- Global prompt updates
|
|
275
|
-
- Locale-specific prompt updates
|
|
276
|
-
- Protected phrases to add
|
|
277
|
-
- Glossary terms to add
|
|
278
|
-
5. Approve suggestions to apply
|
|
279
|
-
|
|
280
|
-
The AI analyzes your feedback and automatically updates translation settings to improve future translations.
|
|
281
|
-
|
|
282
246
|
## Translation Workflow
|
|
283
247
|
|
|
284
248
|
### How It Works
|
|
285
249
|
|
|
286
|
-
1. **
|
|
287
|
-
2. **
|
|
288
|
-
3. **
|
|
289
|
-
|
|
290
|
-
- For **stale (translate diffs)**: Diff-based translation of changed fields only
|
|
291
|
-
4. **Translate** - Uses Sanity Agent Actions with configured prompts
|
|
250
|
+
1. **Select Release** - Choose to create a new Content Release or add to an existing one
|
|
251
|
+
2. **Prepare Translation** - Assemble translation prompts and prepare source document
|
|
252
|
+
3. **Translate** - Uses Sanity Agent Actions (or OpenAI) with configured prompts
|
|
253
|
+
4. **Create Versions** - Translations are created as versioned documents in the release
|
|
292
254
|
5. **Localize References** - Optionally translates referenced documents
|
|
293
|
-
6. **Update Metadata** - Stores translation history
|
|
255
|
+
6. **Update Metadata** - Stores translation history
|
|
294
256
|
|
|
295
257
|
### Reference Translation
|
|
296
258
|
|
package/dist/index.d.ts
CHANGED
|
@@ -446,6 +446,21 @@ declare interface TranslatableVTTCaptions {
|
|
|
446
446
|
_originalMetadata: VTTCaptionMetadata[];
|
|
447
447
|
}
|
|
448
448
|
|
|
449
|
+
/**
|
|
450
|
+
* Special type to track transformed Wistia captions.
|
|
451
|
+
* This combines metadata separation for token efficiency with compact text format for translation.
|
|
452
|
+
*/
|
|
453
|
+
declare interface TranslatableWistiaCaptions {
|
|
454
|
+
_type: "translatable.wistia.captions";
|
|
455
|
+
translationText: string;
|
|
456
|
+
_originalMetadata: WistiaCaptionsMetadata;
|
|
457
|
+
_srtCues: Array<{
|
|
458
|
+
index: number;
|
|
459
|
+
startTime: string;
|
|
460
|
+
endTime: string;
|
|
461
|
+
}>;
|
|
462
|
+
}
|
|
463
|
+
|
|
449
464
|
/**
|
|
450
465
|
* Schema for translation history
|
|
451
466
|
*
|
|
@@ -459,10 +474,7 @@ export declare const translationHistorySchema: {
|
|
|
459
474
|
WidenValidation &
|
|
460
475
|
WidenInitialValue;
|
|
461
476
|
|
|
462
|
-
declare type TranslationMode =
|
|
463
|
-
| "sanity-only"
|
|
464
|
-
| "openai-only"
|
|
465
|
-
| "sanity-with-review";
|
|
477
|
+
declare type TranslationMode = "sanity-only" | "openai-only";
|
|
466
478
|
|
|
467
479
|
/**
|
|
468
480
|
* Represents a VTT caption cue with timing and text content.
|
|
@@ -500,4 +512,40 @@ export declare const vttCaptionTransform: FieldTransform<
|
|
|
500
512
|
TranslatableVTTCaptions
|
|
501
513
|
>;
|
|
502
514
|
|
|
515
|
+
/**
|
|
516
|
+
* Represents a Wistia captions object with SRT content and metadata.
|
|
517
|
+
*/
|
|
518
|
+
declare interface WistiaCaptions {
|
|
519
|
+
captionContent?: string;
|
|
520
|
+
captionFileName?: string;
|
|
521
|
+
isoLanguage?: string;
|
|
522
|
+
captionUploadStatus?: string;
|
|
523
|
+
captionUploadMessage?: string;
|
|
524
|
+
[key: string]: string | undefined;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Wistia captions metadata without captionContent, used for preservation during translation.
|
|
529
|
+
*/
|
|
530
|
+
declare interface WistiaCaptionsMetadata {
|
|
531
|
+
captionFileName?: string;
|
|
532
|
+
isoLanguage?: string;
|
|
533
|
+
captionUploadStatus?: string;
|
|
534
|
+
captionUploadMessage?: string;
|
|
535
|
+
_originalIndex: number;
|
|
536
|
+
[key: string]: string | number | undefined;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Transform for handling Wistia captions in documents using SRT format.
|
|
541
|
+
* This stores metadata separately for token efficiency while formatting
|
|
542
|
+
* text content in a compact indexed format for better translation results.
|
|
543
|
+
*
|
|
544
|
+
* @public
|
|
545
|
+
*/
|
|
546
|
+
export declare const wistiaCaptionTransform: FieldTransform<
|
|
547
|
+
WistiaCaptions,
|
|
548
|
+
TranslatableWistiaCaptions
|
|
549
|
+
>;
|
|
550
|
+
|
|
503
551
|
export {};
|