With the Lilt REST API, you can easily automate the upload, translation, and download of files, in this simple, 3 step process.
Note: To be able to make use of the File Translation API, you must have access to your API key, which is only available to business accounts. See how to obtain your API key here.
To upload a file via the API, you must make a POST request, commonly made via the command line tool curl. To make this request, you need to know your API key, and the path of the file you'd like to upload (for example: C:/Users/Example/Documents/example.txt). There are additional options listed in the documentation.
If you have correctly uploaded the file, you should receive a response confirming all the options you indicated in the upload process, as well as a file ID number, denoted by "id". To have Lilt translate the document you uploaded, you will have to make another POST request using the ID you received, your API key, and the Memory ID being used to translate.
To obtain the Memory ID, first navigate to the Memories tab in Lilt. You will see a list of all your memories, and their ID numbers.
The curl command to start the translation should look something like this
curl -X POST "https://lilt.com/2/translate/file?fileId=[FILE ID]&memoryId=[MEMORY ID]&key=[KEY]"
in which [FILE ID], [MEMORY ID] and [KEY] are replaced by the file ID, Memory ID and API key respectively. If you wish to begin multiple translations at once, write in each of the file IDs, separated by comma.
Note: You may be asked to include a Content-length header. If this is the case, simply append
to your command.
Once a file has been sent off for translation, you will receive another response listing the options you gave, as well as a translation ID, simply listed as "id" in the response. Note that this is distinct from the file ID, which you received when you first uploaded the file.
Checking File Translation Status
If you are uploading and translating a large amount of, or very large, files, it can be useful to check whether they have been translated yet. More importantly, if you wish to automatically download them, you don't want to download them before they have been translated. To check if a file has been translated, you will need your API key, and the file's translation ID, which you should have received from the response when you started the file's translation.
The curl command to get the status of the file should look something like this
curl "https://lilt.com/2/translate/file?&key=[KEY]&translationIds=[TRANSLATION IDS]"
Where [KEY] is your API key and [TRANSLATION IDS] are the IDs from any number of translations which have been initiated. For multiple values, separate by comma.
The response will include the translation ID, file ID and status (either
ReadyForDownload), as well as the time at which it was created in Unix time.
Once a file has been marked as "Ready For Download", you can download it with the following command.
curl "https://lilt.com/2/translate/files?id=[TRANSLATION ID]&key=[KEY]" > [DESTINATION_FILE]
In which [TRANSLATION ID] is the translation ID of the file received when the translation was initiated, [KEY] is your API key, and [DESTINATION_FILE] is the name of either an existing you wish to overwrite, or a new file you wish to create.