sanity-plugin-transifex 3.0.0 → 4.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/README.md +53 -20
- package/dist/index.d.ts +5 -0
- package/dist/index.esm.js +8 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +14 -1
package/README.md
CHANGED
|
@@ -6,10 +6,15 @@
|
|
|
6
6
|
npm install sanity-plugin-transifex
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
|
|
9
12
|
# Sanity + Transifex = 🌍
|
|
10
13
|
|
|
11
14
|
This plugin provides an in-studio integration with [Transifex](https://transifex.com). 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.
|
|
12
15
|
|
|
16
|
+
_Recent updates for v4:_ We've added support for the new document internationalization plugin pattern. Please read the [Document level translations](#document-level-translations) section for more information.
|
|
17
|
+
|
|
13
18
|
# Table of Contents
|
|
14
19
|
|
|
15
20
|
- [Quickstart](#quickstart)
|
|
@@ -21,46 +26,69 @@ This plugin provides an in-studio integration with [Transifex](https://transifex
|
|
|
21
26
|
|
|
22
27
|
## Quickstart
|
|
23
28
|
|
|
24
|
-
1. In your studio folder, run
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
1. In your studio folder, run:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npm install sanity-plugin-transifex
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2. Ensure the plugin has access to your Transifex secrets. You'll want to create a document that includes your project name, organization name, and a token with appropriate access.
|
|
36
|
+
|
|
37
|
+
[Please refer to the Transifex documentation on creating a token if you don't have one already.](https://docs.transifex.com/account/authentication)
|
|
38
|
+
|
|
39
|
+
In your Studio folder, create a file called `populateTransifexSecrets.js` with the following contents:
|
|
28
40
|
|
|
29
41
|
```javascript
|
|
42
|
+
// ./populateTransifexSecrets.js
|
|
43
|
+
// Do not commit this file to your repository
|
|
44
|
+
|
|
30
45
|
import {getCliClient} from 'sanity/cli'
|
|
31
46
|
|
|
32
47
|
const client = getCliClient({apiVersion: '2023-02-15'})
|
|
33
48
|
|
|
34
49
|
client.createOrReplace({
|
|
50
|
+
// The `.` in this _id will ensure the document is private
|
|
51
|
+
// even in a public dataset!
|
|
35
52
|
_id: 'transifex.secrets',
|
|
36
53
|
_type: 'transifexSettings',
|
|
54
|
+
// Replace these with your values
|
|
37
55
|
organization: 'YOUR_TRANSIFEX_ORG_HERE',
|
|
38
56
|
project: 'YOUR_TRANSIFEX_PROJECT_HERE',
|
|
39
57
|
token: 'YOUR_TRANSIFEX_TOKEN_HERE'
|
|
40
58
|
})
|
|
41
59
|
```
|
|
42
60
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
61
|
+
On the command line, run the file:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
npx sanity exec populateTransifexSecrets.js --with-user-token
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Verify that the document was created using the Vision Tool in the Studio and query `*[_id == 'transifex.secrets']`. Note: If you have multiple datasets, you'll have to do this across all of them.
|
|
68
|
+
|
|
69
|
+
If the document was found in your dataset(s), delete `populateTransifexSecrets.js`.
|
|
47
70
|
|
|
48
|
-
|
|
71
|
+
If you have concerns about this being exposed to authenticated users of your studio, you can control access to this path with [role-based access control](https://www.sanity.io/docs/access-control).
|
|
72
|
+
|
|
73
|
+
4. Get the Transifex tab on your desired document type, using whatever pattern you like. You'll use the [desk structure](https://www.sanity.io/docs/structure-builder-introduction) for this. The options for translation will be nested under this desired document type's views. Here's an example:
|
|
49
74
|
|
|
50
75
|
```javascript
|
|
51
76
|
import {DefaultDocumentNodeResolver} from 'sanity/desk'
|
|
52
77
|
//...your other desk structure imports...
|
|
53
|
-
import {
|
|
78
|
+
import {TranslationsTab, defaultDocumentLevelConfig} from 'sanity-plugin-transifex'
|
|
79
|
+
//if you are using field-level translations, you can import the field-level config instead:
|
|
80
|
+
//import {TranslationsTab, defaultFieldLevelConfig} from 'sanity-plugin-studio-smartling'
|
|
81
|
+
//if you're not sure which, please look at the document-level and field-level sections below
|
|
54
82
|
|
|
55
|
-
export const
|
|
83
|
+
export const defaultDocumentNode: DefaultDocumentNodeResolver = (S, {schemaType}) => {
|
|
56
84
|
if (schemaType === 'myTranslatableDocumentType') {
|
|
57
85
|
return S.document().views([
|
|
58
86
|
S.view.form(),
|
|
59
|
-
//...my other views -- for example, live preview,
|
|
60
|
-
S.view.component(
|
|
87
|
+
//...my other views -- for example, live preview, document pane, etc.,
|
|
88
|
+
S.view.component(TranslationsTab).title('Transifex').options(defaultDocumentLevelConfig)
|
|
89
|
+
//again, if you're using field-level translations, you can use the field-level config instead:
|
|
61
90
|
])
|
|
62
91
|
}
|
|
63
|
-
return S.document()
|
|
64
92
|
}
|
|
65
93
|
```
|
|
66
94
|
|
|
@@ -72,8 +100,9 @@ To use the default config mentioned above, we assume that you are following the
|
|
|
72
100
|
|
|
73
101
|
### Field-level translations
|
|
74
102
|
|
|
75
|
-
If you are using field-level translation, we assume any fields you want translated exist in the multi-locale object form we recommend.
|
|
76
|
-
|
|
103
|
+
If you are using field-level translation and the `defaultFieldLevelConfig` configuration, we assume any fields you want translated exist in the multi-locale object form we recommend.
|
|
104
|
+
|
|
105
|
+
For example, on a document you don't want to be translated, you may have a "title" field that's a flat string: `title: 'My title is here.'` For a field you want to include many languages for your title may look like:
|
|
77
106
|
|
|
78
107
|
```javascript
|
|
79
108
|
{
|
|
@@ -88,7 +117,9 @@ For example, on a document you don't want to be translated, you may have a "titl
|
|
|
88
117
|
|
|
89
118
|
### Document level translations
|
|
90
119
|
|
|
91
|
-
Since we often find users want to use the [Document internationalization plugin](https://www.sanity.io/plugins/document-internationalization) if they're using document-level translations, we assume that any documents you want in different languages will
|
|
120
|
+
Since we often find users want to use the [Document internationalization plugin](https://www.sanity.io/plugins/document-internationalization) if they're using document-level translations, we assume that any documents you want in different languages will be present in a `translation.metadata` document.
|
|
121
|
+
|
|
122
|
+
_Important_: The above is true if you are using the Document Internationalization Plugin at version 2 or above. If you are using version 1 please use the `legacyDocumentLevelConfig` configuration exported from this plugin. This configuration assumes your translations follow the pattern `{id-of-base-language-document}__i18n_{locale}`
|
|
92
123
|
|
|
93
124
|
### Final note
|
|
94
125
|
|
|
@@ -106,11 +137,13 @@ To personalize this configuration it's useful to know what arguments go into `Tr
|
|
|
106
137
|
- `importTranslation`: a function that takes in `id` (your document id) `localeId` (the locale of the imported language) and `document` the translated HTML from Transifex. It will deserialize your document back into an object that can be patched into your Sanity data, and then executes that patch.
|
|
107
138
|
- `Adapter`: An interface with methods to send things over to Transifex. You likely don't want to override this!
|
|
108
139
|
|
|
109
|
-
There are
|
|
140
|
+
There are several reasons to override these functions. More general cases are often around ensuring documents serialize and deserialize correctly. Since the serialization functions are used across all our translation plugins currently, you can find some frequently encountered scenarios at [their repository here](https://github.com/sanity-io/sanity-naive-html-serializer), along with code examples for new config.
|
|
141
|
+
|
|
142
|
+
## Migrating to Sanity Studio v3
|
|
110
143
|
|
|
111
|
-
|
|
144
|
+
You should not have to do anything to migrate to Sanity Studio v3. If you are using the default configs, you should be able to upgrade without any changes. If you are using custom serialization, you may need to update how `BaseDocumentSerializer` receives your schema.
|
|
112
145
|
|
|
113
|
-
|
|
146
|
+
These are outlined in the serializer README [here](https://github.com/sanity-io/sanity-naive-html-serializer#v2-to-v3-changes).
|
|
114
147
|
|
|
115
148
|
## License
|
|
116
149
|
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {defaultStopTypes} from 'sanity-translations-tab'
|
|
|
7
7
|
import {documentLevelPatch} from 'sanity-translations-tab'
|
|
8
8
|
import {fieldLevelPatch} from 'sanity-translations-tab'
|
|
9
9
|
import {findLatestDraft} from 'sanity-translations-tab'
|
|
10
|
+
import {legacyDocumentLevelPatch} from 'sanity-translations-tab'
|
|
10
11
|
import {TranslationFunctionContext} from 'sanity-translations-tab'
|
|
11
12
|
import {TranslationsTab} from 'sanity-translations-tab'
|
|
12
13
|
|
|
@@ -45,6 +46,10 @@ export {fieldLevelPatch}
|
|
|
45
46
|
|
|
46
47
|
export {findLatestDraft}
|
|
47
48
|
|
|
49
|
+
export declare const legacyDocumentLevelConfig: ConfigOptions
|
|
50
|
+
|
|
51
|
+
export {legacyDocumentLevelPatch}
|
|
52
|
+
|
|
48
53
|
export declare const TransifexAdapter: Adapter
|
|
49
54
|
|
|
50
55
|
export {TranslationsTab}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { baseDocumentLevelConfig, baseFieldLevelConfig } from 'sanity-translations-tab';
|
|
2
|
-
export { BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, TranslationsTab, customSerializers, defaultStopTypes, documentLevelPatch, fieldLevelPatch, findLatestDraft } from 'sanity-translations-tab';
|
|
1
|
+
import { baseDocumentLevelConfig, legacyDocumentLevelConfig as legacyDocumentLevelConfig$1, baseFieldLevelConfig } from 'sanity-translations-tab';
|
|
2
|
+
export { BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, TranslationsTab, customSerializers, defaultStopTypes, documentLevelPatch, fieldLevelPatch, findLatestDraft, legacyDocumentLevelPatch } from 'sanity-translations-tab';
|
|
3
3
|
const baseTransifexUrl = "https://rest.api.transifex.com";
|
|
4
4
|
const getHeaders = secrets => ({
|
|
5
5
|
Authorization: "Bearer ".concat(secrets == null ? void 0 : secrets.token),
|
|
@@ -183,10 +183,15 @@ const defaultDocumentLevelConfig = {
|
|
|
183
183
|
adapter: TransifexAdapter,
|
|
184
184
|
secretsNamespace: "transifex"
|
|
185
185
|
};
|
|
186
|
+
const legacyDocumentLevelConfig = {
|
|
187
|
+
...legacyDocumentLevelConfig$1,
|
|
188
|
+
adapter: TransifexAdapter,
|
|
189
|
+
secretsNamespace: "transifex"
|
|
190
|
+
};
|
|
186
191
|
const defaultFieldLevelConfig = {
|
|
187
192
|
...baseFieldLevelConfig,
|
|
188
193
|
adapter: TransifexAdapter,
|
|
189
194
|
secretsNamespace: "transifex"
|
|
190
195
|
};
|
|
191
|
-
export { TransifexAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig };
|
|
196
|
+
export { TransifexAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig, legacyDocumentLevelConfig };
|
|
192
197
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.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,cAAg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AA6C,UAAA;YACJf,IAAM,EAAA;UACR;QACF;MACF,CAAA;MACAA,IAAM,EAAA;IACR;EAAA,CACF;EAEA,OAAOxD,MAAMwE,iBAAmB,EAAA;IAC9Bd,MAAQ,EAAA,MAAA;IACRC,IAAA,EAAMC,IAAK,CAAAC,SAAA,CAAUY,kBAAkB,CAAA;IACvCxE,OAAA,EAASV,WAAWC,OAAO;EAAA,CAC5B,CAAE,CAAAU,IAAA,CAAK,MAAMY,kBAAmB,CAAAC,UAAA,EAAYvB,OAAO,CAAC,CAAA;AACvD,CAAA;AC1EO,MAAMmF,gBAA4B,GAAA;EACvC7E,UAAA;EACAgB,kBAAA;EACAuD,UAAA;EACAhB;AACF,CAAA;ACsBA,MAAMuB,0BAA4C,GAAA;EAChD,GAAGC,uBAAA;EACHC,OAAS,EAAAH,gBAAA;EACTI,gBAAkB,EAAA;AACpB,CAAA;AAEA,MAAMC,uBAAyC,GAAA;EAC7C,GAAGC,oBAAA;EACHH,OAAS,EAAAH,gBAAA;EACTI,gBAAkB,EAAA;AACpB,CAAA;"}
|
|
1
|
+
{"version":3,"file":"index.esm.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 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":["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","legacyDocumentLevelConfig","baseLegacyDocumentLevelConfig","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,CAAA,CAAA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;EACHL,OAAS,EAAAH,gBAAA;EACTI,gBAAkB,EAAA;AACpB,CAAA;"}
|
package/dist/index.js
CHANGED
|
@@ -187,6 +187,11 @@ const defaultDocumentLevelConfig = {
|
|
|
187
187
|
adapter: TransifexAdapter,
|
|
188
188
|
secretsNamespace: "transifex"
|
|
189
189
|
};
|
|
190
|
+
const legacyDocumentLevelConfig = {
|
|
191
|
+
...sanityTranslationsTab.legacyDocumentLevelConfig,
|
|
192
|
+
adapter: TransifexAdapter,
|
|
193
|
+
secretsNamespace: "transifex"
|
|
194
|
+
};
|
|
190
195
|
const defaultFieldLevelConfig = {
|
|
191
196
|
...sanityTranslationsTab.baseFieldLevelConfig,
|
|
192
197
|
adapter: TransifexAdapter,
|
|
@@ -246,7 +251,14 @@ Object.defineProperty(exports, 'findLatestDraft', {
|
|
|
246
251
|
return sanityTranslationsTab.findLatestDraft;
|
|
247
252
|
}
|
|
248
253
|
});
|
|
254
|
+
Object.defineProperty(exports, 'legacyDocumentLevelPatch', {
|
|
255
|
+
enumerable: true,
|
|
256
|
+
get: function () {
|
|
257
|
+
return sanityTranslationsTab.legacyDocumentLevelPatch;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
249
260
|
exports.TransifexAdapter = TransifexAdapter;
|
|
250
261
|
exports.defaultDocumentLevelConfig = defaultDocumentLevelConfig;
|
|
251
262
|
exports.defaultFieldLevelConfig = defaultFieldLevelConfig;
|
|
263
|
+
exports.legacyDocumentLevelConfig = legacyDocumentLevelConfig;
|
|
252
264
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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;M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7C,GAAGC,qBAAA,CAAAA,oBAAA;EACHH,OAAS,EAAAH,gBAAA;EACTI,gBAAkB,EAAA;AACpB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
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 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":["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","legacyDocumentLevelConfig","baseLegacyDocumentLevelConfig","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,CA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IAAM,EAAA;YACJqB,EAAI,EAAA6C,UAAA;YACJf,IAAM,EAAA;UACR;QACF;MACF,CAAA;MACAA,IAAM,EAAA;IACR;EAAA,CACF;EAEA,OAAOxD,MAAMwE,iBAAmB,EAAA;IAC9Bd,MAAQ,EAAA,MAAA;IACRC,IAAA,EAAMC,IAAK,CAAAC,SAAA,CAAUY,kBAAkB,CAAA;IACvCxE,OAAA,EAASV,WAAWC,OAAO;EAAA,CAC5B,CAAE,CAAAU,IAAA,CAAK,MAAMY,kBAAmB,CAAAC,UAAA,EAAYvB,OAAO,CAAC,CAAA;AACvD,CAAA;AC1EO,MAAMmF,gBAA4B,GAAA;EACvC7E,UAAA;EACAgB,kBAAA;EACAuD,UAAA;EACAhB;AACF,CAAA;ACwBA,MAAMuB,0BAA4C,GAAA;EAChD,GAAGC,qBAAA,CAAAA,uBAAA;EACHC,OAAS,EAAAH,gBAAA;EACTI,gBAAkB,EAAA;AACpB,CAAA;AAEA,MAAMC,yBAA2C,GAAA;EAC/C,GAAGC,qBAAA,CAAAD,yBAAA;EACHF,OAAS,EAAAH,gBAAA;EACTI,gBAAkB,EAAA;AACpB,CAAA;AAEA,MAAMG,uBAAyC,GAAA;EAC7C,GAAGC,qBAAA,CAAAA,oBAAA;EACHL,OAAS,EAAAH,gBAAA;EACTI,gBAAkB,EAAA;AACpB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-transifex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.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",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@sanity/incompatible-plugin": "^1.0.4",
|
|
52
|
-
"sanity-translations-tab": "^
|
|
52
|
+
"sanity-translations-tab": "^4.0.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@commitlint/cli": "^17.4.3",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
baseDocumentLevelConfig,
|
|
3
|
+
legacyDocumentLevelConfig as baseLegacyDocumentLevelConfig,
|
|
3
4
|
baseFieldLevelConfig,
|
|
4
5
|
Adapter,
|
|
5
6
|
TranslationFunctionContext,
|
|
@@ -13,6 +14,7 @@ export {
|
|
|
13
14
|
BaseDocumentMerger,
|
|
14
15
|
defaultStopTypes,
|
|
15
16
|
customSerializers,
|
|
17
|
+
legacyDocumentLevelPatch,
|
|
16
18
|
documentLevelPatch,
|
|
17
19
|
fieldLevelPatch,
|
|
18
20
|
TranslationsTab,
|
|
@@ -38,10 +40,21 @@ const defaultDocumentLevelConfig: ConfigOptions = {
|
|
|
38
40
|
secretsNamespace: 'transifex',
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
const legacyDocumentLevelConfig: ConfigOptions = {
|
|
44
|
+
...baseLegacyDocumentLevelConfig,
|
|
45
|
+
adapter: TransifexAdapter,
|
|
46
|
+
secretsNamespace: 'transifex',
|
|
47
|
+
}
|
|
48
|
+
|
|
41
49
|
const defaultFieldLevelConfig: ConfigOptions = {
|
|
42
50
|
...baseFieldLevelConfig,
|
|
43
51
|
adapter: TransifexAdapter,
|
|
44
52
|
secretsNamespace: 'transifex',
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
export {
|
|
55
|
+
export {
|
|
56
|
+
TransifexAdapter,
|
|
57
|
+
defaultDocumentLevelConfig,
|
|
58
|
+
defaultFieldLevelConfig,
|
|
59
|
+
legacyDocumentLevelConfig,
|
|
60
|
+
}
|