This manual describes how to set up automatic translation of site pages in SharePoint.
SharePoint multilingual feature enables management of site page translations. It adds new button Translation
where pre-defined language translation can be created.
When a translation is created, a copy of the site page is created in corresponding subfolder...
...and select menu allows to switch between different translations of the site page.
By default, each translation must be translated and published manually. By creating a SharePoint Flow and Azure Function, it may be automatically translated using Azure Translator and published for the audience.
- SharePoint multilingual feature
- Azure Active Directory application registration
- Azure Conginite Services: Translator
- Azure Function App
- SharePoint Flow
Enable SharePoint multilingual feature as defined in documentation.
Note down your SharePoint tenant e.g., xyz.onmicrosoft.com
.
Add application registration as defined in documentation. This app registration will be used by Azure Function App to connect to SharePoint and read/write translated site pages.
NOTE: Certificate is needed to access SharePoint from Azure Function App, Password is not enough.
Once app registration and certificate is created, go to this registration and note down Application (client) Id
(to be found in Application > Overview
) and save Certificate used in credentials.
Go to Manage > API Permissions
and check if sucessful right are delegated to app registration.
Add application registration using following PowerShell commands from PnP PowerShell module.
First install PnP PowerShell module:
Install-Module -Name "PnP.PowerShell"
Then add application registration and follow the instruction:
$result = Register-PnPAzureADApp -ApplicationName "YOUR_APP_NAME" -Tenant YOURTENANT.onmicrosoft.com -OutPath c:\mycertificates -DeviceLogin
Last, display and note down base 64 encoded certificates private key:
$result.Base64Encoded
Deploy (create) Translator from Azure Cognitive Services into your Azure Subscription.
Once Translator is deployed, go to this resource in Azure Portal and note down Key
and Location/Region
(to be found under Resource Management > Keys and Endpoint
).
Deploy (create) Function App into your Azure Subscription.
Use following properties/values when creating Function App:
Property | Value |
---|---|
Publish | Code |
Runtime stack | PowerShell Core |
Plan type | Consumption (Serverless)* |
* Select according to your planned load
Once Function App is deployed, go to this resource in Azure Portal, select Settigns > Configuration
and add following environment properties (case sensitive):
Property | Value |
---|---|
ClientId | Application (client) Id from AD application registration |
ClientSecret | Base64 encoded certificate's PFX file with private key or PnpPowerShell registration Base64 encoded private key from AD application registration step |
TranslatorKey | Key from Translator |
TranslatorRegion | Location/Region from Translator |
Tenant | SharePoint tenant (e.g. xyz.onmicrosoft.com ) |
Open Functions > App files
and select requirements.psd1
from select box. Copy code from function/requirements.psd1
and paste it into Azure Portal.
NOTE: Don't forget to save changes.
In Function App resource in Azure Portal, select Functions > Functions
and then Create
.
Use following properties/values when creating function:
Property | Value |
---|---|
Development env. | Develop in portal |
Template | HTTP trigger |
Authorization level | Function |
Once function is created, function detail will be automatically opened. In Overview
click on Get Function Url
button and note down this URL.
Open Developer > Code + Test
and select run.ps1
from select box. Copy code from function/run.ps1
and paste it into Azure Portal.
Choose function.json
from select box and copy code from function/function.json
and paste it into Azure Portal.
NOTE: Don't forget to save changes.
Open the site in SharePoint and select Pages
from top menu. Now from second level top menu open Automate > Power Automate > See your flows
.
NOTE: If you already have existing SharePoint connection, you can skip this step.
From left menu open Data > Connections
and from top menu click on New connection
. Now choose SharePoint
and create it.
From left menu open My flows
and from top menu open New flow > Automated cloud flow
. Select When a file is created (properties only)
and create.
Entire flow has 4 steps:
First step is the trigger when the flow starts.
Choose Site Address
as the site where you want to enable translations and Library Name
set to Site Pages
(we want to translate only site pages).
As we want to translate only site pages created for translations, we'll be watching for OData__SPIsTranslation
property with value true
. Original (main language) pages have this property set to false
.
Open step menu (three dots in top right corner) and click on Settings
. Add new Trigger Condition
with following value:
@equals(triggerBody()?['OData__SPIsTranslation'],true)
Folder name equals to the translator language code and we can extract it from the site page path.
Add following expression into Inputs
:
replace(replace(triggerBody()?['{Path}'],'SitePages',''),'/','')
Let's prepare JSON input for our Azure Function App. Input has following structure:
{
"language": "language-code-extracted-in-previous-step",
"pageTitle": "name-of-a-site-page",
"siteURL": "your-sharepoint-site-url (e.g. xyz.sharepoint.com/site/CoolSite)"
}
For language
use output from previous step, for pageTitle
use dynamic content Name
and siteURL
is hard coded:
Last step is to call the Azure Function App.
Use following properties/values for HTTP step:
Property | Value | ||||
---|---|---|---|---|---|
Method | POST | ||||
URI | Function URL from Create function |
||||
Headers |
|
||||
Body | Output from previous step |
NOTE: Don't forget to save changes.
When everything is installed and configured, now in SharePoint site page when clicking on Translate
button in top menu, dialog with translations will open.
Clicking on Create
for given language will create a copy of current site page and initiate automatic translation.
After couple of seconds (minutes, depending on load), site page translation will be translated and content in different language can be accessed via top right select menu.
Go to SharePoint flow to access logs of the flow or to Azure Function and select Monitor
to access logs of the function.
SharePoint multilingual feature is available only for Communicaion Sites (not for Team Sites).
Distributed under MIT License. See LICENSE for more details.
This manual is based on work of Michal Sacewicz.