@transifex/api 2.4.1 → 3.2.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 +52 -0
- package/dist/browser.transifexApi.js +1 -2
- package/dist/browser.transifexApi.js.map +1 -1
- package/dist/node.transifexApi.js +1 -2
- package/dist/node.transifexApi.js.map +1 -1
- package/package.json +3 -3
- package/src/transifexApi.js +266 -11
- package/dist/browser.transifexApi.js.LICENSE.txt +0 -1
- package/dist/node.transifexApi.js.LICENSE.txt +0 -1
package/README.md
CHANGED
|
@@ -251,3 +251,55 @@ To delete something:
|
|
|
251
251
|
```javascript
|
|
252
252
|
await project.delete();
|
|
253
253
|
```
|
|
254
|
+
|
|
255
|
+
## File uploads and downloads
|
|
256
|
+
|
|
257
|
+
There is code in `@transifex/api` that automates several {json:api}
|
|
258
|
+
interactions behind the scenes in order to help with file uploads and downloads.
|
|
259
|
+
|
|
260
|
+
In order to upload a source file to a resource, you can do:
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
const content = JSON.stringify({ key: 'A value' });
|
|
264
|
+
await transifexApi.ResourceStringsAsyncUpload.upload({
|
|
265
|
+
resource,
|
|
266
|
+
content,
|
|
267
|
+
});
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
In order to upload a translation file to a resource, you can do:
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
const content = JSON.stringify({ key: 'A value in French' });
|
|
274
|
+
const language = await transifexApi.Language.get({ code: 'fr' });
|
|
275
|
+
await transifexApi.ResourceTranslationsAsyncUpload.upload({
|
|
276
|
+
resource,
|
|
277
|
+
language,
|
|
278
|
+
content,
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
To upload binary files, convert file content to `base64` encoding:
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
await transifexApi.ResourceTranslationsAsyncUpload.upload({
|
|
286
|
+
resource,
|
|
287
|
+
language,
|
|
288
|
+
content, // base64 encoded string
|
|
289
|
+
content_encoding: 'base64',
|
|
290
|
+
});
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
In order to download a translated language file, you can do:
|
|
294
|
+
|
|
295
|
+
```
|
|
296
|
+
const language = await transifexApi.Language.get({ code: 'fr' });
|
|
297
|
+
const url = await transifexApi.ResourceTranslationsAsyncDownload.download({
|
|
298
|
+
resource,
|
|
299
|
+
language,
|
|
300
|
+
});
|
|
301
|
+
const response = await axios.get(url);
|
|
302
|
+
console.log(response.data);
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
As always, in order to see how file uploads and downloads work in the Transifex API, you should check out the API documentation.
|