Instant Translate
In this walkthrough we will demonstrate how to use the LILT API Instant Translate functionality. Instant translate is a powerful way to use LILT's Transformative AI to translate your content quickly and accurately without having to wait for a human to verify the results.
Things you will need:
- API Key - All requests throught the LILT API use the API Key to authenticate.
- File to Translate - We recommend a simple text file (txt) for a first attempt.
- Memory ID - A LILT Data Source's memoryId to use with the translation - Create one here!
File Upload
A common step in many Lilt processes is going to be uploading a file. Before most operations involving translation you will need to upload a file and retain a fileId for further processing. Step 1 is to upload your text file into Lilt, you can do this with a POST call to the files endpoint which will allow you to upload a file. See the API docs for more info
curl -X POST https://api.lilt.com/v2/files?key=API_KEY&name=testfile.txt \
--header "Content-Type: application/octet-stream" \
--data-binary @testfile.txt
Once you make the API call you should see a 201 Created status code and a response object that gives you the fileId:
{
"id": {Your File Id here},
"name": "testfile.txt",
"file_hash": "3858f62230ac3c915f300c664312c63f",
"detected_lang": "en",
"detected_lang_confidence": 0.7,
"category": "REFERENCE",
"labels": [],
"created_at": "2024-02-16T22:12:34.000Z",
"updated_at": "2024-02-16T22:12:34.000Z"
}
Translate File
Now that you have a file saved in LILT, let's translate it! To run an instant translation for a single file you will need to use the translate file endpoint. The end point below will translate your file, using the provided memoryId, fileId. File Translation is an Asynchronous process.
curl -X POST 'https://api.lilt.com/v2/translate/file?key=API_KEY&fileId=123&memoryId=1234'
The response will be a status object that looks like this:
{
"id": 1,
"fileId": "2,",
"status": "InProgress",
"createdAt": 1609357135
}
Monitor Translation
Now that you have the translation id, you can call the monitor endpoint to get the current status of your translations. You can ask for status for any number of translations at a time, we recommend bundling these translationIds together.
curl -X GET 'https://api.lilt.com/v2/translate/file?key=API_KEY&translationIds=1,2,3,4'
The response to the Monitor end point will look the same as the POST call you made earlier. The status might be different. Here are the statuses you can expect to see:
InProgress
- The Translation has begun!Completed
- Translation is Complete but not yet ready for download.Failed
- The Translation was unsuccessful. 🙃ReadyForDownload
- The Translation was Complete and is available for retrieval.
Download Translated File
Once you have the green light to download the translated file you can call the download endpoint. This endpoint only allows for downloading one file at a time.
curl -X GET 'https://api.lilt.com/v2/translate/files?key=API_KEY&id=1'
The response to this end point will be your content translated into whatever language you picked for the Data Source!
Notes
The end points described above have additional features, but we don't recommend them for most users. If you are curious, feel free to take a look at the API Specification.