sanity-plugin-transifex 2.0.5 → 3.0.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/LICENSE +2 -2
- package/README.md +74 -200
- package/dist/index.d.ts +52 -11
- package/dist/index.esm.js +192 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +251 -7
- package/dist/index.js.map +1 -0
- package/package.json +87 -48
- package/sanity.json +8 -0
- package/src/index.ts +14 -19
- package/src/transifexAdapter/createTask.ts +12 -17
- package/src/transifexAdapter/getLocales.ts +10 -11
- package/src/transifexAdapter/getTranslation.ts +48 -60
- package/src/transifexAdapter/getTranslationTask.ts +12 -19
- package/src/transifexAdapter/helpers.ts +3 -3
- package/src/transifexAdapter/index.ts +5 -5
- package/v2-incompatible.js +11 -0
- package/.github/workflows/main.yml +0 -29
- package/.github/workflows/npm-publish.yml +0 -19
- package/dist/sanity-plugin-transifex.cjs.development.js +0 -903
- package/dist/sanity-plugin-transifex.cjs.development.js.map +0 -1
- package/dist/sanity-plugin-transifex.cjs.production.min.js +0 -2
- package/dist/sanity-plugin-transifex.cjs.production.min.js.map +0 -1
- package/dist/sanity-plugin-transifex.esm.js +0 -844
- package/dist/sanity-plugin-transifex.esm.js.map +0 -1
- package/dist/transifexAdapter/createTask.d.ts +0 -6
- package/dist/transifexAdapter/getLocales.d.ts +0 -2
- package/dist/transifexAdapter/getTranslation.d.ts +0 -2
- package/dist/transifexAdapter/getTranslationTask.d.ts +0 -6
- package/dist/transifexAdapter/helpers.d.ts +0 -7
- package/dist/transifexAdapter/index.d.ts +0 -2
- package/test/directives.test.ts +0 -155
- package/test/localeId.test.ts +0 -17
- package/test/mergeTranslation.test.ts +0 -113
- package/tsconfig.json +0 -35
package/dist/index.js
CHANGED
|
@@ -1,8 +1,252 @@
|
|
|
1
|
+
'use strict';
|
|
1
2
|
|
|
2
|
-
'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var sanityTranslationsTab = require('sanity-translations-tab');
|
|
7
|
+
const baseTransifexUrl = "https://rest.api.transifex.com";
|
|
8
|
+
const getHeaders = secrets => ({
|
|
9
|
+
Authorization: "Bearer ".concat(secrets == null ? void 0 : secrets.token),
|
|
10
|
+
"Content-Type": "application/vnd.api+json"
|
|
11
|
+
});
|
|
12
|
+
const projOrgSlug = secrets => "o:".concat(secrets == null ? void 0 : secrets.organization, ":p:").concat(secrets == null ? void 0 : secrets.project);
|
|
13
|
+
const getLocales = async secrets => {
|
|
14
|
+
let locales = [];
|
|
15
|
+
if (secrets) {
|
|
16
|
+
locales = await fetch("".concat(baseTransifexUrl, "/projects/").concat(projOrgSlug(secrets), "/languages"), {
|
|
17
|
+
headers: getHeaders(secrets)
|
|
18
|
+
}).then(res => res.json()).then(res => res.data.map(lang => ({
|
|
19
|
+
enabled: true,
|
|
20
|
+
description: lang.attributes.name,
|
|
21
|
+
localeId: lang.attributes.code
|
|
22
|
+
})));
|
|
23
|
+
}
|
|
24
|
+
return locales;
|
|
25
|
+
};
|
|
26
|
+
const getTranslationTask = async (documentId, secrets) => {
|
|
27
|
+
if (!documentId || !secrets) {
|
|
28
|
+
return {
|
|
29
|
+
taskId: documentId,
|
|
30
|
+
documentId,
|
|
31
|
+
locales: []
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const projectFilter = "filter[project]=".concat(projOrgSlug(secrets));
|
|
35
|
+
const resourceFilter = "filter[resource]=".concat(projOrgSlug(secrets), ":r:").concat(documentId);
|
|
36
|
+
const task = await fetch("".concat(baseTransifexUrl, "/resource_language_stats?").concat(projectFilter, "&").concat(resourceFilter), {
|
|
37
|
+
headers: getHeaders(secrets)
|
|
38
|
+
}).then(res => {
|
|
39
|
+
if (res.ok) {
|
|
40
|
+
return res.json();
|
|
41
|
+
} else if (res.status === 404) {
|
|
42
|
+
return {
|
|
43
|
+
data: []
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
throw Error("Failed to retrieve tasks from Transifex. Status: ".concat(res.status));
|
|
47
|
+
}).then(res => ({
|
|
48
|
+
taskId: "".concat(projOrgSlug(secrets), ":r:").concat(documentId),
|
|
49
|
+
documentId,
|
|
50
|
+
locales: res.data.map(locale => ({
|
|
51
|
+
localeId: locale.relationships.language.data.id.split(":")[1],
|
|
52
|
+
progress: Math.floor(100 * (locale.attributes.reviewed_strings / parseFloat(locale.attributes.total_strings)))
|
|
53
|
+
}))
|
|
54
|
+
}));
|
|
55
|
+
const locales = await getLocales(secrets);
|
|
56
|
+
const localeIds = locales.map(l => l.localeId);
|
|
57
|
+
const validLocales = task.locales.filter(locale => localeIds.find(id => id === locale.localeId));
|
|
58
|
+
task.locales = validLocales;
|
|
59
|
+
return task;
|
|
60
|
+
};
|
|
61
|
+
const pollForFileDownloadLocation = async (resourceDownloadUrl, translationDownloadId, headers) => {
|
|
62
|
+
const response = await fetch("".concat(resourceDownloadUrl, "/").concat(translationDownloadId), {
|
|
63
|
+
headers
|
|
64
|
+
});
|
|
65
|
+
if (response.status === 500) {
|
|
66
|
+
console.info("Transifex plugin message: Received 500 for translation download ID ".concat(translationDownloadId, ". Trying to reconnect..."));
|
|
67
|
+
await new Promise(resolve => setTimeout(resolve, 3e3));
|
|
68
|
+
return pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers);
|
|
69
|
+
} else if (response.redirected) {
|
|
70
|
+
console.info("Transifex plugin message: Received redirect for translation download ID ".concat(translationDownloadId, ". Following redirect now for file download."));
|
|
71
|
+
return response.url;
|
|
72
|
+
} else if (response.status === 200) {
|
|
73
|
+
console.info("Transifex plugin message: Requested download location for translation download ID ".concat(translationDownloadId, ". Location is still pending, trying again."));
|
|
74
|
+
await new Promise(resolve => setTimeout(resolve, 3e3));
|
|
75
|
+
return pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers);
|
|
76
|
+
}
|
|
77
|
+
console.error("Transifex plugin message: Requested download location for translation download ID ".concat(translationDownloadId, " but received error code ").concat(response.status, ". Waiting and trying again."));
|
|
78
|
+
await new Promise(resolve => setTimeout(resolve, 3e3));
|
|
79
|
+
return pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers);
|
|
80
|
+
};
|
|
81
|
+
const handleFileDownload = url => {
|
|
82
|
+
return fetch(url).then(res => res.text());
|
|
83
|
+
};
|
|
84
|
+
const getTranslation = async (taskId, localeId, secrets) => {
|
|
85
|
+
const resourceDownloadBody = {
|
|
86
|
+
data: {
|
|
87
|
+
attributes: {
|
|
88
|
+
content_encoding: "text"
|
|
89
|
+
},
|
|
90
|
+
relationships: {
|
|
91
|
+
language: {
|
|
92
|
+
data: {
|
|
93
|
+
id: "l:".concat(localeId),
|
|
94
|
+
type: "languages"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
resource: {
|
|
98
|
+
data: {
|
|
99
|
+
id: taskId,
|
|
100
|
+
type: "resources"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
type: "resource_translations_async_downloads"
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const resourceDownloadUrl = "".concat(baseTransifexUrl, "/resource_translations_async_downloads");
|
|
108
|
+
const translationDownloadId = await fetch(resourceDownloadUrl, {
|
|
109
|
+
headers: getHeaders(secrets),
|
|
110
|
+
method: "POST",
|
|
111
|
+
body: JSON.stringify(resourceDownloadBody)
|
|
112
|
+
}).then(res => res.json()).then(res => res.data.id);
|
|
113
|
+
const headers = getHeaders(secrets);
|
|
114
|
+
const location = await pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers);
|
|
115
|
+
return handleFileDownload(location);
|
|
116
|
+
};
|
|
117
|
+
const createResource = (doc, documentId, secrets) => {
|
|
118
|
+
const resourceCreateBody = {
|
|
119
|
+
data: {
|
|
120
|
+
attributes: {
|
|
121
|
+
accept_translations: true,
|
|
122
|
+
name: doc.name,
|
|
123
|
+
slug: documentId
|
|
124
|
+
},
|
|
125
|
+
relationships: {
|
|
126
|
+
i18n_format: {
|
|
127
|
+
data: {
|
|
128
|
+
id: "HTML_FRAGMENT",
|
|
129
|
+
type: "i18n_formats"
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
project: {
|
|
133
|
+
data: {
|
|
134
|
+
id: projOrgSlug(secrets),
|
|
135
|
+
type: "projects"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
type: "resources"
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
return fetch("".concat(baseTransifexUrl, "/resources"), {
|
|
143
|
+
headers: getHeaders(secrets),
|
|
144
|
+
method: "POST",
|
|
145
|
+
body: JSON.stringify(resourceCreateBody)
|
|
146
|
+
}).then(res => res.json()).then(res => res.data.id);
|
|
147
|
+
};
|
|
148
|
+
const createTask = async (documentId, document, localeIds, secrets) => {
|
|
149
|
+
let resourceId = await fetch("".concat(baseTransifexUrl, "/resources/").concat(projOrgSlug(secrets), ":r:").concat(documentId), {
|
|
150
|
+
headers: getHeaders(secrets)
|
|
151
|
+
}).then(res => res.json()).then(res => res.data ? res.data.id : null);
|
|
152
|
+
if (!resourceId) {
|
|
153
|
+
resourceId = await createResource(document, documentId, secrets);
|
|
154
|
+
}
|
|
155
|
+
const resourceUploadUrl = "".concat(baseTransifexUrl, "/resource_strings_async_uploads");
|
|
156
|
+
const resourceUploadBody = {
|
|
157
|
+
data: {
|
|
158
|
+
attributes: {
|
|
159
|
+
content: document.content,
|
|
160
|
+
content_encoding: "text"
|
|
161
|
+
},
|
|
162
|
+
relationships: {
|
|
163
|
+
resource: {
|
|
164
|
+
data: {
|
|
165
|
+
id: resourceId,
|
|
166
|
+
type: "resources"
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
type: "resource_strings_async_uploads"
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
return fetch(resourceUploadUrl, {
|
|
174
|
+
method: "POST",
|
|
175
|
+
body: JSON.stringify(resourceUploadBody),
|
|
176
|
+
headers: getHeaders(secrets)
|
|
177
|
+
}).then(() => getTranslationTask(documentId, secrets));
|
|
178
|
+
};
|
|
179
|
+
const TransifexAdapter = {
|
|
180
|
+
getLocales,
|
|
181
|
+
getTranslationTask,
|
|
182
|
+
createTask,
|
|
183
|
+
getTranslation
|
|
184
|
+
};
|
|
185
|
+
const defaultDocumentLevelConfig = {
|
|
186
|
+
...sanityTranslationsTab.baseDocumentLevelConfig,
|
|
187
|
+
adapter: TransifexAdapter,
|
|
188
|
+
secretsNamespace: "transifex"
|
|
189
|
+
};
|
|
190
|
+
const defaultFieldLevelConfig = {
|
|
191
|
+
...sanityTranslationsTab.baseFieldLevelConfig,
|
|
192
|
+
adapter: TransifexAdapter,
|
|
193
|
+
secretsNamespace: "transifex"
|
|
194
|
+
};
|
|
195
|
+
Object.defineProperty(exports, 'BaseDocumentDeserializer', {
|
|
196
|
+
enumerable: true,
|
|
197
|
+
get: function () {
|
|
198
|
+
return sanityTranslationsTab.BaseDocumentDeserializer;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
Object.defineProperty(exports, 'BaseDocumentMerger', {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
get: function () {
|
|
204
|
+
return sanityTranslationsTab.BaseDocumentMerger;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
Object.defineProperty(exports, 'BaseDocumentSerializer', {
|
|
208
|
+
enumerable: true,
|
|
209
|
+
get: function () {
|
|
210
|
+
return sanityTranslationsTab.BaseDocumentSerializer;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
Object.defineProperty(exports, 'TranslationsTab', {
|
|
214
|
+
enumerable: true,
|
|
215
|
+
get: function () {
|
|
216
|
+
return sanityTranslationsTab.TranslationsTab;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
Object.defineProperty(exports, 'customSerializers', {
|
|
220
|
+
enumerable: true,
|
|
221
|
+
get: function () {
|
|
222
|
+
return sanityTranslationsTab.customSerializers;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
Object.defineProperty(exports, 'defaultStopTypes', {
|
|
226
|
+
enumerable: true,
|
|
227
|
+
get: function () {
|
|
228
|
+
return sanityTranslationsTab.defaultStopTypes;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
Object.defineProperty(exports, 'documentLevelPatch', {
|
|
232
|
+
enumerable: true,
|
|
233
|
+
get: function () {
|
|
234
|
+
return sanityTranslationsTab.documentLevelPatch;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(exports, 'fieldLevelPatch', {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
get: function () {
|
|
240
|
+
return sanityTranslationsTab.fieldLevelPatch;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
Object.defineProperty(exports, 'findLatestDraft', {
|
|
244
|
+
enumerable: true,
|
|
245
|
+
get: function () {
|
|
246
|
+
return sanityTranslationsTab.findLatestDraft;
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
exports.TransifexAdapter = TransifexAdapter;
|
|
250
|
+
exports.defaultDocumentLevelConfig = defaultDocumentLevelConfig;
|
|
251
|
+
exports.defaultFieldLevelConfig = defaultFieldLevelConfig;
|
|
252
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","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 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 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 defaultFieldLevelConfig: ConfigOptions = {\n ...baseFieldLevelConfig,\n adapter: TransifexAdapter,\n secretsNamespace: 'transifex',\n}\n\nexport {TransifexAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig}\n"],"names":["baseTransifexUrl","getHeaders","secrets","Authorization","token","projOrgSlug","organization","project","getLocales","locales","fetch","headers","then","res","json","data","map","lang","enabled","description","attributes","name","localeId","code","getTranslationTask","documentId","taskId","projectFilter","resourceFilter","task","ok","status","Error","locale","relationships","language","id","split","progress","Math","floor","reviewed_strings","parseFloat","total_strings","localeIds","l","validLocales","filter","find","pollForFileDownloadLocation","resourceDownloadUrl","translationDownloadId","response","console","info","Promise","resolve","setTimeout","redirected","url","error","handleFileDownload","text","getTranslation","resourceDownloadBody","content_encoding","type","resource","method","body","JSON","stringify","location","createResource","doc","resourceCreateBody","accept_translations","slug","i18n_format","createTask","document","resourceId","resourceUploadUrl","resourceUploadBody","content","TransifexAdapter","defaultDocumentLevelConfig","baseDocumentLevelConfig","adapter","secretsNamespace","defaultFieldLevelConfig","baseFieldLevelConfig"],"mappings":";;;;;;AAEO,MAAMA,gBAAmB,GAAA,gCAAA;AAEnB,MAAAC,UAAA,GAAcC,OAAqD,KAAA;EAC9EC,aAAA,mBAAyBD,OAAS,IAAA,IAAA,GAAA,KAAA,CAAA,GAAAA,OAAA,CAAAE,KAAA,CAAA;EAClC,cAAgB,EAAA;AAClB,CAAA,CAAA;AAEO,MAAMC,cAAeH,OAAA,gBACrBA,OAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAAA,OAAA,CAASI,4BAAkBJ,OAAS,IAAA,IAAA,GAAA,KAAA,CAAA,GAAAA,OAAA,CAAAK,OAAA,CAAA;ACP9B,MAAAC,UAAA,GAAoC,MAAON,OAA4B,IAAA;EAClF,IAAIO,UAAU,EAAC;EACf,IAAIP,OAAS,EAAA;IACXO,OAAA,GAAU,MAAMC,KAAM,WAAGV,gBAA6B,uBAAAK,WAAA,CAAYH,OAAO,CAAe,iBAAA;MACtFS,OAAA,EAASV,WAAWC,OAAO;IAAA,CAC5B,EACEU,IAAK,CAACC,OAAQA,GAAI,CAAAC,IAAA,EAAM,CACxB,CAAAF,IAAA,CAAMC,GACL,IAAAA,GAAA,CAAIE,IAAK,CAAAC,GAAA,CAAKC,IAA+B,KAAA;MAC3CC,OAAS,EAAA,IAAA;MACTC,WAAA,EAAaF,KAAKG,UAAW,CAAAC,IAAA;MAC7BC,QAAA,EAAUL,KAAKG,UAAW,CAAAG;IAAA,CAC1B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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,61 +1,100 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"lint": "tsdx lint src",
|
|
13
|
-
"prepare": "tsdx build",
|
|
14
|
-
"size": "size-limit",
|
|
15
|
-
"analyze": "size-limit --why"
|
|
16
|
-
},
|
|
17
|
-
"husky": {
|
|
18
|
-
"hooks": {
|
|
19
|
-
"pre-commit": "tsdx lint src"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"eslintConfig": {
|
|
23
|
-
"extends": "react-app",
|
|
24
|
-
"rules": {
|
|
25
|
-
"@typescript-eslint/no-redeclare": "off",
|
|
26
|
-
"no-redeclare": "off"
|
|
27
|
-
}
|
|
2
|
+
"name": "sanity-plugin-transifex",
|
|
3
|
+
"version": "3.0.0",
|
|
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
|
+
"keywords": [
|
|
6
|
+
"sanity",
|
|
7
|
+
"sanity-plugin"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/sanity-io/sanity-plugin-transifex#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/sanity-io/sanity-plugin-transifex/issues"
|
|
28
12
|
},
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"singleQuote": true,
|
|
33
|
-
"trailingComma": "es5"
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git@github.com:sanity-io/sanity-plugin-transifex.git"
|
|
34
16
|
},
|
|
35
|
-
"
|
|
17
|
+
"license": "MIT",
|
|
36
18
|
"author": "Sanity.io",
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"source": "./src/index.ts",
|
|
23
|
+
"require": "./dist/index.js",
|
|
24
|
+
"import": "./dist/index.esm.js",
|
|
25
|
+
"default": "./dist/index.esm.js"
|
|
43
26
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"module": "./dist/index.esm.js",
|
|
31
|
+
"source": "./src/index.ts",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"sanity.json",
|
|
36
|
+
"src",
|
|
37
|
+
"v2-incompatible.js"
|
|
48
38
|
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
|
|
41
|
+
"lint": "eslint .",
|
|
42
|
+
"prepare": "husky install",
|
|
43
|
+
"analyze": "size-limit --why",
|
|
44
|
+
"clean": "rimraf dist",
|
|
45
|
+
"format": "prettier --write --cache --ignore-unknown .",
|
|
46
|
+
"link-watch": "plugin-kit link-watch",
|
|
47
|
+
"prepublishOnly": "run-s build",
|
|
48
|
+
"watch": "pkg-utils watch --strict"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@sanity/incompatible-plugin": "^1.0.4",
|
|
52
|
+
"sanity-translations-tab": "^3.0.0"
|
|
53
|
+
},
|
|
49
54
|
"devDependencies": {
|
|
50
|
-
"@
|
|
55
|
+
"@commitlint/cli": "^17.4.3",
|
|
56
|
+
"@commitlint/config-conventional": "^17.4.3",
|
|
57
|
+
"@sanity/pkg-utils": "^2.2.5",
|
|
58
|
+
"@sanity/plugin-kit": "^3.1.4",
|
|
59
|
+
"@sanity/semantic-release-preset": "^4.0.0",
|
|
60
|
+
"@types/react": "^18.0.28",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^5.52.0",
|
|
62
|
+
"@typescript-eslint/parser": "^5.52.0",
|
|
63
|
+
"eslint": "^8.34.0",
|
|
64
|
+
"eslint-config-prettier": "^8.6.0",
|
|
51
65
|
"eslint-config-react-app": "^6.0.0",
|
|
52
|
-
"
|
|
66
|
+
"eslint-config-sanity": "^6.0.0",
|
|
67
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
68
|
+
"eslint-plugin-react": "^7.32.2",
|
|
69
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
70
|
+
"husky": "^8.0.3",
|
|
71
|
+
"lint-staged": "^13.1.2",
|
|
72
|
+
"npm-run-all": "^4.1.5",
|
|
73
|
+
"prettier": "^2.8.4",
|
|
74
|
+
"prettier-plugin-packagejson": "^2.4.3",
|
|
75
|
+
"react": "^18.2.0",
|
|
76
|
+
"react-dom": "^18.2.0",
|
|
77
|
+
"react-is": "^18.2.0",
|
|
78
|
+
"rimraf": "^4.1.2",
|
|
79
|
+
"sanity": "^3.3.1",
|
|
80
|
+
"semantic-release": "^20.1.0",
|
|
53
81
|
"size-limit": "^4.7.0",
|
|
54
|
-
"
|
|
82
|
+
"styled-components": "^5.3.6",
|
|
55
83
|
"tslib": "^2.0.3",
|
|
56
|
-
"typescript": "^4.
|
|
84
|
+
"typescript": "^4.9.5"
|
|
57
85
|
},
|
|
58
|
-
"
|
|
59
|
-
"
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"react": "^18",
|
|
88
|
+
"sanity": "^3"
|
|
89
|
+
},
|
|
90
|
+
"engines": {
|
|
91
|
+
"node": ">=14"
|
|
92
|
+
},
|
|
93
|
+
"eslintConfig": {
|
|
94
|
+
"extends": "react-app",
|
|
95
|
+
"rules": {
|
|
96
|
+
"@typescript-eslint/no-redeclare": "off",
|
|
97
|
+
"no-redeclare": "off"
|
|
98
|
+
}
|
|
60
99
|
}
|
|
61
100
|
}
|
package/sanity.json
ADDED
package/src/index.ts
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
|
-
TranslationsTab,
|
|
3
2
|
baseDocumentLevelConfig,
|
|
4
3
|
baseFieldLevelConfig,
|
|
4
|
+
Adapter,
|
|
5
|
+
TranslationFunctionContext,
|
|
6
|
+
} from 'sanity-translations-tab'
|
|
7
|
+
import {TransifexAdapter} from './transifexAdapter'
|
|
8
|
+
|
|
9
|
+
export {
|
|
5
10
|
findLatestDraft,
|
|
6
11
|
BaseDocumentDeserializer,
|
|
7
12
|
BaseDocumentSerializer,
|
|
8
13
|
BaseDocumentMerger,
|
|
9
14
|
defaultStopTypes,
|
|
10
15
|
customSerializers,
|
|
11
|
-
Adapter,
|
|
12
16
|
documentLevelPatch,
|
|
13
17
|
fieldLevelPatch,
|
|
18
|
+
TranslationsTab,
|
|
14
19
|
} from 'sanity-translations-tab'
|
|
15
|
-
import { TransifexAdapter } from './transifexAdapter'
|
|
16
20
|
|
|
17
21
|
interface ConfigOptions {
|
|
18
22
|
adapter: Adapter
|
|
19
23
|
secretsNamespace: string | null
|
|
20
|
-
exportForTranslation: (
|
|
24
|
+
exportForTranslation: (
|
|
25
|
+
id: string,
|
|
26
|
+
context: TranslationFunctionContext
|
|
27
|
+
) => Promise<Record<string, any>>
|
|
21
28
|
importTranslation: (
|
|
22
29
|
id: string,
|
|
23
30
|
localeId: string,
|
|
24
|
-
doc: string
|
|
31
|
+
doc: string,
|
|
32
|
+
context: TranslationFunctionContext
|
|
25
33
|
) => Promise<void>
|
|
26
34
|
}
|
|
27
35
|
const defaultDocumentLevelConfig: ConfigOptions = {
|
|
@@ -36,17 +44,4 @@ const defaultFieldLevelConfig: ConfigOptions = {
|
|
|
36
44
|
secretsNamespace: 'transifex',
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
export {
|
|
40
|
-
TranslationsTab,
|
|
41
|
-
findLatestDraft,
|
|
42
|
-
documentLevelPatch,
|
|
43
|
-
fieldLevelPatch,
|
|
44
|
-
BaseDocumentDeserializer,
|
|
45
|
-
BaseDocumentSerializer,
|
|
46
|
-
BaseDocumentMerger,
|
|
47
|
-
defaultStopTypes,
|
|
48
|
-
customSerializers,
|
|
49
|
-
TransifexAdapter,
|
|
50
|
-
defaultDocumentLevelConfig,
|
|
51
|
-
defaultFieldLevelConfig,
|
|
52
|
-
}
|
|
47
|
+
export {TransifexAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { Secrets
|
|
2
|
-
import {
|
|
3
|
-
import getTranslationTask from './getTranslationTask'
|
|
1
|
+
import {Adapter, Secrets} from 'sanity-translations-tab'
|
|
2
|
+
import {baseTransifexUrl, projOrgSlug, getHeaders} from './helpers'
|
|
3
|
+
import {getTranslationTask} from './getTranslationTask'
|
|
4
4
|
|
|
5
|
-
const createResource =
|
|
6
|
-
doc: Record<string, any>,
|
|
7
|
-
documentId: string,
|
|
8
|
-
secrets: Secrets | null
|
|
9
|
-
) => {
|
|
5
|
+
const createResource = (doc: Record<string, any>, documentId: string, secrets: Secrets | null) => {
|
|
10
6
|
const resourceCreateBody = {
|
|
11
7
|
data: {
|
|
12
8
|
attributes: {
|
|
@@ -37,24 +33,23 @@ const createResource = async (
|
|
|
37
33
|
method: 'POST',
|
|
38
34
|
body: JSON.stringify(resourceCreateBody),
|
|
39
35
|
})
|
|
40
|
-
.then(res => res.json())
|
|
41
|
-
.then(res => res.data.id)
|
|
36
|
+
.then((res) => res.json())
|
|
37
|
+
.then((res) => res.data.id)
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
//@ts-ignore until we resolve the TranslationTask return type
|
|
41
|
+
export const createTask: Adapter['createTask'] = async (
|
|
45
42
|
documentId: string,
|
|
46
43
|
document: Record<string, any>,
|
|
47
|
-
//unfortunately Transifex doesn't let you specify locales on creating a task
|
|
48
|
-
//@ts-ignore
|
|
49
44
|
localeIds: string[],
|
|
50
45
|
secrets: Secrets | null
|
|
51
|
-
) {
|
|
46
|
+
) => {
|
|
52
47
|
let resourceId = await fetch(
|
|
53
48
|
`${baseTransifexUrl}/resources/${projOrgSlug(secrets)}:r:${documentId}`,
|
|
54
|
-
{
|
|
49
|
+
{headers: getHeaders(secrets)}
|
|
55
50
|
)
|
|
56
|
-
.then(res => res.json())
|
|
57
|
-
.then(res => (res.data ? res.data.id : null))
|
|
51
|
+
.then((res) => res.json())
|
|
52
|
+
.then((res) => (res.data ? res.data.id : null))
|
|
58
53
|
|
|
59
54
|
if (!resourceId) {
|
|
60
55
|
resourceId = await createResource(document, documentId, secrets)
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { Secrets
|
|
2
|
-
import {
|
|
1
|
+
import {Adapter, Secrets} from 'sanity-translations-tab'
|
|
2
|
+
import {baseTransifexUrl, projOrgSlug, getHeaders} from './helpers'
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export const getLocales: Adapter['getLocales'] = async (secrets: Secrets | null) => {
|
|
5
|
+
let locales = []
|
|
5
6
|
if (secrets) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.then(res =>
|
|
11
|
-
.then(res =>
|
|
7
|
+
locales = await fetch(`${baseTransifexUrl}/projects/${projOrgSlug(secrets)}/languages`, {
|
|
8
|
+
headers: getHeaders(secrets),
|
|
9
|
+
})
|
|
10
|
+
.then((res) => res.json())
|
|
11
|
+
.then((res) =>
|
|
12
12
|
res.data.map((lang: Record<string, any>) => ({
|
|
13
13
|
enabled: true,
|
|
14
14
|
description: lang.attributes.name,
|
|
15
15
|
localeId: lang.attributes.code,
|
|
16
16
|
}))
|
|
17
17
|
)
|
|
18
|
-
} else {
|
|
19
|
-
return []
|
|
20
18
|
}
|
|
19
|
+
return locales
|
|
21
20
|
}
|