Translating Content Automatically In Agility CMS

Follow

Introduction

Since Agility CMS is an API-driven platform, you can use tools like Zapier to automate tasks that you do all the time.

In this case, we're going to automate the translation of content.  Specifically, we will be translated a Blog Post from English to French. Before we do anything, let's plan out what's going to happen:

  • The user saves a Blog Post in English
  • If the item hasn't been translated to French yet, translate it
  • Notify the user that the item has been translated.

Setup Your Environment

Free Blog Account

In this example, we'll be using the content modelling from the NextJS Blog Starter, which you can find here.  Sign up for a new free account using that.  Don't worry about deploying to a hosting environment - we can do that later.

Add the French Language

The starter site gives you a single language, en-us, so let's go to the Settings section and add a new language. 

In the Content Manager, click on Settings | Languages and then click on the (+) sign to add a new Language. 

Screen_Shot_2021-02-08_at_12.22.17_PM.png

For this example, we'll be using French as the language name and fr-ca as the language code.

Configure Zapier

Zapier works great with Agility CMS.  Let's open zapier.com and make a new automation, which they call a "Zap." Our Zap will have the following logic:

  1. Trigger whenever a content item is saved in your Agility instance
  2. Only proceed if the content is a blog post in English
  3. Only proceed if the content has not been saved in French yet
  4. Translate the title and content fields
  5. Save the post in Agility in French.

Let's do this!

Trigger

The first thing we need to do is trigger an event in Zapier when someone saves an item.  Let's choose Webhook as the trigger, and choose Catch Raw Hook as the trigger event.

Screen_Shot_2021-02-08_at_12.30.13_PM.png

The next thing you'll see is the Webhook URL.  Go ahead and copy that value to your clipboard, and navigate back to the Agility Content Manager.  

Go to the Settings | Webhooks section.  Here you can create a new Webhook that will trigger our Zap.  Click the (+) button and paste in the URL that you copied earlier. You should also choose the option to Receive Content Save Events

Screen_Shot_2021-02-08_at_2.45.42_PM.png

Save that webhook.  Now we can navigate to the Content section in Agility and save a new blog post in English.  You can keep it short and sweet - this is just a test post. Agility will send a message to Zapier.

Back in the Zapier configuration, click on the Test Webhook button in the Set up Webhook section.  You should see something like the image below.

Screen_Shot_2021-02-08_at_2.58.48_PM.png

Go ahead and click Continue. 

 

Parse the Hook

Now we need to parse the body of the Webhook.  We'll use a small snippet of code to do that for us.

Add a Code By Zapier action and choose Run Javascript as the event, then click Continue.

Screen_Shot_2021-02-08_at_3.07.28_PM.png

Next, add webhookBody as the Input Data name, and in the value section select the 1. Raw Body output from the previous action.

In the Code section  paste the following value:

output = JSON.parse(inputData.webhookBody);

You should have something that likes this:

Screen_Shot_2021-02-08_at_3.08.56_PM.png

Click Continue, then click Test & Continue.

Setup a Filter 

We only want to operate on the following content items: English items in the Blog Posts list.  Let's create a filter for that.  Choose Filter as the action type on the next action.

In the Filter setup & testing section, add the following items.

  • Reference Name exactly matches posts
  • Language Code exactly matches en-us
  • State exactly matches Saved.

In the first field column, you will be able to choose the outputs of the previous action.

Screen_Shot_2021-02-08_at_3.19.35_PM.png

Check for the Item in French

We only want to do this work if we need to, so if the item already exists in French, we don't want to continue. This is where we need to connect Zapier directly to our Agility instance.

In the next action, choose Agility CMS as the app.  Click Sign in to Agility CMS.  In the screen that pops up, copy and paste the values that are in your Settings | API Keys screen in the Content Manager.

It should look something like this:

Screen_Shot_2021-02-09_at_10.16.41_AM.png

Take care to make sure you all the right keys into the right fields, especially the Preview and Fetch API keys.

Once you get everything copied into those fields, click Yes, Continue.

Now you can select that account as the one you want to use here and click Continue.

Screen_Shot_2021-02-08_at_3.30.57_PM.png

Let's set up this action! 

We want to check that the item hasn't been saved in French.  Choose Preview, enter fr-ca for the language, and link the Content ID field to the Content ID output from parse action.

Lastly, under "Should This Step Be Considered A "success" When Nothing Is Found?", choose True - we only want to continue if this action doesn't return anything.

You should end up with something like this:

Screen_Shot_2021-02-08_at_3.33.41_PM.png

Let's click through to the next action!

Get the Item in English

This step is almost exactly the same as the one above, except this time we're going to be accessing the item in en-us, and we only want to continue if we get the item. All the other fields are the same as above.

You should end up with something like this:

Screen_Shot_2021-02-08_at_3.40.35_PM.png

 

Let's Translate!

Now we're going to translate the title field.   In the next action, choose Translate by Zapier as the action type.  For the Action Event, choose Translate Text

Screen_Shot_2021-02-08_at_3.43.58_PM.png

Next, in the action setup screen, choose English as the Source Language, map the Text field to the Title field that was returned from Agility CMS above.  

You should end up with the following:

Screen_Shot_2021-02-08_at_3.46.24_PM.png

Next, we'll translate the Content field.  The steps are almost the same as above, except you'll choose the Content field as the text.  Note that the Zapier translate action is limited to 1000 characters.  If you need to translate more text, you can choose another translation service.

Screen_Shot_2021-02-08_at_3.48.00_PM.png

Save the Item in French

Now that we've got everything translated, we can save it into Agility in French. 

In the next action, choose Agility CMS as the app, and Save Item as the Action Event.

Screen_Shot_2021-02-08_at_3.51.40_PM.png

This action has quite a few inputs to fill out, so take this one carefully.

  • Choose the Content ID output from the parse action for the Content ID.
  • Enter fr-ca for the Language Code.
  • Enter Posts for the Reference Name.
  • For the Fields, enter the following values:
    • Title: choose the title translation output from step 6.
    • Content: choose the content translation output from step 7.
    • Slug: choose the Slug field value from step 5.
    • Date: choose the Date field value from step 5.

Phew! After all the setup, you should see something like the following:

Screen_Shot_2021-02-08_at_3.54.01_PM.png

When you click Continue, you should something like this, which will confirm whether you're on the right track.  You should be able to see what the field values are that will be saved into Agility.

Screen_Shot_2021-02-08_at_4.01.07_PM.png

Click Test & Continue and the item should be saved into Agility.  You can check in the Content Manager if the item is there by switch the language toggle to French.  The Zapier screen should look something like this:

Screen_Shot_2021-02-08_at_4.03.21_PM.png

Now, if you're all good with that, you can go ahead and click Turn on Zap.  If you want to kick things up a notch, click Close on that action and add another action.

Send a Notification

If you're like me, you like to know when things are working! Let's send a message when this translation is completed. This could be useful as a note to yourself, or maybe a notification to a team member.

We use Slack for messaging, so I'll choose the Slack Message action.  You may have to connect the account to your Slack account.  Once you get there, you can tailor the message specifically to what just happened.  

Here's what my message looks like:

Screen_Shot_2021-02-08_at_4.10.10_PM.png

Once you click Test & Continue, you should get a message that looks something like this:

Screen_Shot_2021-02-08_at_4.11.17_PM.png

Nicely Done

That's it!

You've got everything configured to translate items in Agility CMS. 

You can go ahead and click Turn On Zap and data will start being translated automatically.

You can take this as a starting point for other automations in Zapier as well, for instance, if you want to translate to other languages in addition to French.

 

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.