sanity-plugin-transifex 4.0.3 → 5.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 +49 -14
- package/dist/index.d.ts +13 -56
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +130 -147
- package/dist/index.js.map +1 -1
- package/package.json +33 -80
- package/dist/index.d.mts +0 -57
- package/dist/index.mjs +0 -183
- package/dist/index.mjs.map +0 -1
- package/sanity.json +0 -8
- package/src/index.ts +0 -60
- package/src/transifexAdapter/createTask.ts +0 -82
- package/src/transifexAdapter/getLocales.ts +0 -20
- package/src/transifexAdapter/getTranslation.ts +0 -90
- package/src/transifexAdapter/getTranslationTask.ts +0 -51
- package/src/transifexAdapter/helpers.ts +0 -11
- package/src/transifexAdapter/index.ts +0 -13
- package/v2-incompatible.js +0 -11
package/package.json
CHANGED
|
@@ -1,104 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-transifex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "This plugin provides an in-studio integration with Transifex. It allows your editors to send any document to Transifex with the click of a button, monitor ongoing translations, and import partial or complete translations back into the studio.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
7
7
|
"sanity-plugin"
|
|
8
8
|
],
|
|
9
|
-
"homepage": "https://github.com/sanity-io/sanity-plugin-transifex#readme",
|
|
9
|
+
"homepage": "https://github.com/sanity-io/plugins/tree/main/plugins/sanity-plugin-transifex#readme",
|
|
10
10
|
"bugs": {
|
|
11
|
-
"url": "https://github.com/sanity-io/
|
|
11
|
+
"url": "https://github.com/sanity-io/plugins/issues"
|
|
12
12
|
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
13
15
|
"repository": {
|
|
14
16
|
"type": "git",
|
|
15
|
-
"url": "git@github.com
|
|
16
|
-
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"author": "Sanity.io",
|
|
19
|
-
"exports": {
|
|
20
|
-
".": {
|
|
21
|
-
"source": "./src/index.ts",
|
|
22
|
-
"require": "./dist/index.js",
|
|
23
|
-
"import": "./dist/index.mjs",
|
|
24
|
-
"default": "./dist/index.js"
|
|
25
|
-
},
|
|
26
|
-
"./package.json": "./package.json"
|
|
17
|
+
"url": "git+ssh://git@github.com/sanity-io/plugins.git",
|
|
18
|
+
"directory": "plugins/sanity-plugin-transifex"
|
|
27
19
|
},
|
|
28
|
-
"type": "commonjs",
|
|
29
|
-
"main": "./dist/index.js",
|
|
30
|
-
"module": "./dist/index.mjs",
|
|
31
|
-
"types": "./dist/index.d.ts",
|
|
32
20
|
"files": [
|
|
33
|
-
"dist"
|
|
34
|
-
"sanity.json",
|
|
35
|
-
"src",
|
|
36
|
-
"v2-incompatible.js"
|
|
21
|
+
"dist"
|
|
37
22
|
],
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"clean": "rimraf dist",
|
|
44
|
-
"format": "prettier --write --cache --ignore-unknown .",
|
|
45
|
-
"link-watch": "plugin-kit link-watch",
|
|
46
|
-
"prepublishOnly": "npm run build",
|
|
47
|
-
"watch": "pkg-utils watch --strict"
|
|
23
|
+
"type": "module",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./dist/index.js",
|
|
27
|
+
"./package.json": "./package.json"
|
|
48
28
|
},
|
|
49
29
|
"dependencies": {
|
|
50
|
-
"
|
|
51
|
-
"sanity-translations-tab": "^5.0.0"
|
|
30
|
+
"sanity-translations-tab": "6.1.0"
|
|
52
31
|
},
|
|
53
32
|
"devDependencies": {
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"eslint-config-sanity": "^6.0.0",
|
|
66
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
67
|
-
"eslint-plugin-react": "^7.32.2",
|
|
68
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
69
|
-
"husky": "^8.0.3",
|
|
70
|
-
"lint-staged": "^13.1.2",
|
|
71
|
-
"npm-run-all": "^4.1.5",
|
|
72
|
-
"prettier": "^2.8.4",
|
|
73
|
-
"prettier-plugin-packagejson": "^2.4.3",
|
|
74
|
-
"react": "^18.3.0",
|
|
75
|
-
"react-dom": "^18.3.0",
|
|
76
|
-
"react-is": "^18.3.0",
|
|
77
|
-
"rimraf": "^4.1.2",
|
|
78
|
-
"sanity": "^3.98.1",
|
|
79
|
-
"semantic-release": "^20.1.0",
|
|
80
|
-
"size-limit": "^4.7.0",
|
|
81
|
-
"tslib": "^2.0.3",
|
|
82
|
-
"typescript": "5.8.3"
|
|
33
|
+
"@sanity/pkg-utils": "^10.5.0",
|
|
34
|
+
"@types/react": "^19.2.14",
|
|
35
|
+
"@types/react-dom": "^19.2.3",
|
|
36
|
+
"babel-plugin-react-compiler": "^1.0.0",
|
|
37
|
+
"babel-plugin-styled-components": "^2.3.0",
|
|
38
|
+
"react": "^19.2.5",
|
|
39
|
+
"react-dom": "^19.2.5",
|
|
40
|
+
"sanity": "^5.21.0",
|
|
41
|
+
"styled-components": "^6.4.2",
|
|
42
|
+
"@repo/package.config": "0.0.0",
|
|
43
|
+
"@repo/tsconfig": "0.0.0"
|
|
83
44
|
},
|
|
84
45
|
"peerDependencies": {
|
|
85
|
-
"react": "^
|
|
86
|
-
"react-dom": "^
|
|
87
|
-
"sanity": "^
|
|
46
|
+
"react": "^19.2",
|
|
47
|
+
"react-dom": "^19.2",
|
|
48
|
+
"sanity": "^5 || ^6.0.0-0",
|
|
49
|
+
"styled-components": "^6.1"
|
|
88
50
|
},
|
|
89
51
|
"engines": {
|
|
90
|
-
"node": ">=
|
|
91
|
-
},
|
|
92
|
-
"eslintConfig": {
|
|
93
|
-
"extends": "react-app",
|
|
94
|
-
"rules": {
|
|
95
|
-
"@typescript-eslint/no-redeclare": "off",
|
|
96
|
-
"no-redeclare": "off"
|
|
97
|
-
}
|
|
52
|
+
"node": ">=20.19 <22 || >=22.12"
|
|
98
53
|
},
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"tsconfig": false
|
|
102
|
-
}
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "pkg build --strict --check --clean"
|
|
103
56
|
}
|
|
104
|
-
}
|
|
57
|
+
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import {Adapter} from 'sanity-translations-tab'
|
|
2
|
-
import {BaseDocumentDeserializer} from 'sanity-translations-tab'
|
|
3
|
-
import {BaseDocumentMerger} from 'sanity-translations-tab'
|
|
4
|
-
import {BaseDocumentSerializer} from 'sanity-translations-tab'
|
|
5
|
-
import {customSerializers} from 'sanity-translations-tab'
|
|
6
|
-
import {defaultStopTypes} from 'sanity-translations-tab'
|
|
7
|
-
import {documentLevelPatch} from 'sanity-translations-tab'
|
|
8
|
-
import {fieldLevelPatch} from 'sanity-translations-tab'
|
|
9
|
-
import {findLatestDraft} from 'sanity-translations-tab'
|
|
10
|
-
import {legacyDocumentLevelPatch} from 'sanity-translations-tab'
|
|
11
|
-
import {TranslationFunctionContext} from 'sanity-translations-tab'
|
|
12
|
-
import {TranslationsTab} from 'sanity-translations-tab'
|
|
13
|
-
|
|
14
|
-
export {BaseDocumentDeserializer}
|
|
15
|
-
|
|
16
|
-
export {BaseDocumentMerger}
|
|
17
|
-
|
|
18
|
-
export {BaseDocumentSerializer}
|
|
19
|
-
|
|
20
|
-
declare interface ConfigOptions {
|
|
21
|
-
adapter: Adapter
|
|
22
|
-
secretsNamespace: string | null
|
|
23
|
-
exportForTranslation: (
|
|
24
|
-
id: string,
|
|
25
|
-
context: TranslationFunctionContext,
|
|
26
|
-
) => Promise<Record<string, any>>
|
|
27
|
-
importTranslation: (
|
|
28
|
-
id: string,
|
|
29
|
-
localeId: string,
|
|
30
|
-
doc: string,
|
|
31
|
-
context: TranslationFunctionContext,
|
|
32
|
-
) => Promise<void>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export {customSerializers}
|
|
36
|
-
|
|
37
|
-
export declare const defaultDocumentLevelConfig: ConfigOptions
|
|
38
|
-
|
|
39
|
-
export declare const defaultFieldLevelConfig: ConfigOptions
|
|
40
|
-
|
|
41
|
-
export {defaultStopTypes}
|
|
42
|
-
|
|
43
|
-
export {documentLevelPatch}
|
|
44
|
-
|
|
45
|
-
export {fieldLevelPatch}
|
|
46
|
-
|
|
47
|
-
export {findLatestDraft}
|
|
48
|
-
|
|
49
|
-
export declare const legacyDocumentLevelConfig: ConfigOptions
|
|
50
|
-
|
|
51
|
-
export {legacyDocumentLevelPatch}
|
|
52
|
-
|
|
53
|
-
export declare const TransifexAdapter: Adapter
|
|
54
|
-
|
|
55
|
-
export {TranslationsTab}
|
|
56
|
-
|
|
57
|
-
export {}
|
package/dist/index.mjs
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { baseDocumentLevelConfig, baseFieldLevelConfig, legacyDocumentLevelConfig as legacyDocumentLevelConfig$1 } from "sanity-translations-tab";
|
|
2
|
-
import { BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, TranslationsTab, customSerializers, defaultStopTypes, documentLevelPatch, fieldLevelPatch, findLatestDraft, legacyDocumentLevelPatch } from "sanity-translations-tab";
|
|
3
|
-
const baseTransifexUrl = "https://rest.api.transifex.com", getHeaders = (secrets) => ({
|
|
4
|
-
Authorization: `Bearer ${secrets?.token}`,
|
|
5
|
-
"Content-Type": "application/vnd.api+json"
|
|
6
|
-
}), projOrgSlug = (secrets) => `o:${secrets?.organization}:p:${secrets?.project}`, getLocales = async (secrets) => {
|
|
7
|
-
let locales = [];
|
|
8
|
-
return secrets && (locales = await fetch(`${baseTransifexUrl}/projects/${projOrgSlug(secrets)}/languages`, {
|
|
9
|
-
headers: getHeaders(secrets)
|
|
10
|
-
}).then((res) => res.json()).then(
|
|
11
|
-
(res) => res.data.map((lang) => ({
|
|
12
|
-
enabled: !0,
|
|
13
|
-
description: lang.attributes.name,
|
|
14
|
-
localeId: lang.attributes.code
|
|
15
|
-
}))
|
|
16
|
-
)), locales;
|
|
17
|
-
}, getTranslationTask = async (documentId, secrets) => {
|
|
18
|
-
if (!documentId || !secrets)
|
|
19
|
-
return {
|
|
20
|
-
taskId: documentId,
|
|
21
|
-
documentId,
|
|
22
|
-
locales: []
|
|
23
|
-
};
|
|
24
|
-
const projectFilter = `filter[project]=${projOrgSlug(secrets)}`, resourceFilter = `filter[resource]=${projOrgSlug(secrets)}:r:${documentId}`, task = await fetch(
|
|
25
|
-
`${baseTransifexUrl}/resource_language_stats?${projectFilter}&${resourceFilter}`,
|
|
26
|
-
{ headers: getHeaders(secrets) }
|
|
27
|
-
).then((res) => {
|
|
28
|
-
if (res.ok)
|
|
29
|
-
return res.json();
|
|
30
|
-
if (res.status === 404)
|
|
31
|
-
return { data: [] };
|
|
32
|
-
throw Error(`Failed to retrieve tasks from Transifex. Status: ${res.status}`);
|
|
33
|
-
}).then((res) => ({
|
|
34
|
-
taskId: `${projOrgSlug(secrets)}:r:${documentId}`,
|
|
35
|
-
documentId,
|
|
36
|
-
locales: res.data.map((locale) => ({
|
|
37
|
-
localeId: locale.relationships.language.data.id.split(":")[1],
|
|
38
|
-
progress: Math.floor(
|
|
39
|
-
100 * (locale.attributes.reviewed_strings / parseFloat(locale.attributes.total_strings))
|
|
40
|
-
)
|
|
41
|
-
}))
|
|
42
|
-
})), localeIds = (await getLocales(secrets)).map((l) => l.localeId), validLocales = task.locales.filter(
|
|
43
|
-
(locale) => localeIds.find((id) => id === locale.localeId)
|
|
44
|
-
);
|
|
45
|
-
return task.locales = validLocales, task;
|
|
46
|
-
}, pollForFileDownloadLocation = async (resourceDownloadUrl, translationDownloadId, headers) => {
|
|
47
|
-
const response = await fetch(`${resourceDownloadUrl}/${translationDownloadId}`, {
|
|
48
|
-
headers
|
|
49
|
-
});
|
|
50
|
-
return response.status === 500 ? (console.info(
|
|
51
|
-
`Transifex plugin message: Received 500 for translation download ID ${translationDownloadId}. Trying to reconnect...`
|
|
52
|
-
), await new Promise((resolve) => setTimeout(resolve, 3e3)), pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers)) : response.redirected ? (console.info(
|
|
53
|
-
`Transifex plugin message: Received redirect for translation download ID ${translationDownloadId}. Following redirect now for file download.`
|
|
54
|
-
), response.url) : response.status === 200 ? (console.info(
|
|
55
|
-
`Transifex plugin message: Requested download location for translation download ID ${translationDownloadId}. Location is still pending, trying again.`
|
|
56
|
-
), await new Promise((resolve) => setTimeout(resolve, 3e3)), pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers)) : (console.error(
|
|
57
|
-
`Transifex plugin message: Requested download location for translation download ID ${translationDownloadId} but received error code ${response.status}. Waiting and trying again.`
|
|
58
|
-
), await new Promise((resolve) => setTimeout(resolve, 3e3)), pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers));
|
|
59
|
-
}, handleFileDownload = (url) => fetch(url).then((res) => res.text()), getTranslation = async (taskId, localeId, secrets) => {
|
|
60
|
-
const resourceDownloadBody = {
|
|
61
|
-
data: {
|
|
62
|
-
attributes: {
|
|
63
|
-
content_encoding: "text"
|
|
64
|
-
},
|
|
65
|
-
relationships: {
|
|
66
|
-
language: {
|
|
67
|
-
data: {
|
|
68
|
-
id: `l:${localeId}`,
|
|
69
|
-
type: "languages"
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
resource: {
|
|
73
|
-
data: {
|
|
74
|
-
id: taskId,
|
|
75
|
-
type: "resources"
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
type: "resource_translations_async_downloads"
|
|
80
|
-
}
|
|
81
|
-
}, resourceDownloadUrl = `${baseTransifexUrl}/resource_translations_async_downloads`, translationDownloadId = await fetch(resourceDownloadUrl, {
|
|
82
|
-
headers: getHeaders(secrets),
|
|
83
|
-
method: "POST",
|
|
84
|
-
body: JSON.stringify(resourceDownloadBody)
|
|
85
|
-
}).then((res) => res.json()).then((res) => res.data.id), headers = getHeaders(secrets), location = await pollForFileDownloadLocation(
|
|
86
|
-
resourceDownloadUrl,
|
|
87
|
-
translationDownloadId,
|
|
88
|
-
headers
|
|
89
|
-
);
|
|
90
|
-
return handleFileDownload(location);
|
|
91
|
-
}, createResource = (doc, documentId, secrets) => {
|
|
92
|
-
const resourceCreateBody = {
|
|
93
|
-
data: {
|
|
94
|
-
attributes: {
|
|
95
|
-
accept_translations: !0,
|
|
96
|
-
name: doc.name,
|
|
97
|
-
slug: documentId
|
|
98
|
-
},
|
|
99
|
-
relationships: {
|
|
100
|
-
i18n_format: {
|
|
101
|
-
data: {
|
|
102
|
-
id: "HTML_FRAGMENT",
|
|
103
|
-
type: "i18n_formats"
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
project: {
|
|
107
|
-
data: {
|
|
108
|
-
id: projOrgSlug(secrets),
|
|
109
|
-
type: "projects"
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
type: "resources"
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
return fetch(`${baseTransifexUrl}/resources`, {
|
|
117
|
-
headers: getHeaders(secrets),
|
|
118
|
-
method: "POST",
|
|
119
|
-
body: JSON.stringify(resourceCreateBody)
|
|
120
|
-
}).then((res) => res.json()).then((res) => res.data.id);
|
|
121
|
-
}, createTask = async (documentId, document, localeIds, secrets) => {
|
|
122
|
-
let resourceId = await fetch(
|
|
123
|
-
`${baseTransifexUrl}/resources/${projOrgSlug(secrets)}:r:${documentId}`,
|
|
124
|
-
{ headers: getHeaders(secrets) }
|
|
125
|
-
).then((res) => res.json()).then((res) => res.data ? res.data.id : null);
|
|
126
|
-
resourceId || (resourceId = await createResource(document, documentId, secrets));
|
|
127
|
-
const resourceUploadUrl = `${baseTransifexUrl}/resource_strings_async_uploads`, resourceUploadBody = {
|
|
128
|
-
data: {
|
|
129
|
-
attributes: {
|
|
130
|
-
content: document.content,
|
|
131
|
-
content_encoding: "text"
|
|
132
|
-
},
|
|
133
|
-
relationships: {
|
|
134
|
-
resource: {
|
|
135
|
-
data: {
|
|
136
|
-
id: resourceId,
|
|
137
|
-
type: "resources"
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
type: "resource_strings_async_uploads"
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
return fetch(resourceUploadUrl, {
|
|
145
|
-
method: "POST",
|
|
146
|
-
body: JSON.stringify(resourceUploadBody),
|
|
147
|
-
headers: getHeaders(secrets)
|
|
148
|
-
}).then(() => getTranslationTask(documentId, secrets));
|
|
149
|
-
}, TransifexAdapter = {
|
|
150
|
-
getLocales,
|
|
151
|
-
getTranslationTask,
|
|
152
|
-
createTask,
|
|
153
|
-
getTranslation
|
|
154
|
-
}, defaultDocumentLevelConfig = {
|
|
155
|
-
...baseDocumentLevelConfig,
|
|
156
|
-
adapter: TransifexAdapter,
|
|
157
|
-
secretsNamespace: "transifex"
|
|
158
|
-
}, legacyDocumentLevelConfig = {
|
|
159
|
-
...legacyDocumentLevelConfig$1,
|
|
160
|
-
adapter: TransifexAdapter,
|
|
161
|
-
secretsNamespace: "transifex"
|
|
162
|
-
}, defaultFieldLevelConfig = {
|
|
163
|
-
...baseFieldLevelConfig,
|
|
164
|
-
adapter: TransifexAdapter,
|
|
165
|
-
secretsNamespace: "transifex"
|
|
166
|
-
};
|
|
167
|
-
export {
|
|
168
|
-
BaseDocumentDeserializer,
|
|
169
|
-
BaseDocumentMerger,
|
|
170
|
-
BaseDocumentSerializer,
|
|
171
|
-
TransifexAdapter,
|
|
172
|
-
TranslationsTab,
|
|
173
|
-
customSerializers,
|
|
174
|
-
defaultDocumentLevelConfig,
|
|
175
|
-
defaultFieldLevelConfig,
|
|
176
|
-
defaultStopTypes,
|
|
177
|
-
documentLevelPatch,
|
|
178
|
-
fieldLevelPatch,
|
|
179
|
-
findLatestDraft,
|
|
180
|
-
legacyDocumentLevelConfig,
|
|
181
|
-
legacyDocumentLevelPatch
|
|
182
|
-
};
|
|
183
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/transifexAdapter/helpers.ts","../src/transifexAdapter/getLocales.ts","../src/transifexAdapter/getTranslationTask.ts","../src/transifexAdapter/getTranslation.ts","../src/transifexAdapter/createTask.ts","../src/transifexAdapter/index.ts","../src/index.ts"],"sourcesContent":["import {Secrets} from 'sanity-translations-tab'\n\nexport const baseTransifexUrl = 'https://rest.api.transifex.com'\n\nexport const getHeaders = (secrets: Secrets | null): Record<string, string> => ({\n Authorization: `Bearer ${secrets?.token}`,\n 'Content-Type': 'application/vnd.api+json',\n})\n\nexport const projOrgSlug = (secrets: Secrets | null): string =>\n `o:${secrets?.organization}:p:${secrets?.project}`\n","import {Adapter, Secrets} from 'sanity-translations-tab'\nimport {baseTransifexUrl, projOrgSlug, getHeaders} from './helpers'\n\nexport const getLocales: Adapter['getLocales'] = async (secrets: Secrets | null) => {\n let locales = []\n if (secrets) {\n locales = await fetch(`${baseTransifexUrl}/projects/${projOrgSlug(secrets)}/languages`, {\n headers: getHeaders(secrets),\n })\n .then((res) => res.json())\n .then((res) =>\n res.data.map((lang: Record<string, any>) => ({\n enabled: true,\n description: lang.attributes.name,\n localeId: lang.attributes.code,\n }))\n )\n }\n return locales\n}\n","import {Adapter, Secrets} from 'sanity-translations-tab'\nimport {baseTransifexUrl, projOrgSlug, getHeaders} from './helpers'\nimport {getLocales} from './getLocales'\n\nexport const getTranslationTask: Adapter['getTranslationTask'] = async (\n documentId: string,\n secrets: Secrets | null\n) => {\n if (!documentId || !secrets) {\n return {\n taskId: documentId,\n documentId: documentId,\n locales: [],\n }\n }\n const projectFilter = `filter[project]=${projOrgSlug(secrets)}`\n const resourceFilter = `filter[resource]=${projOrgSlug(secrets)}:r:${documentId}`\n const task = await fetch(\n `${baseTransifexUrl}/resource_language_stats?${projectFilter}&${resourceFilter}`,\n {headers: getHeaders(secrets)}\n )\n .then((res) => {\n if (res.ok) {\n return res.json()\n }\n //normal -- just means that this task doesn't exist yet.\n else if (res.status === 404) {\n return {data: []}\n }\n throw Error(`Failed to retrieve tasks from Transifex. Status: ${res.status}`)\n })\n .then((res) => ({\n taskId: `${projOrgSlug(secrets)}:r:${documentId}`,\n documentId: documentId,\n locales: res.data.map((locale: Record<string, any>) => ({\n localeId: locale.relationships.language.data.id.split(':')[1],\n progress: Math.floor(\n 100 * (locale.attributes.reviewed_strings / parseFloat(locale.attributes.total_strings))\n ),\n })),\n }))\n\n const locales = await getLocales(secrets)\n const localeIds = locales.map((l: Record<string, any>) => l.localeId)\n const validLocales = task.locales.filter((locale: Record<string, any>) =>\n localeIds.find((id: string) => id === locale.localeId)\n )\n task.locales = validLocales\n\n return task\n}\n","import {Adapter, Secrets} from 'sanity-translations-tab'\nimport {baseTransifexUrl, getHeaders} from './helpers'\n\nconst pollForFileDownloadLocation = async (\n resourceDownloadUrl: string,\n translationDownloadId: string,\n headers: Record<string, any>\n): Promise<string> => {\n const response = await fetch(`${resourceDownloadUrl}/${translationDownloadId}`, {\n headers: headers,\n })\n\n if (response.status === 500) {\n //eslint-disable-next-line no-console -- this is for developer feedback/debugging\n console.info(\n `Transifex plugin message: Received 500 for translation download ID ${translationDownloadId}. Trying to reconnect...`\n )\n await new Promise((resolve) => setTimeout(resolve, 3000))\n return pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers)\n } else if (response.redirected) {\n //eslint-disable-next-line no-console -- this is for developer feedback/debugging\n console.info(\n `Transifex plugin message: Received redirect for translation download ID ${translationDownloadId}. Following redirect now for file download.`\n )\n return response.url\n } else if (response.status === 200) {\n //eslint-disable-next-line no-console -- this is for developer feedback/debugging\n console.info(\n `Transifex plugin message: Requested download location for translation download ID ${translationDownloadId}. Location is still pending, trying again.`\n )\n await new Promise((resolve) => setTimeout(resolve, 3000))\n return pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers)\n }\n //eslint-disable-next-line no-console -- this is for developer feedback/debugging\n console.error(\n `Transifex plugin message: Requested download location for translation download ID ${translationDownloadId} but received error code ${response.status}. Waiting and trying again.`\n )\n await new Promise((resolve) => setTimeout(resolve, 3000))\n return pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers)\n}\n\nconst handleFileDownload = (url: string) => {\n return fetch(url).then((res) => res.text())\n}\n\nexport const getTranslation: Adapter['getTranslation'] = async (\n taskId: string,\n localeId: string,\n secrets: Secrets | null\n) => {\n const resourceDownloadBody = {\n data: {\n attributes: {\n content_encoding: 'text',\n },\n relationships: {\n language: {\n data: {\n id: `l:${localeId}`,\n type: 'languages',\n },\n },\n resource: {\n data: {\n id: taskId,\n type: 'resources',\n },\n },\n },\n type: 'resource_translations_async_downloads',\n },\n }\n\n const resourceDownloadUrl = `${baseTransifexUrl}/resource_translations_async_downloads`\n const translationDownloadId = await fetch(resourceDownloadUrl, {\n headers: getHeaders(secrets),\n method: 'POST',\n body: JSON.stringify(resourceDownloadBody),\n })\n .then((res) => res.json())\n .then((res) => res.data.id)\n\n const headers = getHeaders(secrets)\n const location = await pollForFileDownloadLocation(\n resourceDownloadUrl,\n translationDownloadId,\n headers\n )\n return handleFileDownload(location)\n}\n","import {Adapter, Secrets} from 'sanity-translations-tab'\nimport {baseTransifexUrl, projOrgSlug, getHeaders} from './helpers'\nimport {getTranslationTask} from './getTranslationTask'\n\nconst createResource = (doc: Record<string, any>, documentId: string, secrets: Secrets | null) => {\n const resourceCreateBody = {\n data: {\n attributes: {\n accept_translations: true,\n name: doc.name,\n slug: documentId,\n },\n relationships: {\n i18n_format: {\n data: {\n id: 'HTML_FRAGMENT',\n type: 'i18n_formats',\n },\n },\n project: {\n data: {\n id: projOrgSlug(secrets),\n type: 'projects',\n },\n },\n },\n type: 'resources',\n },\n }\n\n return fetch(`${baseTransifexUrl}/resources`, {\n headers: getHeaders(secrets),\n method: 'POST',\n body: JSON.stringify(resourceCreateBody),\n })\n .then((res) => res.json())\n .then((res) => res.data.id)\n}\n\n//@ts-ignore until we resolve the TranslationTask return type\nexport const createTask: Adapter['createTask'] = async (\n documentId: string,\n document: Record<string, any>,\n localeIds: string[],\n secrets: Secrets | null\n) => {\n let resourceId = await fetch(\n `${baseTransifexUrl}/resources/${projOrgSlug(secrets)}:r:${documentId}`,\n {headers: getHeaders(secrets)}\n )\n .then((res) => res.json())\n .then((res) => (res.data ? res.data.id : null))\n\n if (!resourceId) {\n resourceId = await createResource(document, documentId, secrets)\n }\n\n const resourceUploadUrl = `${baseTransifexUrl}/resource_strings_async_uploads`\n const resourceUploadBody = {\n data: {\n attributes: {\n content: document.content,\n content_encoding: 'text',\n },\n relationships: {\n resource: {\n data: {\n id: resourceId,\n type: 'resources',\n },\n },\n },\n type: 'resource_strings_async_uploads',\n },\n }\n\n return fetch(resourceUploadUrl, {\n method: 'POST',\n body: JSON.stringify(resourceUploadBody),\n headers: getHeaders(secrets),\n }).then(() => getTranslationTask(documentId, secrets))\n}\n","import {Adapter} from 'sanity-translations-tab'\n\nimport {getLocales} from './getLocales'\nimport {getTranslationTask} from './getTranslationTask'\nimport {getTranslation} from './getTranslation'\nimport {createTask} from './createTask'\n\nexport const TransifexAdapter: Adapter = {\n getLocales,\n getTranslationTask,\n createTask,\n getTranslation,\n}\n","import {\n baseDocumentLevelConfig,\n legacyDocumentLevelConfig as baseLegacyDocumentLevelConfig,\n baseFieldLevelConfig,\n Adapter,\n TranslationFunctionContext,\n} from 'sanity-translations-tab'\nimport {TransifexAdapter} from './transifexAdapter'\n\nexport {\n findLatestDraft,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n legacyDocumentLevelPatch,\n documentLevelPatch,\n fieldLevelPatch,\n TranslationsTab,\n} from 'sanity-translations-tab'\n\ninterface ConfigOptions {\n adapter: Adapter\n secretsNamespace: string | null\n exportForTranslation: (\n id: string,\n context: TranslationFunctionContext\n ) => Promise<Record<string, any>>\n importTranslation: (\n id: string,\n localeId: string,\n doc: string,\n context: TranslationFunctionContext\n ) => Promise<void>\n}\nconst defaultDocumentLevelConfig: ConfigOptions = {\n ...baseDocumentLevelConfig,\n adapter: TransifexAdapter,\n secretsNamespace: 'transifex',\n}\n\nconst legacyDocumentLevelConfig: ConfigOptions = {\n ...baseLegacyDocumentLevelConfig,\n adapter: TransifexAdapter,\n secretsNamespace: 'transifex',\n}\n\nconst defaultFieldLevelConfig: ConfigOptions = {\n ...baseFieldLevelConfig,\n adapter: TransifexAdapter,\n secretsNamespace: 'transifex',\n}\n\nexport {\n TransifexAdapter,\n defaultDocumentLevelConfig,\n defaultFieldLevelConfig,\n legacyDocumentLevelConfig,\n}\n"],"names":["baseLegacyDocumentLevelConfig"],"mappings":";;AAEO,MAAM,mBAAmB,kCAEnB,aAAa,CAAC,aAAqD;AAAA,EAC9E,eAAe,UAAU,SAAS,KAAK;AAAA,EACvC,gBAAgB;AAClB,IAEa,cAAc,CAAC,YAC1B,KAAK,SAAS,YAAY,MAAM,SAAS,OAAO,ICPrC,aAAoC,OAAO,YAA4B;AAClF,MAAI,UAAU,CAAA;AACd,SAAI,YACF,UAAU,MAAM,MAAM,GAAG,gBAAgB,aAAa,YAAY,OAAO,CAAC,cAAc;AAAA,IACtF,SAAS,WAAW,OAAO;AAAA,EAAA,CAC5B,EACE,KAAK,CAAC,QAAQ,IAAI,KAAA,CAAM,EACxB;AAAA,IAAK,CAAC,QACL,IAAI,KAAK,IAAI,CAAC,UAA+B;AAAA,MAC3C,SAAS;AAAA,MACT,aAAa,KAAK,WAAW;AAAA,MAC7B,UAAU,KAAK,WAAW;AAAA,IAAA,EAC1B;AAAA,EAAA,IAGD;AACT,GCfa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GjE,QAAM,oBAAoB,GAAG,gBAAgB,mCACvC,qBAAqB;AAAA,IACzB,MAAM;AAAA,MACJ,YAAY;AAAA,QACV,SAAS,SAAS;AAAA,QAClB,kBAAkB;AAAA,MAAA;AAAA,MAEpB,eAAe;AAAA,QACb,UAAU;AAAA,UACR,MAAM;AAAA,YACJ,IAAI;AAAA,YACJ,MAAM;AAAA,UAAA;AAAA,QACR;AAAA,MACF;AAAA,MAEF,MAAM;AAAA,IAAA;AAAA,EACR;AAGF,SAAO,MAAM,mBAAmB;AAAA,IAC9B,QAAQ;AAAA,IACR,MAAM,KAAK,UAAU,kBAAkB;AAAA,IACvC,SAAS,WAAW,OAAO;AAAA,EAAA,CAC5B,EAAE,KAAK,MAAM,mBAAmB,YAAY,OAAO,CAAC;AACvD,GC1Ea,mBAA4B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GCwBM,6BAA4C;AAAA,EAChD,GAAG;AAAA,EACH,SAAS;AAAA,EACT,kBAAkB;AACpB,GAEM,4BAA2C;AAAA,EAC/C,GAAGA;AAAAA,EACH,SAAS;AAAA,EACT,kBAAkB;AACpB,GAEM,0BAAyC;AAAA,EAC7C,GAAG;AAAA,EACH,SAAS;AAAA,EACT,kBAAkB;AACpB;"}
|
package/sanity.json
DELETED
package/src/index.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
baseDocumentLevelConfig,
|
|
3
|
-
legacyDocumentLevelConfig as baseLegacyDocumentLevelConfig,
|
|
4
|
-
baseFieldLevelConfig,
|
|
5
|
-
Adapter,
|
|
6
|
-
TranslationFunctionContext,
|
|
7
|
-
} from 'sanity-translations-tab'
|
|
8
|
-
import {TransifexAdapter} from './transifexAdapter'
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
findLatestDraft,
|
|
12
|
-
BaseDocumentDeserializer,
|
|
13
|
-
BaseDocumentSerializer,
|
|
14
|
-
BaseDocumentMerger,
|
|
15
|
-
defaultStopTypes,
|
|
16
|
-
customSerializers,
|
|
17
|
-
legacyDocumentLevelPatch,
|
|
18
|
-
documentLevelPatch,
|
|
19
|
-
fieldLevelPatch,
|
|
20
|
-
TranslationsTab,
|
|
21
|
-
} from 'sanity-translations-tab'
|
|
22
|
-
|
|
23
|
-
interface ConfigOptions {
|
|
24
|
-
adapter: Adapter
|
|
25
|
-
secretsNamespace: string | null
|
|
26
|
-
exportForTranslation: (
|
|
27
|
-
id: string,
|
|
28
|
-
context: TranslationFunctionContext
|
|
29
|
-
) => Promise<Record<string, any>>
|
|
30
|
-
importTranslation: (
|
|
31
|
-
id: string,
|
|
32
|
-
localeId: string,
|
|
33
|
-
doc: string,
|
|
34
|
-
context: TranslationFunctionContext
|
|
35
|
-
) => Promise<void>
|
|
36
|
-
}
|
|
37
|
-
const defaultDocumentLevelConfig: ConfigOptions = {
|
|
38
|
-
...baseDocumentLevelConfig,
|
|
39
|
-
adapter: TransifexAdapter,
|
|
40
|
-
secretsNamespace: 'transifex',
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const legacyDocumentLevelConfig: ConfigOptions = {
|
|
44
|
-
...baseLegacyDocumentLevelConfig,
|
|
45
|
-
adapter: TransifexAdapter,
|
|
46
|
-
secretsNamespace: 'transifex',
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const defaultFieldLevelConfig: ConfigOptions = {
|
|
50
|
-
...baseFieldLevelConfig,
|
|
51
|
-
adapter: TransifexAdapter,
|
|
52
|
-
secretsNamespace: 'transifex',
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export {
|
|
56
|
-
TransifexAdapter,
|
|
57
|
-
defaultDocumentLevelConfig,
|
|
58
|
-
defaultFieldLevelConfig,
|
|
59
|
-
legacyDocumentLevelConfig,
|
|
60
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {Adapter, Secrets} from 'sanity-translations-tab'
|
|
2
|
-
import {baseTransifexUrl, projOrgSlug, getHeaders} from './helpers'
|
|
3
|
-
import {getTranslationTask} from './getTranslationTask'
|
|
4
|
-
|
|
5
|
-
const createResource = (doc: Record<string, any>, documentId: string, secrets: Secrets | null) => {
|
|
6
|
-
const resourceCreateBody = {
|
|
7
|
-
data: {
|
|
8
|
-
attributes: {
|
|
9
|
-
accept_translations: true,
|
|
10
|
-
name: doc.name,
|
|
11
|
-
slug: documentId,
|
|
12
|
-
},
|
|
13
|
-
relationships: {
|
|
14
|
-
i18n_format: {
|
|
15
|
-
data: {
|
|
16
|
-
id: 'HTML_FRAGMENT',
|
|
17
|
-
type: 'i18n_formats',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
project: {
|
|
21
|
-
data: {
|
|
22
|
-
id: projOrgSlug(secrets),
|
|
23
|
-
type: 'projects',
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
type: 'resources',
|
|
28
|
-
},
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return fetch(`${baseTransifexUrl}/resources`, {
|
|
32
|
-
headers: getHeaders(secrets),
|
|
33
|
-
method: 'POST',
|
|
34
|
-
body: JSON.stringify(resourceCreateBody),
|
|
35
|
-
})
|
|
36
|
-
.then((res) => res.json())
|
|
37
|
-
.then((res) => res.data.id)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//@ts-ignore until we resolve the TranslationTask return type
|
|
41
|
-
export const createTask: Adapter['createTask'] = async (
|
|
42
|
-
documentId: string,
|
|
43
|
-
document: Record<string, any>,
|
|
44
|
-
localeIds: string[],
|
|
45
|
-
secrets: Secrets | null
|
|
46
|
-
) => {
|
|
47
|
-
let resourceId = await fetch(
|
|
48
|
-
`${baseTransifexUrl}/resources/${projOrgSlug(secrets)}:r:${documentId}`,
|
|
49
|
-
{headers: getHeaders(secrets)}
|
|
50
|
-
)
|
|
51
|
-
.then((res) => res.json())
|
|
52
|
-
.then((res) => (res.data ? res.data.id : null))
|
|
53
|
-
|
|
54
|
-
if (!resourceId) {
|
|
55
|
-
resourceId = await createResource(document, documentId, secrets)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const resourceUploadUrl = `${baseTransifexUrl}/resource_strings_async_uploads`
|
|
59
|
-
const resourceUploadBody = {
|
|
60
|
-
data: {
|
|
61
|
-
attributes: {
|
|
62
|
-
content: document.content,
|
|
63
|
-
content_encoding: 'text',
|
|
64
|
-
},
|
|
65
|
-
relationships: {
|
|
66
|
-
resource: {
|
|
67
|
-
data: {
|
|
68
|
-
id: resourceId,
|
|
69
|
-
type: 'resources',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
type: 'resource_strings_async_uploads',
|
|
74
|
-
},
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return fetch(resourceUploadUrl, {
|
|
78
|
-
method: 'POST',
|
|
79
|
-
body: JSON.stringify(resourceUploadBody),
|
|
80
|
-
headers: getHeaders(secrets),
|
|
81
|
-
}).then(() => getTranslationTask(documentId, secrets))
|
|
82
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {Adapter, Secrets} from 'sanity-translations-tab'
|
|
2
|
-
import {baseTransifexUrl, projOrgSlug, getHeaders} from './helpers'
|
|
3
|
-
|
|
4
|
-
export const getLocales: Adapter['getLocales'] = async (secrets: Secrets | null) => {
|
|
5
|
-
let locales = []
|
|
6
|
-
if (secrets) {
|
|
7
|
-
locales = await fetch(`${baseTransifexUrl}/projects/${projOrgSlug(secrets)}/languages`, {
|
|
8
|
-
headers: getHeaders(secrets),
|
|
9
|
-
})
|
|
10
|
-
.then((res) => res.json())
|
|
11
|
-
.then((res) =>
|
|
12
|
-
res.data.map((lang: Record<string, any>) => ({
|
|
13
|
-
enabled: true,
|
|
14
|
-
description: lang.attributes.name,
|
|
15
|
-
localeId: lang.attributes.code,
|
|
16
|
-
}))
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
return locales
|
|
20
|
-
}
|