@smartcat/sanity-plugin 1.0.0 → 1.1.0
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 +294 -0
- package/dist/_chunks-cjs/constants.cjs +13 -0
- package/dist/_chunks-cjs/constants.cjs.map +1 -0
- package/dist/_chunks-cjs/index.cjs +174 -0
- package/dist/_chunks-cjs/index.cjs.map +1 -0
- package/dist/_chunks-cjs/index2.cjs +338 -0
- package/dist/_chunks-cjs/index2.cjs.map +1 -0
- package/dist/_chunks-cjs/workflow.cjs +16 -0
- package/dist/_chunks-cjs/workflow.cjs.map +1 -0
- package/dist/_chunks-es/constants.js +14 -0
- package/dist/_chunks-es/constants.js.map +1 -0
- package/dist/_chunks-es/index.js +175 -0
- package/dist/_chunks-es/index.js.map +1 -0
- package/dist/_chunks-es/index2.js +340 -0
- package/dist/_chunks-es/index2.js.map +1 -0
- package/dist/_chunks-es/workflow.js +17 -0
- package/dist/_chunks-es/workflow.js.map +1 -0
- package/dist/export.cjs +160 -0
- package/dist/export.cjs.map +1 -0
- package/dist/export.d.cts +162 -0
- package/dist/export.d.ts +162 -0
- package/dist/export.js +162 -0
- package/dist/export.js.map +1 -0
- package/dist/import.cjs +169 -0
- package/dist/import.cjs.map +1 -0
- package/dist/import.d.cts +155 -0
- package/dist/import.d.ts +155 -0
- package/dist/import.js +169 -0
- package/dist/import.js.map +1 -0
- package/dist/index.cjs +2172 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +122 -0
- package/dist/index.d.ts +122 -0
- package/dist/index.js +2179 -0
- package/dist/index.js.map +1 -0
- package/dist/locjson.cjs +12 -0
- package/dist/locjson.cjs.map +1 -0
- package/dist/locjson.d.cts +291 -0
- package/dist/locjson.d.ts +291 -0
- package/dist/locjson.js +12 -0
- package/dist/locjson.js.map +1 -0
- package/dist/progress.cjs +16 -0
- package/dist/progress.cjs.map +1 -0
- package/dist/progress.d.cts +277 -0
- package/dist/progress.d.ts +277 -0
- package/dist/progress.js +16 -0
- package/dist/progress.js.map +1 -0
- package/dist/smartcat.cjs +287 -0
- package/dist/smartcat.cjs.map +1 -0
- package/dist/smartcat.d.cts +234 -0
- package/dist/smartcat.d.ts +234 -0
- package/dist/smartcat.js +287 -0
- package/dist/smartcat.js.map +1 -0
- package/dist/templates.cjs +12 -0
- package/dist/templates.cjs.map +1 -0
- package/dist/templates.d.cts +52 -0
- package/dist/templates.d.ts +52 -0
- package/dist/templates.js +12 -0
- package/dist/templates.js.map +1 -0
- package/package.json +101 -15
- package/src/actions/AddToProjectAction.tsx +274 -0
- package/src/export/export.test.ts +537 -0
- package/src/export/index.ts +393 -0
- package/src/form/TranslationStatusInput.tsx +212 -0
- package/src/import/import.test.ts +346 -0
- package/src/import/index.ts +418 -0
- package/src/index.ts +63 -0
- package/src/lib/constants.ts +23 -0
- package/src/lib/documentTitle.test.ts +43 -0
- package/src/lib/documentTitle.ts +30 -0
- package/src/lib/languageMap.test.ts +56 -0
- package/src/lib/languageMap.ts +71 -0
- package/src/lib/linkedDocuments.test.ts +56 -0
- package/src/lib/linkedDocuments.ts +100 -0
- package/src/lib/locjson/deserialize.ts +60 -0
- package/src/lib/locjson/fields.ts +355 -0
- package/src/lib/locjson/filename.ts +34 -0
- package/src/lib/locjson/index.ts +10 -0
- package/src/lib/locjson/locjson.test.ts +615 -0
- package/src/lib/locjson/paths.test.ts +41 -0
- package/src/lib/locjson/paths.ts +73 -0
- package/src/lib/locjson/portableText.ts +157 -0
- package/src/lib/locjson/serialize.ts +124 -0
- package/src/lib/locjson/types.ts +106 -0
- package/src/lib/log.ts +33 -0
- package/src/lib/projectItems.ts +31 -0
- package/src/lib/resolveConfig.test.ts +62 -0
- package/src/lib/resolveConfig.ts +54 -0
- package/src/lib/workflow.test.ts +37 -0
- package/src/lib/workflow.ts +48 -0
- package/src/lib/zip.fixtures.ts +75 -0
- package/src/lib/zip.test.ts +110 -0
- package/src/lib/zip.ts +164 -0
- package/src/progress/core.ts +409 -0
- package/src/progress/index.ts +7 -0
- package/src/progress/progress.test.ts +290 -0
- package/src/schema/settings.ts +55 -0
- package/src/schema/translatableOptions.ts +25 -0
- package/src/schema/translationProject.ts +268 -0
- package/src/smartcat/client.test.ts +222 -0
- package/src/smartcat/client.ts +351 -0
- package/src/smartcat/index.ts +10 -0
- package/src/smartcat/types.ts +99 -0
- package/src/templates/core.ts +55 -0
- package/src/templates/index.ts +5 -0
- package/src/templates/templates.test.ts +50 -0
- package/src/tool/Dashboard.tsx +46 -0
- package/src/tool/ItemProgress.tsx +176 -0
- package/src/tool/LogPanel.tsx +207 -0
- package/src/tool/ProjectView.tsx +1004 -0
- package/src/tool/ProjectsView.tsx +208 -0
- package/src/tool/StatusBadge.tsx +33 -0
- package/src/tool/StudioInit.tsx +42 -0
- package/src/tool/WorkflowSelect.tsx +41 -0
- package/src/tool/data.ts +86 -0
- package/src/tool/index.ts +19 -0
- package/src/tool/processing.test.ts +698 -0
- package/src/tool/processing.ts +839 -0
- package/src/tool/useTemplates.ts +84 -0
- package/src/tool/useWorkflowSelection.ts +65 -0
- package/src/types.ts +77 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Plugin as Plugin_2 } from "sanity";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A language an installation can translate into.
|
|
5
|
+
* `id` is the locale tag used in Sanity (and document-internationalization).
|
|
6
|
+
* `smartcatLanguage` is the code Smartcat expects; set it only when the Sanity
|
|
7
|
+
* tag differs from Smartcat's (e.g. id "PL-PL" → smartcatLanguage "pl"). Defaults to `id`.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare interface SmartcatLanguage {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
smartcatLanguage?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Plugin configuration, supplied by the consuming Studio.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare interface SmartcatPluginConfig {
|
|
23
|
+
/**
|
|
24
|
+
* Document types the "Add to translation project" action and status line
|
|
25
|
+
* appear on. Omit to allow every document type (except the plugin's own
|
|
26
|
+
* `smartcat.*` types). This affects the Studio UI only — not which linked
|
|
27
|
+
* documents get pulled into a project (see `rootTypes`).
|
|
28
|
+
*/
|
|
29
|
+
translatableTypes?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Root/standalone document types — the "include linked documents" crawl stops
|
|
32
|
+
* when it reaches one (they're translated on their own, as peers). Omit to
|
|
33
|
+
* inherit the explicitly-configured `translatableTypes`, or `[]` if that is
|
|
34
|
+
* also omitted (i.e. no boundary: pull in every transitively-linked
|
|
35
|
+
* translatable document).
|
|
36
|
+
*/
|
|
37
|
+
rootTypes?: string[];
|
|
38
|
+
/**
|
|
39
|
+
* Source language tag for new projects. Required.
|
|
40
|
+
*/
|
|
41
|
+
sourceLanguage: string;
|
|
42
|
+
/**
|
|
43
|
+
* Languages content can be translated into. Used to populate
|
|
44
|
+
* a project's target languages. Optional at this phase.
|
|
45
|
+
*/
|
|
46
|
+
languages?: SmartcatLanguage[];
|
|
47
|
+
/**
|
|
48
|
+
* Field name `@sanity/document-internationalization` stores each document's
|
|
49
|
+
* locale in. Must match that plugin's `languageField` setting. Defaults to
|
|
50
|
+
* `'language'`.
|
|
51
|
+
*/
|
|
52
|
+
documentI18nPluginLanguageField?: string;
|
|
53
|
+
/**
|
|
54
|
+
* How `sanity-plugin-internationalized-array` identifies the locale within an
|
|
55
|
+
* array field's members. `'language'` (default) for v5+; set to `'_key'` to
|
|
56
|
+
* support v4.x and lower, which keyed members by the language code.
|
|
57
|
+
*/
|
|
58
|
+
fieldI18nPluginLanguageField?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Smartcat translation plugin for Sanity Studio.
|
|
63
|
+
*
|
|
64
|
+
* - Adds a `smartcat.translationProject` document type (a named set of items).
|
|
65
|
+
* - Adds an "Add to translation project" document action on the configured
|
|
66
|
+
* `translatableTypes`.
|
|
67
|
+
* - Shows a status line on those types when the document belongs to one or more
|
|
68
|
+
* translation projects.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export declare const smartcatTranslation: Plugin_2<SmartcatPluginConfig>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Schema option this plugin adds, mirroring how `@sanity/document-internationalization`
|
|
76
|
+
* contributes `options.documentInternationalization.exclude`.
|
|
77
|
+
*
|
|
78
|
+
* Set it on a field — or once on a custom type — to force translation of a type
|
|
79
|
+
* the default allowlist (`string`/`text`/Portable Text) would otherwise skip,
|
|
80
|
+
* e.g. a custom string alias. The kind is derived from the resolved `jsonType`.
|
|
81
|
+
*/
|
|
82
|
+
export declare interface SmartcatTranslationSchemaOptions {
|
|
83
|
+
smartcatTranslation?: {
|
|
84
|
+
/**
|
|
85
|
+
* Force this field/type into translation even when its base type isn't in the
|
|
86
|
+
* default allowlist. Overrides a `documentInternationalization.exclude` on the
|
|
87
|
+
* same field. Ignored if the type has no translatable representation.
|
|
88
|
+
*/
|
|
89
|
+
include?: boolean;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Document type for a translation project (a named set of items to translate).
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export declare const TRANSLATION_PROJECT_TYPE = "smartcat.translationProject";
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Lifecycle of a translation project. Drives the export/import Functions.
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export declare type TranslationProjectStatus =
|
|
106
|
+
| "draft"
|
|
107
|
+
| "queued"
|
|
108
|
+
| "sent"
|
|
109
|
+
| "translating"
|
|
110
|
+
| "importing"
|
|
111
|
+
| "downloaded"
|
|
112
|
+
| "completed"
|
|
113
|
+
| "error";
|
|
114
|
+
|
|
115
|
+
export {};
|
|
116
|
+
|
|
117
|
+
declare module "sanity" {
|
|
118
|
+
interface StringOptions extends SmartcatTranslationSchemaOptions {}
|
|
119
|
+
interface TextOptions extends SmartcatTranslationSchemaOptions {}
|
|
120
|
+
interface ArrayOptions extends SmartcatTranslationSchemaOptions {}
|
|
121
|
+
interface ObjectOptions extends SmartcatTranslationSchemaOptions {}
|
|
122
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Plugin as Plugin_2 } from "sanity";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A language an installation can translate into.
|
|
5
|
+
* `id` is the locale tag used in Sanity (and document-internationalization).
|
|
6
|
+
* `smartcatLanguage` is the code Smartcat expects; set it only when the Sanity
|
|
7
|
+
* tag differs from Smartcat's (e.g. id "PL-PL" → smartcatLanguage "pl"). Defaults to `id`.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare interface SmartcatLanguage {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
smartcatLanguage?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Plugin configuration, supplied by the consuming Studio.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare interface SmartcatPluginConfig {
|
|
23
|
+
/**
|
|
24
|
+
* Document types the "Add to translation project" action and status line
|
|
25
|
+
* appear on. Omit to allow every document type (except the plugin's own
|
|
26
|
+
* `smartcat.*` types). This affects the Studio UI only — not which linked
|
|
27
|
+
* documents get pulled into a project (see `rootTypes`).
|
|
28
|
+
*/
|
|
29
|
+
translatableTypes?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Root/standalone document types — the "include linked documents" crawl stops
|
|
32
|
+
* when it reaches one (they're translated on their own, as peers). Omit to
|
|
33
|
+
* inherit the explicitly-configured `translatableTypes`, or `[]` if that is
|
|
34
|
+
* also omitted (i.e. no boundary: pull in every transitively-linked
|
|
35
|
+
* translatable document).
|
|
36
|
+
*/
|
|
37
|
+
rootTypes?: string[];
|
|
38
|
+
/**
|
|
39
|
+
* Source language tag for new projects. Required.
|
|
40
|
+
*/
|
|
41
|
+
sourceLanguage: string;
|
|
42
|
+
/**
|
|
43
|
+
* Languages content can be translated into. Used to populate
|
|
44
|
+
* a project's target languages. Optional at this phase.
|
|
45
|
+
*/
|
|
46
|
+
languages?: SmartcatLanguage[];
|
|
47
|
+
/**
|
|
48
|
+
* Field name `@sanity/document-internationalization` stores each document's
|
|
49
|
+
* locale in. Must match that plugin's `languageField` setting. Defaults to
|
|
50
|
+
* `'language'`.
|
|
51
|
+
*/
|
|
52
|
+
documentI18nPluginLanguageField?: string;
|
|
53
|
+
/**
|
|
54
|
+
* How `sanity-plugin-internationalized-array` identifies the locale within an
|
|
55
|
+
* array field's members. `'language'` (default) for v5+; set to `'_key'` to
|
|
56
|
+
* support v4.x and lower, which keyed members by the language code.
|
|
57
|
+
*/
|
|
58
|
+
fieldI18nPluginLanguageField?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Smartcat translation plugin for Sanity Studio.
|
|
63
|
+
*
|
|
64
|
+
* - Adds a `smartcat.translationProject` document type (a named set of items).
|
|
65
|
+
* - Adds an "Add to translation project" document action on the configured
|
|
66
|
+
* `translatableTypes`.
|
|
67
|
+
* - Shows a status line on those types when the document belongs to one or more
|
|
68
|
+
* translation projects.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export declare const smartcatTranslation: Plugin_2<SmartcatPluginConfig>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Schema option this plugin adds, mirroring how `@sanity/document-internationalization`
|
|
76
|
+
* contributes `options.documentInternationalization.exclude`.
|
|
77
|
+
*
|
|
78
|
+
* Set it on a field — or once on a custom type — to force translation of a type
|
|
79
|
+
* the default allowlist (`string`/`text`/Portable Text) would otherwise skip,
|
|
80
|
+
* e.g. a custom string alias. The kind is derived from the resolved `jsonType`.
|
|
81
|
+
*/
|
|
82
|
+
export declare interface SmartcatTranslationSchemaOptions {
|
|
83
|
+
smartcatTranslation?: {
|
|
84
|
+
/**
|
|
85
|
+
* Force this field/type into translation even when its base type isn't in the
|
|
86
|
+
* default allowlist. Overrides a `documentInternationalization.exclude` on the
|
|
87
|
+
* same field. Ignored if the type has no translatable representation.
|
|
88
|
+
*/
|
|
89
|
+
include?: boolean;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Document type for a translation project (a named set of items to translate).
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export declare const TRANSLATION_PROJECT_TYPE = "smartcat.translationProject";
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Lifecycle of a translation project. Drives the export/import Functions.
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export declare type TranslationProjectStatus =
|
|
106
|
+
| "draft"
|
|
107
|
+
| "queued"
|
|
108
|
+
| "sent"
|
|
109
|
+
| "translating"
|
|
110
|
+
| "importing"
|
|
111
|
+
| "downloaded"
|
|
112
|
+
| "completed"
|
|
113
|
+
| "error";
|
|
114
|
+
|
|
115
|
+
export {};
|
|
116
|
+
|
|
117
|
+
declare module "sanity" {
|
|
118
|
+
interface StringOptions extends SmartcatTranslationSchemaOptions {}
|
|
119
|
+
interface TextOptions extends SmartcatTranslationSchemaOptions {}
|
|
120
|
+
interface ArrayOptions extends SmartcatTranslationSchemaOptions {}
|
|
121
|
+
interface ObjectOptions extends SmartcatTranslationSchemaOptions {}
|
|
122
|
+
}
|