Translate a published page via a flow

Recently I was working on a SharePoint Online multilingual project. This motivated me to look into the current set of translation capabilities of SharePoint Online. This article demonstrates a simplified setup of automated SharePoint Online page translation via a Power Automate cloud flow.

Setting the Scene

My experience with translation features primarily comes from the SharePoint Server days. In other words, I was managing several Farm topologies which used the variations feature back in the day. Without going into the details it was imho not the most user friendly feature in SharePoint Server 2013 😉

But a lot has changed since those days so why not give translation features a second change?

In my setup I was dealing with a site with two languages. The primary language was English and Dutch was enabled on the site as well. This gives you the ability to create a Dutch page for every English page.

germantranslation

However, that also means a Translator (person) needs to edit these pages manually. The idea is to automate this via a Power Automate cloud flow, sounds doable, right?

The process steps

flowchart_pagetranslation

Trigger Conditions

The first step was already pretty challenging. In my use case I wanted the flow to be only triggered once for a published page (in other words, only a .0 major version). This could be done by checking the {VersionNumber} property.

Additionally, the flow shouldn’t be started for a page which already had been translated before, this could be done by checking the OData__SPTranslatedLanguages property.

And lastly we don’t want to retrigger the flow for the translation pages itself. The could be done by checking if published page itself isn’t a translation page via the OData__SPIsTranslation property.

Translation of Text

For the translation of the text on the page the flow is using the CanvasContent1 property of the published page. It inspects if it contains text and uses the AI – Translate Text (Single) action of Encodian. Obviously, other services are available to translate text, Encodian is just used as an example. Also be aware this action requires an Encodian subscription and also additional cost might be involved.

After the translation the CanvastContent1 array is rebuild with the translated text and the translation page will be updated with the new text.

Sounds easy, right? Lets dig into the details of the flow to achieve this.

Flow Setup

In this example only one additional language has been enabled (Dutch) besides the primary language (English). When you have more languages you would need to update the logic to loop through all translation pages.

translatenewpublishedpage

1. Add a When an item or a file is modified action.
This first action checks if a page is published and it doesn’t have a translation yet.

triggercondition_newpublishedpage

a. Select your preferred site in the Site Address
b. Use Site Pages as a custom value in the List or Library Name
c. In the Settings use the expression from code snippet below in as a Trigger Condition

2. Add a Initialize Variable action.
The array variable is used to store both the content which doesn’t need translation and the translated text of the web parts on the page.

initializevariable_translatedcanvascontent1

a. In the Name field use TranslatedCanvasContent1
b. Select the Type Array
c. Add [] as the value

3. Add a Get my profile (v2) action (optional).
This action was used to get the email of my own account.

getmyprofile_translated

4. Add a Send an HTTP request to SharePoint action.
This request is used to get the Language and the CanvasContent1 of the published page.

getpagedetails

a. Select your preferred site in the Site Address
b. Use the GET method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

5. Add a second Send an HTTP request to SharePoint action.
This second request is used to create translation pages for all languages enabled on the site. I have a separate Create Translation Pages for All Languages blog for this in my SharePoint Online cookbook as well.

createtranslationforalllanguages

a. Select your preferred site in the Site Address
b. Use the POST method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

e. Use the Body from the code snippet below

6. Add a third Send an HTTP request to SharePoint action.
This third request is used to retrieve the details of the newly created translation page. The response of the previous action is pretty limited, for example it doesn’t include the ID of the page.

gettranslationpage

a. Select your preferred site in the Site Address
b. Use the GET method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

7. Add an Apply to each action.
This action is used to loop through the items of the CanvasContent1 array.

applytoeach_canvascontent1

a. Use the expression from code snippet below in the Select an output from previous steps field

8. Add an Condition action (within the Apply to each).
This action is used to check if any InnerHTML/Text is available for translation. If that is not the case the item would be ignored and not translated.

innerhtml_condition

a. As a condition expression use the InnerHTML property of the item is not equal to null

9. Add an AI – Translate Text (Single) action (in True section).
This fourth request is used to update the file property but doesn’t include the sharedLockId property.

aitranslatetext

a. Use the InnerHTML in the Text field
b. Use the primary language in the Source Language, in this example English
c. Use the second language in the Target Language, in this example Dutch

10. Add an Append to array variable action (in True section).

replacebytranslatedcontent

a. Select the TranslatedCanvasContent1 variable
b. Use expression from the code snippet below for the value

11. Add a second Append to array variable action (in False section).

nothingupdated

a. Select the TranslatedCanvasContent1 variable
b. Use expression from the code snippet below for the value

12. Add a fourth Send an HTTP request to SharePoint action.
This fourth request is to checkout the page

checkoutpage_translated

a. Select your preferred site in the Site Address
b. Use the POST method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

13. Add a fifth Send an HTTP request to SharePoint action.
This fifth request is to update the page with the translated content.

savepage_translated

a. Select your preferred site in the Site Address
b. Use the POST method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

e. Use the Body from the code snippet below

14. Add a sixth Send an HTTP request to SharePoint action.
This sixth request is to publish the page.

publishpage_translated

a. Select your preferred site in the Site Address
b. Use the POST method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

That is it for the cloud flow setup of this example. Hopefully it is useful to get started with translation of pages. Let me know in the comments what you think of this approach?

You may also like...

2 Responses

  1. Have you looked in the multilingual functionality of PointFire from a company called Icefire?

    The process is simpler and faster.

  2. Dennis says:

    Hi Jacques,

    No I haven’t looked into your product. I will have a proper look into the added value/features of PointFire. Thanks for sharing.

    Out of interest, what process/specific part of PointFire is simpler and faster?

    Generally speaking I need to have a good use case to add a third party app to a SharePoint Online environment. A third party app normally requires effort and cost as well. I see PointFire 365 is $850/year for up to 100 users and you have to install and maintain a custom app in the app catalogue as well.

    So, typically I prefer to use the native features of the platform first. But again, it all depends on requirements.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.