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/LICENSE.md
CHANGED
|
@@ -106,14 +106,7 @@ specific language governing permissions and limitations under the License.
|
|
|
106
106
|
|
|
107
107
|
## Additional Code
|
|
108
108
|
|
|
109
|
-
The
|
|
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/\*\*
|
|
109
|
+
The some portions of the Software are adapted from https://github.com/sanity-io/sanity-translations-tab. These portions are licensed under the license of the original software, listed below.
|
|
117
110
|
|
|
118
111
|
MIT License
|
|
119
112
|
|
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# gt-sanity
|
|
2
2
|
|
|
3
3
|
> This is a **Sanity Studio v3** plugin.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
npm install
|
|
8
|
+
npm install gt-sanity
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
Then, create a [GT project](https://generaltranslation.com/dashboard) and get a production API key and project ID.
|
|
@@ -49,7 +49,7 @@ Add it as a plugin in `sanity.config.ts` (or .js):
|
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
51
|
import { defineConfig } from 'sanity';
|
|
52
|
-
import { gtPlugin } from '
|
|
52
|
+
import { gtPlugin } from 'gt-sanity';
|
|
53
53
|
|
|
54
54
|
export default defineConfig({
|
|
55
55
|
//...
|
|
@@ -68,8 +68,8 @@ Add the Translation View to your document structure:
|
|
|
68
68
|
```ts
|
|
69
69
|
// ./structure.ts
|
|
70
70
|
import type { DefaultDocumentNodeResolver } from 'sanity/structure';
|
|
71
|
-
import { TranslationsTab } from '
|
|
72
|
-
import { defaultDocumentLevelConfig } from '
|
|
71
|
+
import { TranslationsTab } from 'gt-sanity';
|
|
72
|
+
import { defaultDocumentLevelConfig } from 'gt-sanity';
|
|
73
73
|
export const defaultDocumentNode: DefaultDocumentNodeResolver = (
|
|
74
74
|
S,
|
|
75
75
|
{ schemaType }
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BaseDocumentDeserializer } from 'sanity-naive-html-serializer';
|
|
2
2
|
import { BaseDocumentMerger } from 'sanity-naive-html-serializer';
|
|
3
3
|
import { BaseDocumentSerializer } from 'sanity-naive-html-serializer';
|
|
4
|
-
import { CustomMapping } from 'generaltranslation/types';
|
|
5
4
|
import { customSerializers } from 'sanity-naive-html-serializer';
|
|
6
5
|
import { defaultStopTypes } from 'sanity-naive-html-serializer';
|
|
7
6
|
import { DeserializerRule } from '@sanity/block-tools';
|
|
7
|
+
import { GT } from 'generaltranslation';
|
|
8
8
|
import { JSX } from 'react';
|
|
9
9
|
import { Plugin as Plugin_2 } from 'sanity';
|
|
10
10
|
import { PortableTextTypeComponent } from '@portabletext/to-html';
|
|
@@ -70,7 +70,8 @@ export declare const documentLevelPatch: (
|
|
|
70
70
|
localeId: string,
|
|
71
71
|
client: SanityClient,
|
|
72
72
|
languageField?: string,
|
|
73
|
-
mergeWithTargetLocale?: boolean
|
|
73
|
+
mergeWithTargetLocale?: boolean,
|
|
74
|
+
publish?: boolean
|
|
74
75
|
) => Promise<void>;
|
|
75
76
|
|
|
76
77
|
export declare type ExportForTranslation = (
|
|
@@ -99,6 +100,8 @@ export declare const findLatestDraft: (
|
|
|
99
100
|
client: SanityClient
|
|
100
101
|
) => Promise<SanityDocument>;
|
|
101
102
|
|
|
103
|
+
declare const gt: GT;
|
|
104
|
+
|
|
102
105
|
export declare const GTAdapter: Adapter;
|
|
103
106
|
|
|
104
107
|
declare type GTFile = {
|
|
@@ -111,7 +114,7 @@ declare type GTFile = {
|
|
|
111
114
|
*
|
|
112
115
|
* ```ts
|
|
113
116
|
* import {defineConfig} from 'sanity'
|
|
114
|
-
* import {gtPlugin} from '
|
|
117
|
+
* import {gtPlugin} from 'gt-sanity'
|
|
115
118
|
*
|
|
116
119
|
* export default defineConfig({
|
|
117
120
|
* // ...
|
|
@@ -119,26 +122,31 @@ declare type GTFile = {
|
|
|
119
122
|
* })
|
|
120
123
|
* ```
|
|
121
124
|
*/
|
|
122
|
-
export declare const gtPlugin: Plugin_2<
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
locales: string[];
|
|
137
|
-
}
|
|
138
|
-
>;
|
|
125
|
+
export declare const gtPlugin: Plugin_2<GTPluginConfig>;
|
|
126
|
+
|
|
127
|
+
export declare type GTPluginConfig = Omit<
|
|
128
|
+
Parameters<typeof gt.setConfig>[0],
|
|
129
|
+
'locales'
|
|
130
|
+
> & {
|
|
131
|
+
locales: string[];
|
|
132
|
+
singletons?: string[];
|
|
133
|
+
singletonMapping?: (sourceDocumentId: string, locale: string) => string;
|
|
134
|
+
ignoreFields?: IgnoreFields[];
|
|
135
|
+
languageField?: string;
|
|
136
|
+
translateDocuments?: TranslateDocumentFilter[];
|
|
137
|
+
secretsNamespace?: string;
|
|
138
|
+
};
|
|
139
139
|
|
|
140
140
|
declare type GTSerializedDocument = Omit<SerializedDocument, 'name'> & GTFile;
|
|
141
141
|
|
|
142
|
+
declare type IgnoreFields = {
|
|
143
|
+
documentId?: string;
|
|
144
|
+
fields?: {
|
|
145
|
+
property: string;
|
|
146
|
+
type?: string;
|
|
147
|
+
}[];
|
|
148
|
+
};
|
|
149
|
+
|
|
142
150
|
export declare type ImportTranslation = (
|
|
143
151
|
documentInfo: GTFile,
|
|
144
152
|
localeId: string,
|
|
@@ -152,16 +160,8 @@ export declare type ImportTranslation = (
|
|
|
152
160
|
additionalBlockDeserializers?: DeserializerRule[];
|
|
153
161
|
},
|
|
154
162
|
languageField?: string,
|
|
155
|
-
mergeWithTargetLocale?: boolean
|
|
156
|
-
|
|
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
|
|
163
|
+
mergeWithTargetLocale?: boolean,
|
|
164
|
+
publish?: boolean
|
|
165
165
|
) => Promise<void>;
|
|
166
166
|
|
|
167
167
|
export declare type Secrets = {
|
|
@@ -176,6 +176,11 @@ export declare type Secrets = {
|
|
|
176
176
|
|
|
177
177
|
export { SerializedDocument };
|
|
178
178
|
|
|
179
|
+
declare type TranslateDocumentFilter = {
|
|
180
|
+
documentId?: string;
|
|
181
|
+
type?: string;
|
|
182
|
+
};
|
|
183
|
+
|
|
179
184
|
export declare interface TranslationFunctionContext {
|
|
180
185
|
client: SanityClient;
|
|
181
186
|
schema: Schema;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BaseDocumentDeserializer } from 'sanity-naive-html-serializer';
|
|
2
2
|
import { BaseDocumentMerger } from 'sanity-naive-html-serializer';
|
|
3
3
|
import { BaseDocumentSerializer } from 'sanity-naive-html-serializer';
|
|
4
|
-
import { CustomMapping } from 'generaltranslation/types';
|
|
5
4
|
import { customSerializers } from 'sanity-naive-html-serializer';
|
|
6
5
|
import { defaultStopTypes } from 'sanity-naive-html-serializer';
|
|
7
6
|
import { DeserializerRule } from '@sanity/block-tools';
|
|
7
|
+
import { GT } from 'generaltranslation';
|
|
8
8
|
import { JSX } from 'react';
|
|
9
9
|
import { Plugin as Plugin_2 } from 'sanity';
|
|
10
10
|
import { PortableTextTypeComponent } from '@portabletext/to-html';
|
|
@@ -70,7 +70,8 @@ export declare const documentLevelPatch: (
|
|
|
70
70
|
localeId: string,
|
|
71
71
|
client: SanityClient,
|
|
72
72
|
languageField?: string,
|
|
73
|
-
mergeWithTargetLocale?: boolean
|
|
73
|
+
mergeWithTargetLocale?: boolean,
|
|
74
|
+
publish?: boolean
|
|
74
75
|
) => Promise<void>;
|
|
75
76
|
|
|
76
77
|
export declare type ExportForTranslation = (
|
|
@@ -99,6 +100,8 @@ export declare const findLatestDraft: (
|
|
|
99
100
|
client: SanityClient
|
|
100
101
|
) => Promise<SanityDocument>;
|
|
101
102
|
|
|
103
|
+
declare const gt: GT;
|
|
104
|
+
|
|
102
105
|
export declare const GTAdapter: Adapter;
|
|
103
106
|
|
|
104
107
|
declare type GTFile = {
|
|
@@ -111,7 +114,7 @@ declare type GTFile = {
|
|
|
111
114
|
*
|
|
112
115
|
* ```ts
|
|
113
116
|
* import {defineConfig} from 'sanity'
|
|
114
|
-
* import {gtPlugin} from '
|
|
117
|
+
* import {gtPlugin} from 'gt-sanity'
|
|
115
118
|
*
|
|
116
119
|
* export default defineConfig({
|
|
117
120
|
* // ...
|
|
@@ -119,26 +122,31 @@ declare type GTFile = {
|
|
|
119
122
|
* })
|
|
120
123
|
* ```
|
|
121
124
|
*/
|
|
122
|
-
export declare const gtPlugin: Plugin_2<
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
locales: string[];
|
|
137
|
-
}
|
|
138
|
-
>;
|
|
125
|
+
export declare const gtPlugin: Plugin_2<GTPluginConfig>;
|
|
126
|
+
|
|
127
|
+
export declare type GTPluginConfig = Omit<
|
|
128
|
+
Parameters<typeof gt.setConfig>[0],
|
|
129
|
+
'locales'
|
|
130
|
+
> & {
|
|
131
|
+
locales: string[];
|
|
132
|
+
singletons?: string[];
|
|
133
|
+
singletonMapping?: (sourceDocumentId: string, locale: string) => string;
|
|
134
|
+
ignoreFields?: IgnoreFields[];
|
|
135
|
+
languageField?: string;
|
|
136
|
+
translateDocuments?: TranslateDocumentFilter[];
|
|
137
|
+
secretsNamespace?: string;
|
|
138
|
+
};
|
|
139
139
|
|
|
140
140
|
declare type GTSerializedDocument = Omit<SerializedDocument, 'name'> & GTFile;
|
|
141
141
|
|
|
142
|
+
declare type IgnoreFields = {
|
|
143
|
+
documentId?: string;
|
|
144
|
+
fields?: {
|
|
145
|
+
property: string;
|
|
146
|
+
type?: string;
|
|
147
|
+
}[];
|
|
148
|
+
};
|
|
149
|
+
|
|
142
150
|
export declare type ImportTranslation = (
|
|
143
151
|
documentInfo: GTFile,
|
|
144
152
|
localeId: string,
|
|
@@ -152,16 +160,8 @@ export declare type ImportTranslation = (
|
|
|
152
160
|
additionalBlockDeserializers?: DeserializerRule[];
|
|
153
161
|
},
|
|
154
162
|
languageField?: string,
|
|
155
|
-
mergeWithTargetLocale?: boolean
|
|
156
|
-
|
|
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
|
|
163
|
+
mergeWithTargetLocale?: boolean,
|
|
164
|
+
publish?: boolean
|
|
165
165
|
) => Promise<void>;
|
|
166
166
|
|
|
167
167
|
export declare type Secrets = {
|
|
@@ -176,6 +176,11 @@ export declare type Secrets = {
|
|
|
176
176
|
|
|
177
177
|
export { SerializedDocument };
|
|
178
178
|
|
|
179
|
+
declare type TranslateDocumentFilter = {
|
|
180
|
+
documentId?: string;
|
|
181
|
+
type?: string;
|
|
182
|
+
};
|
|
183
|
+
|
|
179
184
|
export declare interface TranslationFunctionContext {
|
|
180
185
|
client: SanityClient;
|
|
181
186
|
schema: Schema;
|