gt-sanity 4.0.32 → 4.0.33
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 +48 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +474 -107
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/adapter/core.ts +11 -2
- package/src/components/TranslationsProvider.tsx +183 -20
- package/src/components/__tests__/TranslationsProvider.test.ts +195 -0
- package/src/components/tab/TranslationView.tsx +43 -1
- package/src/components/tab/__tests__/TranslationView.test.ts +106 -0
- package/src/configuration/baseDocumentLevelConfig/__tests__/documentLevelPatch.test.ts +4 -2
- package/src/configuration/baseDocumentLevelConfig/__tests__/documentLevelPatchNonDefaultSource.test.ts +24 -0
- package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.ts +30 -10
- package/src/configuration/baseDocumentLevelConfig/helpers/createI18nDocAndPatchMetadata.ts +18 -11
- package/src/configuration/baseDocumentLevelConfig/index.ts +2 -2
- package/src/configuration/internationalizedArrayConfig/internationalizedArrayPatch.ts +7 -5
- package/src/index.ts +8 -1
- package/src/translation/__tests__/bulkSources.test.ts +33 -0
- package/src/translation/__tests__/collectExistingTranslations.test.ts +5 -0
- package/src/translation/__tests__/previewUrls.test.ts +416 -0
- package/src/translation/__tests__/updatePreviewUrls.test.ts +129 -0
- package/src/translation/__tests__/uploadFiles.test.ts +36 -0
- package/src/translation/bulkSources.ts +8 -3
- package/src/translation/collectExistingTranslations.ts +15 -2
- package/src/translation/importDocument.ts +3 -1
- package/src/translation/previewUrls.ts +302 -0
- package/src/translation/strategy.ts +2 -1
- package/src/translation/updatePreviewUrls.ts +46 -0
- package/src/translation/uploadFiles.ts +1 -0
- package/src/types.ts +2 -0
- package/src/utils/__tests__/groqClient.ts +26 -2
- package/src/utils/batchProcessor.ts +6 -1
- package/src/utils/importUtils.ts +31 -1
package/README.md
CHANGED
|
@@ -199,6 +199,54 @@ not supported. gt-sanity then ignores the marker, as it did before the option
|
|
|
199
199
|
existed, so a `sourceLocale` translation of an original in another locale is
|
|
200
200
|
treated as an original and can be translated from again.
|
|
201
201
|
|
|
202
|
+
## Preview URLs
|
|
203
|
+
|
|
204
|
+
To let reviewers in General Translation open a string on the page that shows
|
|
205
|
+
it, give the plugin your site's origin and the page of each document type, in
|
|
206
|
+
the same shape as `presentationTool`'s `resolve.locations` (the Presentation
|
|
207
|
+
tool itself is not required). `resolve` also gets the Sanity language id of the
|
|
208
|
+
page being linked, so it can build each locale's URL:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
gtPlugin({
|
|
212
|
+
// ...
|
|
213
|
+
previewUrl: {
|
|
214
|
+
origin: 'https://staging.example.com',
|
|
215
|
+
locations: {
|
|
216
|
+
page: {
|
|
217
|
+
select: { slug: 'slug.current' },
|
|
218
|
+
resolve: (doc, { language }) => ({
|
|
219
|
+
locations: [
|
|
220
|
+
{ title: 'Page', href: localizedPath(language, doc?.slug) },
|
|
221
|
+
],
|
|
222
|
+
}),
|
|
223
|
+
},
|
|
224
|
+
// Shared content links to a page that shows it.
|
|
225
|
+
siteSettings: {
|
|
226
|
+
select: {},
|
|
227
|
+
resolve: (_doc, { language }) => ({
|
|
228
|
+
locations: [{ title: 'Home', href: localizedPath(language, '') }],
|
|
229
|
+
}),
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
`localizedPath` stands for your own routing, such as `es-ES` to `/es/...`. Studios
|
|
237
|
+
that use Presentation can pass the same `resolve.locations`; resolvers that
|
|
238
|
+
ignore the language link every locale to the same page.
|
|
239
|
+
|
|
240
|
+
Each uploaded source document is sent with its first location, resolved from
|
|
241
|
+
its published version in its own language. When a translation is imported, its
|
|
242
|
+
page is resolved from the document it was written to (the translated document
|
|
243
|
+
for document-level types, the same document for field-level types), in the
|
|
244
|
+
target language, and stored in General Translation as that translation's
|
|
245
|
+
preview URL. That document is usually still a draft, so it is read with drafts
|
|
246
|
+
included. A type with fixed locations always links them. Other unpublished
|
|
247
|
+
source documents, and types with no location, get no URL. Failing to resolve or
|
|
248
|
+
store a URL warns and never stops an upload or import.
|
|
249
|
+
|
|
202
250
|
## Automatic Actions
|
|
203
251
|
|
|
204
252
|
The Translate dialog on a document can refresh status, import a translation as
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { DocumentActionComponent } from "sanity";
|
|
|
3
3
|
import { documentInternationalization } from "@sanity/document-internationalization";
|
|
4
4
|
import { PluginConfig as DocumentInternationalizationConfig } from "@sanity/document-internationalization";
|
|
5
5
|
import { DocumentInternationalizationMenu } from "@sanity/document-internationalization";
|
|
6
|
+
import type { DocumentLocationResolverObject } from "sanity/presentation";
|
|
7
|
+
import type { DocumentLocationsState } from "sanity/presentation";
|
|
6
8
|
import { GT } from "generaltranslation";
|
|
7
9
|
import { internationalizedArray } from "sanity-plugin-internationalized-array";
|
|
8
10
|
import { Language as InternationalizedArrayLanguage } from "sanity-plugin-internationalized-array";
|
|
@@ -244,6 +246,8 @@ declare type GTFile = {
|
|
|
244
246
|
* configured source locale. Omitted means the configured source locale.
|
|
245
247
|
*/
|
|
246
248
|
sourceLocale?: string;
|
|
249
|
+
/** Page on the site that shows this version of the document. */
|
|
250
|
+
previewUrl?: string;
|
|
247
251
|
};
|
|
248
252
|
|
|
249
253
|
/**
|
|
@@ -309,6 +313,7 @@ export declare type GTPluginConfig = Omit<
|
|
|
309
313
|
autoImport?: boolean;
|
|
310
314
|
autoPatchReferences?: boolean;
|
|
311
315
|
autoPublish?: boolean;
|
|
316
|
+
previewUrl?: PreviewUrlConfig;
|
|
312
317
|
};
|
|
313
318
|
|
|
314
319
|
/**
|
|
@@ -410,6 +415,26 @@ declare interface Merger {
|
|
|
410
415
|
|
|
411
416
|
export { Metadata };
|
|
412
417
|
|
|
418
|
+
export declare type PreviewUrlConfig = {
|
|
419
|
+
/** Origin of the site that shows the documents, e.g. `https://staging.example.com`. */
|
|
420
|
+
origin: string;
|
|
421
|
+
/** Locations by document type, as given to `presentationTool({ resolve: { locations } })`; a document's first location is its page. */
|
|
422
|
+
locations: Record<string, PreviewUrlResolver | DocumentLocationsState>;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
/** Presentation's location resolver, with the Sanity language id of the page being linked as the second argument. */
|
|
426
|
+
declare type PreviewUrlResolver = Omit<
|
|
427
|
+
DocumentLocationResolverObject,
|
|
428
|
+
"resolve"
|
|
429
|
+
> & {
|
|
430
|
+
resolve: (
|
|
431
|
+
document: Parameters<DocumentLocationResolverObject["resolve"]>[0],
|
|
432
|
+
context: {
|
|
433
|
+
language: string;
|
|
434
|
+
},
|
|
435
|
+
) => ReturnType<DocumentLocationResolverObject["resolve"]>;
|
|
436
|
+
};
|
|
437
|
+
|
|
413
438
|
/**
|
|
414
439
|
* A raw (uncompiled) schema field or array-member definition. Inline object
|
|
415
440
|
* declarations carry their `fields` here, and array declarations carry their
|