While Contentstack does not offer translation services, it offers easy integration with third-party translation providers. In this guide, we will learn how to set up a translation system using Contentstack's webhook and workflows along with AWS Lambda and AWS Translate.
Here's a quick overview of the process: When the workflow stage of entry in the master locale changes to "Send to Translation", a webhook is triggered, which invokes an AWS Lambda code. This code translates content using AWS Translate and then localizes the entry with the translated content using a Content Management API request. This also changes the workflow stage status of the entry to "Review Translation.
Here are the steps to set up this translation solution:
- Set up the essentials
- Set up workflows for translation
- Set up Lambda function for translation
- Trigger a webhook to initiate translation
- Working knowledge of AWS API Gateways
- Access to the AWS environments such as AWS Lambda, AWS API Gateway, and AWS IAM
- Contentstack account
Step 1 Set up the Essentials
First, create a stack, and add a content type (in our example it is Product), add entries to it, at least one additional language, and a publishing environment.
Once you have these configured, then you're ready to begin the integration process for translation.
Step 2 Set up Workflows for Translation
To set up workflows for the translation process within Contentstack, follow the below steps:
- Create a workflow by navigating to the settings icon > Workflows > Add Workflow.
- Add stages, as required. Add a translation-related stage, such as Send to Translation.
Read more on how to set up workflows.
Once the editor changes the workflow stage to "Send to Translation", the webhook will be triggered and call the AWS Lambda function.
Step 3 Set up Lambda Function for Translation
Perform the following steps to set up your AWS Lambda function:
- Login to your AWS Management Console, select AWS Lambda Service from the service list.
- Click on the Create Function button, and then the Author from Scratch option.
- Configure the lambda based on your requirements. Choose Node.js as your run-time language.
Note: You can use any language instead of Node.js. You can also add triggers to your lambda to push an event to SNS when the lambda is invoked.
- AWS Lambda offers an inline code editor. You can write your lambda code here or alternatively upload the code. For our example, we will upload the code due to the large size. To get the sample code, contact our support team at firstname.lastname@example.org.
- In the Environment variables section, enter the credentials against the variables as follows:
x-api-key = ABCD (applicable if you have added it to the API Gateway)
role_name = french translation reviewer
workflow-stage-uid = 1234
role = ABCD1234
- In the Lambda function handler and role, keep the index.handler as Handler and for the Role choose an existing role or create a new role from template(s).
- Review your setting and click on the Create Function option if everything you entered is correct.
Once you do this setup, AWS Lambda will run the code that we have uploaded and translate the English content into French and will deliver the translated content to your content type. The workflow stage of the translated entry also changes to Ready for Review.
Step 4 Trigger a Webhook to Initiate Translation
We will now set up a webhook that triggers when the entry workflow stage is set to Send to Translation.
Let’s have a look at the steps involved in creating a webhook to send content for translation.
- Create a webhook by navigating to the settings icon > Webhooks > + New Webhook.
- Enter any valid name for your webhook, for example, AWS Lambda For Translation.
- In the URL to notify field, enter the AWS Lambda URL, where the webhook will notify about the change.
- Under the When section, select the options Any > Entry > All > Workflow Stage Changed > (Workflow name) > (Stage name for example, "Send to Translation").
This will configure your webhook to trigger on a workflow stage change such as "Send to Translation", like in the above workflow example. As soon as the webhook is triggered, it notifies the specified URL about the event along with a JSON payload.