gt-sanity 0.0.5 → 0.0.6
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.md +1 -8
- package/README.md +5 -5
- package/dist/index.d.mts +35 -30
- package/dist/index.d.ts +35 -30
- package/dist/index.js +234 -123
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +237 -124
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
- package/src/adapter/core.ts +72 -7
- package/src/adapter/createTask.ts +1 -1
- package/src/adapter/types.ts +9 -0
- package/src/components/LanguageStatus.tsx +2 -0
- package/src/components/NewTask.tsx +2 -0
- package/src/components/ProgressBar.tsx +2 -0
- package/src/components/TaskView.tsx +2 -0
- package/src/components/TranslationContext.tsx +5 -0
- package/src/components/TranslationView.tsx +34 -2
- package/src/components/TranslationsTab.tsx +4 -0
- package/src/components/page/TranslationsTool.tsx +876 -0
- package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.ts +23 -10
- package/src/configuration/baseDocumentLevelConfig/helpers/createI18nDocAndPatchMetadata.ts +77 -24
- package/src/configuration/baseDocumentLevelConfig/helpers/createTranslationMetadata.ts +2 -0
- package/src/configuration/baseDocumentLevelConfig/helpers/getOrCreateTranslationMetadata.ts +2 -0
- package/src/configuration/baseDocumentLevelConfig/helpers/getTranslationMetadata.ts +2 -0
- package/src/configuration/baseDocumentLevelConfig/helpers/patchI18nDoc.ts +51 -8
- package/src/configuration/baseDocumentLevelConfig/index.ts +6 -37
- package/src/configuration/baseFieldLevelConfig.ts +4 -1
- package/src/configuration/utils/checkSerializationVersion.ts +2 -0
- package/src/configuration/utils/findDocumentAtRevision.ts +2 -0
- package/src/configuration/utils/findLatestDraft.ts +2 -0
- package/src/hooks/useClient.ts +3 -1
- package/src/hooks/useSecrets.ts +2 -0
- package/src/index.ts +70 -32
- package/src/translation/checkTranslationStatus.ts +42 -0
- package/src/translation/createJobs.ts +16 -0
- package/src/translation/downloadTranslations.ts +68 -0
- package/src/translation/importDocument.ts +24 -0
- package/src/translation/initProject.ts +61 -0
- package/src/translation/uploadFiles.ts +32 -0
- package/src/types.ts +4 -1
- package/src/utils/applyDocuments.ts +72 -0
- package/src/utils/serialize.ts +32 -0
- package/src/utils/shared.ts +1 -0
- package/src/configuration/baseDocumentLevelConfig/helpers/index.ts +0 -5
- package/src/configuration/baseDocumentLevelConfig/legacyDocumentLevelPatch.ts +0 -69
- package/src/configuration/index.ts +0 -18
- package/src/configuration/utils/index.ts +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt-sanity",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "General Translation integration with Sanity",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -59,11 +59,13 @@
|
|
|
59
59
|
"@sanity/incompatible-plugin": "^1.0.5",
|
|
60
60
|
"@sanity/ui": "^2.16.4",
|
|
61
61
|
"@sanity/util": "^3.98.1",
|
|
62
|
-
"generaltranslation": "^7.6.
|
|
62
|
+
"generaltranslation": "^7.6.3",
|
|
63
|
+
"jsonpath-plus": "^10.3.0",
|
|
64
|
+
"jsonpointer": "^5.0.1",
|
|
65
|
+
"lightningcss": "^1.30.1",
|
|
63
66
|
"sanity-naive-html-serializer": "^3.2.0"
|
|
64
67
|
},
|
|
65
68
|
"devDependencies": {
|
|
66
|
-
"lightningcss": "^1.30.1",
|
|
67
69
|
"@sanity/pkg-utils": "^8.1.6",
|
|
68
70
|
"@sanity/plugin-kit": "^4.0.19",
|
|
69
71
|
"@types/react": "^19.1.12",
|
package/src/adapter/core.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { GT } from 'generaltranslation';
|
|
2
2
|
import { libraryDefaultLocale } from 'generaltranslation/internal';
|
|
3
3
|
import type { Secrets } from '../types';
|
|
4
|
+
import type { TranslateDocumentFilter, IgnoreFields } from './types';
|
|
5
|
+
import { SECRETS_NAMESPACE } from '../utils/shared';
|
|
4
6
|
|
|
5
7
|
export const gt = new GT();
|
|
6
8
|
|
|
@@ -12,33 +14,96 @@ export function overrideConfig(secrets: Secrets | null) {
|
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export class GTConfig {
|
|
17
|
+
secretsNamespace: string;
|
|
18
|
+
languageField: string;
|
|
15
19
|
sourceLocale: string;
|
|
16
20
|
locales: string[];
|
|
21
|
+
singletons: string[];
|
|
22
|
+
singletonMapping: (sourceDocumentId: string, locale: string) => string;
|
|
23
|
+
ignoreFields: IgnoreFields[];
|
|
24
|
+
translateDocuments: TranslateDocumentFilter[];
|
|
17
25
|
private static instance: GTConfig;
|
|
18
|
-
constructor(
|
|
26
|
+
constructor(
|
|
27
|
+
secretsNamespace: string,
|
|
28
|
+
languageField: string,
|
|
29
|
+
sourceLocale: string,
|
|
30
|
+
locales: string[],
|
|
31
|
+
singletons: string[],
|
|
32
|
+
singletonMapping: (sourceDocumentId: string, locale: string) => string,
|
|
33
|
+
ignoreFields: IgnoreFields[],
|
|
34
|
+
translateDocuments: TranslateDocumentFilter[]
|
|
35
|
+
) {
|
|
36
|
+
this.secretsNamespace = secretsNamespace;
|
|
37
|
+
this.languageField = languageField;
|
|
19
38
|
this.sourceLocale = sourceLocale;
|
|
20
39
|
this.locales = locales;
|
|
40
|
+
this.singletons = singletons;
|
|
41
|
+
this.singletonMapping = singletonMapping;
|
|
42
|
+
this.ignoreFields = ignoreFields;
|
|
43
|
+
this.translateDocuments = translateDocuments;
|
|
21
44
|
}
|
|
22
45
|
|
|
23
46
|
static getInstance() {
|
|
24
47
|
if (!this.instance) {
|
|
25
|
-
this.instance = new GTConfig(
|
|
48
|
+
this.instance = new GTConfig(
|
|
49
|
+
SECRETS_NAMESPACE,
|
|
50
|
+
'language',
|
|
51
|
+
gt.sourceLocale || libraryDefaultLocale,
|
|
52
|
+
[],
|
|
53
|
+
[],
|
|
54
|
+
() => '',
|
|
55
|
+
[],
|
|
56
|
+
[]
|
|
57
|
+
);
|
|
26
58
|
}
|
|
27
59
|
return this.instance;
|
|
28
60
|
}
|
|
29
61
|
|
|
30
|
-
|
|
62
|
+
init(
|
|
63
|
+
secretsNamespace: string,
|
|
64
|
+
languageField: string,
|
|
65
|
+
sourceLocale: string,
|
|
66
|
+
locales: string[],
|
|
67
|
+
singletons: string[],
|
|
68
|
+
singletonMapping: (sourceDocumentId: string, locale: string) => string,
|
|
69
|
+
ignoreFields: IgnoreFields[],
|
|
70
|
+
translateDocuments: TranslateDocumentFilter[]
|
|
71
|
+
) {
|
|
72
|
+
this.secretsNamespace = secretsNamespace;
|
|
73
|
+
this.languageField = languageField;
|
|
31
74
|
this.sourceLocale = sourceLocale;
|
|
75
|
+
this.locales = locales;
|
|
76
|
+
this.singletons = singletons;
|
|
77
|
+
this.singletonMapping = singletonMapping;
|
|
78
|
+
this.ignoreFields = ignoreFields;
|
|
79
|
+
this.translateDocuments = translateDocuments;
|
|
32
80
|
}
|
|
33
|
-
|
|
34
|
-
|
|
81
|
+
|
|
82
|
+
getSecretsNamespace() {
|
|
83
|
+
return this.secretsNamespace;
|
|
35
84
|
}
|
|
36
85
|
|
|
37
|
-
|
|
38
|
-
this.
|
|
86
|
+
getLanguageField() {
|
|
87
|
+
return this.languageField;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
getSourceLocale() {
|
|
91
|
+
return this.sourceLocale;
|
|
39
92
|
}
|
|
40
93
|
getLocales() {
|
|
41
94
|
return this.locales;
|
|
42
95
|
}
|
|
96
|
+
getSingletons() {
|
|
97
|
+
return this.singletons;
|
|
98
|
+
}
|
|
99
|
+
getSingletonMapping() {
|
|
100
|
+
return this.singletonMapping;
|
|
101
|
+
}
|
|
102
|
+
getIgnoreFields() {
|
|
103
|
+
return this.ignoreFields;
|
|
104
|
+
}
|
|
105
|
+
getTranslateDocuments() {
|
|
106
|
+
return this.translateDocuments;
|
|
107
|
+
}
|
|
43
108
|
}
|
|
44
109
|
export const gtConfig = GTConfig.getInstance();
|
|
@@ -13,7 +13,7 @@ export const createTask: Adapter['createTask'] = async (
|
|
|
13
13
|
workflowUid?: string,
|
|
14
14
|
callbackUrl?: string
|
|
15
15
|
) => {
|
|
16
|
-
const fileName = `sanity
|
|
16
|
+
const fileName = `sanity/${documentInfo.documentId}`;
|
|
17
17
|
overrideConfig(secrets);
|
|
18
18
|
const uploadResult = await gt.uploadSourceFiles(
|
|
19
19
|
[
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// adapted from https://github.com/sanity-io/sanity-translations-tab. See LICENSE.md for more details.
|
|
2
|
+
|
|
1
3
|
import { useCallback, useState } from 'react';
|
|
2
4
|
import { Flex, Card, Text, Grid, Box, Button } from '@sanity/ui';
|
|
3
5
|
import { DownloadIcon, CheckmarkCircleIcon } from '@sanity/icons';
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
// adapted from https://github.com/sanity-io/sanity-translations-tab. See LICENSE.md for more details.
|
|
2
|
+
|
|
1
3
|
import React from 'react';
|
|
4
|
+
import { SanityDocument } from 'sanity';
|
|
2
5
|
import { GTSerializedDocument } from '../types';
|
|
3
6
|
import { Adapter, GTFile, Secrets, WorkflowIdentifiers } from '../types';
|
|
4
7
|
|
|
5
8
|
export type ContextProps = {
|
|
6
9
|
documentInfo: GTFile;
|
|
10
|
+
document: SanityDocument;
|
|
11
|
+
languageField: string;
|
|
7
12
|
adapter: Adapter;
|
|
8
13
|
importTranslation: (languageId: string, document: string) => Promise<void>;
|
|
9
14
|
exportForTranslation: (documentInfo: GTFile) => Promise<GTSerializedDocument>;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
// adapted from https://github.com/sanity-io/sanity-translations-tab. See LICENSE.md for more details.
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Add cleanup function to cancel async tasks
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
|
-
import { useCallback, useContext, useEffect, useState } from 'react';
|
|
6
|
-
import { Stack, useToast } from '@sanity/ui';
|
|
7
|
+
import { useCallback, useContext, useEffect, useState, useMemo } from 'react';
|
|
8
|
+
import { Stack, useToast, Text, Card } from '@sanity/ui';
|
|
7
9
|
import { TranslationContext } from './TranslationContext';
|
|
10
|
+
import { gtConfig } from '../adapter/core';
|
|
8
11
|
|
|
9
12
|
import { NewTask } from './NewTask';
|
|
10
13
|
import { TaskView } from './TaskView';
|
|
@@ -17,6 +20,23 @@ export const TranslationView = () => {
|
|
|
17
20
|
const context = useContext(TranslationContext);
|
|
18
21
|
const toast = useToast();
|
|
19
22
|
|
|
23
|
+
// Extract the current document's language from the language field
|
|
24
|
+
const currentDocumentLanguage = useMemo(() => {
|
|
25
|
+
if (!context?.document || !context?.languageField) return null;
|
|
26
|
+
|
|
27
|
+
// Get the language from the document's language field
|
|
28
|
+
const documentLanguage = context.document[context.languageField];
|
|
29
|
+
|
|
30
|
+
// If no language field is set, assume it's the source language
|
|
31
|
+
return documentLanguage || gtConfig.getSourceLocale();
|
|
32
|
+
}, [context?.document, context?.languageField]);
|
|
33
|
+
|
|
34
|
+
// Only show translation components if we're on a source language document
|
|
35
|
+
const shouldShowTranslationComponents = useMemo(() => {
|
|
36
|
+
if (!currentDocumentLanguage) return false;
|
|
37
|
+
return currentDocumentLanguage === gtConfig.getSourceLocale();
|
|
38
|
+
}, [currentDocumentLanguage]);
|
|
39
|
+
|
|
20
40
|
useEffect(() => {
|
|
21
41
|
async function fetchData() {
|
|
22
42
|
if (!context) {
|
|
@@ -71,6 +91,18 @@ export const TranslationView = () => {
|
|
|
71
91
|
}
|
|
72
92
|
}, [context, setTask]);
|
|
73
93
|
|
|
94
|
+
// Show message if we're not on a source language document
|
|
95
|
+
if (!shouldShowTranslationComponents) {
|
|
96
|
+
return (
|
|
97
|
+
<Card padding={4} tone='neutral' border>
|
|
98
|
+
<Text size={1} muted>
|
|
99
|
+
Translation tools are only available for{' '}
|
|
100
|
+
<code>{gtConfig.getSourceLocale()}</code> documents.
|
|
101
|
+
</Text>
|
|
102
|
+
</Card>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
74
106
|
return (
|
|
75
107
|
<Stack space={6}>
|
|
76
108
|
<NewTask locales={locales} refreshTask={refreshTask} />
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// adapted from https://github.com/sanity-io/sanity-translations-tab. See LICENSE.md for more details.
|
|
2
|
+
|
|
1
3
|
import { useMemo } from 'react';
|
|
2
4
|
import { SanityDocument, useSchema } from 'sanity';
|
|
3
5
|
import { randomKey } from '@sanity/util/content';
|
|
@@ -154,6 +156,8 @@ const TranslationTab = (props: TranslationTabProps) => {
|
|
|
154
156
|
<TranslationContext.Provider
|
|
155
157
|
value={{
|
|
156
158
|
documentInfo: { documentId, versionId: revisionId },
|
|
159
|
+
document: displayed,
|
|
160
|
+
languageField: props.options.languageField || 'language',
|
|
157
161
|
secrets,
|
|
158
162
|
importTranslation,
|
|
159
163
|
exportForTranslation,
|