Intro
Welcome to part 2 where I’ll dive into creating and configuring two Power Automate Flows. These flows are doing the heavy lifting of communicating with SharePoint Online, Azure Translator Service, and Azure Blob Store transfer blob content as well as calling the Azure Translator Document Translation Rest API to perform translation of the new document. Both Power Automate flows leverage connectors to facilitate the calls necessary for translation to succeed. This solution will automatically translate documents from the source language to a new document in the preferred language. The Power Automate Actions will be leveraging Power Automate Connectors
For Example:
Step 1: User 1 uploads document authored in English azureblobstorageblog.docx to a SharePoint Document Library (TranslateDocLib)
Step 2: User 1 waits for a period of time and then opens the translated folder and a new word document with the same name is present.
Step 3: User 1 opens the document and it’s in Japanese
This is really cool that I can automatically have document translation in place. Before going through the setup of two Power Automate flows, I recommend reviewing my Intro to SharePoint Online Document Translation Part 1 blog to get a better understanding.
My Azure Setup
I have an Azure Resource Group provisioned that contains a storage account and Azure Translator Resource. Next, I’ll grab the properties from these Azure resources.
Azure Translator Resource
- Name: translateTime
- Access Key
Note: During the provision of Azure Translator Resource or if it’s already provisioned, you’ll need to configure as managed identity (system assigned: on)
Azure Storage Account
- Storage Account Name: azspostorage
- Blob Storage Container Name: azspostore
- Storage Account Access Key
Note: Azure Translator Identity is assigned Storage Blob Data Contributor Role. The folder names within the Azure Blob Storage container are not required as Power Automate will facilitate the creation of those folders.
My SharePoint Online Setup
SharePoint Team Site
- SharePoint Site: https://406z05.sharepoint.com/sites/SampleTeamSite
- Document Library: TranslateDocLib
- Subfolder: Translated
Setup Power Automate Connections
I will use the Azure Blob Storage Connector and SharePoint Online Connector for both Power Automate Flows.
Setup SharePoint Connection
1. Authenticate to https://us.flow.microsoft.com
2. From Navigation panel on the left, Access Data\Connections and click Create a Connection
3. From top right search box, type SharePoint and click the plus sign next to SharePoint Connector
4. Select “Connect directly (cloud-Services) and hit Create
5. When prompted, enter your credentials to establish an Oauth connection to SharePoint Online.
Note: After success, my connection looks like
Setup Azure Blob Storage Connection
- Authenticate to https://us.flow.microsoft.com
- From Navigation pane on the left, Access Data\Connections and click Create a Connection
- From top right search box, type Azure Blob and click the plus sign next to Azure Blob Storage
- Enter Azure Storage Account name, associated access key, and hit create
I now have two connections present:
Setup Contoso-Translate Power Automate Flow
I’ll create a simple 4 step flow that will pick up new documents from SharePoint and place them in Azure Blob Store. Finally, it will call Azure Translator service to perform Document Translation.
Step 1: SPO – When an Item is created
A trigger is chosen to start the flow after a user uploads a document to the specified document library
- Within https://us.flow.microsoft.com, select My Flows from the navigation pane.
- Select + New flow and click Automated cloud flow
- From Build an automated cloud flow window fill out the following fields:
Flow name: Contoso-Translate
Chose your flow’s trigger: When an item is created (SharePoint) - Click create and enter the SharePoint Site and populate the Document Library where document translation will occur:
Step 2: SPO – Get file content using path
This will fetch the file content from SharePoint.
- Click + New Step and type “get file content” in the search bar
- Under actions tab, select Get file content (SharePoint)
- Populate the Site Address Field where document translation will occur
- Double-click the File Identifier field and under dynamic content winodw, search full path
- Click Full Path and this step is complete and should look like:
Step 3 – Azure – Create blob (V2)
This will create a blob representation of the newly created document in Azure Blob Storage
1) Click + New Step and type “create blob” in the search bar
2) Under Actions tab, select Create blob (V2) (Azure Blob Storage)
I filled out the following fields:
- Storage Account Name: Select the pull down and click “Use connection settings (storage account name)
- Folder Path: type in the container name followed by the folder name. In my example, I entered /azspostore/translatetodo/
- Blob name: double-click the field which will enumerate dynamic content window and within this window search File name with and select File name with extension
- Blob Content: double-click the field and under dynamic content window, search File Content and select “File Content“
The step is complete and should look like the following:
Step 4 – HTTP (call into Document Translation Rest API)
This will call the Document Translation Rest API where the following attributes are required:
- Header Section – Ocp-Apim-Subscription-Key: this is the access key to the designated Azure Translator Resource
- Body: Source location of file to pickup for tranlsation
- Body: Destination location: where to put the newly created translated document
- Body: Language – desired language
1) Click + New Step and type “http”. Click HTTP under actions tab
2) Fill out the following fields:
- Method: Post
- URI: https://<azuretranslatorserviceresourcename>.cognitiveservices.azure.com/translator/translator/text/batch/v1.0/batches
Headers Section
- Ocp-Apim-Subscription-Key: <Azure Translator Resource Access Key”>
- Content-Type: application/json
- Content-Length: 626
So far it looks like:
Body Section
I copied the following JSON into the body section:
{
"inputs": [
{
"storageType": "File",
"source": {
"sourceUrl": "https://<storageaccountname>.blob.core.windows.net@{outputs('Create_blob_(V2)')?['body/Path']}"
},
"targets": [
{
"targetUrl": "https://<storageaccountname>.blob.core.windows.net/<blob-container>/translatedone/@{triggerOutputs()?['body/{FilenameWithExtension}']}",
"language": "ja"
}
]
}
]
}
Source URL Note: Updated <storageaccountname> with my Azure Storage Account Name.
Target URL Note: Updated <storageaccountname> with my storage account name. Update <blob-container> with my Azure blob container name.
Language: update language to ja for Japanese translation.
My body looks like the following:
The first flow is complete so save it and navigate back to My flows and continue to the next flow.
Setup Contoso-Translate-Done Power Automate Flow
Here, I’ll create a simple 3 step flow that will pick up newly translated documents from Azure Blob Storage after Azure Translate Service completes translation. It will place the file in a SharePoint Document Library subfolder.
Step 1: When a blob is added or modified (properties only) (V2)
This is a trigger to start the flow after Azure Translation Service creates the translated document in Azure Blob Storage.
1) Within https://us.flow.microsoft.com, select My Flows from the navigation pane.
2) Select + New flow and click Automated cloud flow
3) From Build an automated cloud flow window, filled out the following fields:
- Flow name: Contoso-Translate-Done
- Choose your flow’s trigger: When a blob is added or modified (Azure Blob Storage) and click Create
4) Fill out the following fields:
- Storage Account name: select the pull down and click “Use connection settings (storage account name)
- Container: type the Azure Blob Storage Container and folder that will contain translated documents. For Example: /containerName/folderName
Step 2: Azure – Get blob content using path (V2)
This step grabs the blob content from Azure Blob Storage.
- Click + New Step and type “azure blob content using path” in the search bar
- Under Actions tab, select “Get blob content using path (V2)
- Fill out the following fields:
- Storage Account name: select the pull down and select “Use connection settings (storage account name)“
- Blob path: double-click this field and under Dynamic content window, type “Path” and select it
Step 3: SharePoint – Create File
- Click + New Step and type “create file” and select “Create File (SharePoint)“
- Fill out the following fields:
- Site Address: Enter SharePoint Online Site
- Folder Path: Enter Document Library and subfolder (/documentlibrary/translated)
- File Name: double-click this field and under Dynamic Content window type “Name” and select it.
- File Content: double-click this field and under Dynamic Content window type “File Content” and select it.
Hit the save button for this flow and it’s now complete!
Turn on or Test Power Automate Flows
This is the fun part where your hard work of setup is about to pay off. Looking at my completed flows:
I’m in a test Tenant so just turned each flow on by clicking the ellipsis next to each flow and click “Turn on”.
Going to my SharePoint Document Library and adding another document “azureblobstorageblog.docx” that’s authored in English.
Checking the run history of my Contoso-Translate Flow and things look good:
Waited for 5 minutes and checked the run history of Contoso-Translate-Done flow and all green checks
Checking the translated folder within the Document Library and the translated document is present.
Opening the document and success:
Resources
Document Translation – REST API (Azure Cognitive Services) | Microsoft Docs
Document Translation is generally available now – Microsoft Tech Community
Authorize requests to Azure Storage (REST API) | Microsoft Docs
Authentication – Azure Cognitive Services | Microsoft Docs
Azure Blob Storage – Connectors | Microsoft Docs
Thank You,
Russ Maxwell, Microsoft