Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Export TermCollection as TBX

Request

GET editor/languageresourceinstance/tbxexport

ParamscollectionId Required. Id of a TermCollection to be exported.

tbxBasicOnly=(0|1) Required. Whether to export only TBX Basic standard attributes + processStatus, rather than all attributes.

exportImages=(0|tbx|zip) Required. Whether to export images:

  • 0 - No. You should explicitly specify that value for this param if you don't want images (if any) to be exported.
  • tbx - Yes, in hex format, embedded in TBX
  • zip - Yes, in media/ folder inside ZIP-archive

Important: response for this endpoint comes with 'Content-Disposition: attachment' HTTP header to provide a direct download of an exported file.

Code Block
languagejs
titleResponse
collapsetrue
raw text/binary contents, depending on whether TermCollection was exported into a tbx or zip file



Export TermCollection as XLSX

Request

GET editor/languageresourceinstance/xlsxexport

ParamscollectionId Required. Id of a TermCollection to be exported.

Important:

response for this endpoint comes

XSLX export is a two-step operation consisting of prepare-step and download-step. 

Prepare-step may take a while depending on TermCollection size, and is implemented in a way that allows to track the preparation progress measured in percents of already exported term entries vs total term entries in that TermCollection, so progress is printed during the export.

Code Block
languagejs
titleResponse
collapsetrue
Total number of term entries: 1
Starting export...
Progress: 0%
..
Progress: 95%
Progress: 100%
Preparing the download...
Done in 2.35 sec

Once export is Done, browser page is reloaded with javascript and the download is started - so yes - all this is intended to work via browser.
For getting the same result via REST API some important things need to be considered:

Example 1: REST API request via curl-command

Step 1: curl -c cookies.txt http://yourTranslate5app.com/editor/languageresourceinstance/xlsxexport?collectionId=XXX

This is the first needed request, that starts and keeps session and shows the progress as pure HTML code during execution (see below)

Code Block
languagejs
titleResponse
collapsetrue
<pre>Total number of term entries: 1</pre><pre>Starting export...</pre><pre>Progress: 100%</pre><pre>Preparing the download...</pre><pre>Done in 0.078 sec</pre><script>window.location=window.location</script>

 - step 2: curl -c cookies.txt -o file.xlsx  http://yourTranslate5app.com/editor/languageresourceinstance/xlsxexport?collectionId=XXX

This is the second needed request that preserves the session and responses with 'Content-Disposition: attachment'

HTTP header to provide a direct download of an exported file.

header and raw file data as response body, which is saved into file.xlsx on your local computer from where you call the curl-command

Example 2: REST API request via php curl - see both steps below

Code Block
language
js
php
titleResponse
linenumberstrue
collapsetrue
<?php

$url = 'http://yourTranslate5app.com/editor/languageresourceinstance/xlsxexport?collectionId=XXX';
$cookie = __DIR__ . '/cookies.txt';

// 1. First request – simulate progress
curl_setopt_array($ch1 = curl_init(), [
    CURLOPT_URL => $url,
    CURLOPT_COOKIEJAR => $cookie,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_WRITEFUNCTION => function($ch, $data) {
		
		// Print immediately during progress
        echo $data; 
		
		// Tell curl all is ok for now, as otherwise curl will stop the execution
        return strlen($data); 
    },
]);
curl_exec($ch1);
curl_close($ch1);

// 2. Second request – simulate reload to start download
curl_setopt_array($ch2 = curl_init(), [
    CURLOPT_URL => $url,
    CURLOPT_COOKIEFILE => $cookie,
    CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch2);
curl_close($ch2);

// Save downloaded file locally
file_put_contents('file.xlsx', $response);