Skip to content

Manual describing how to set up automatic translation of site pages in SharePoint.

License

Notifications You must be signed in to change notification settings

tomasszabo/sp-automatic-translation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SharePoint: Automatic Site Pages translation to different languages

This manual describes how to set up automatic translation of site pages in SharePoint.

How it works?

SharePoint multilingual feature enables management of site page translations. It adds new button Translation where pre-defined language translation can be created.

SharePoint mutlilingual feature

When a translation is created, a copy of the site page is created in corresponding subfolder...

Translations in subfolder

...and select menu allows to switch between different translations of the site page.

Language switching

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.

What is needed?

  1. SharePoint multilingual feature
  2. Azure Active Directory application registration
  3. Azure Conginite Services: Translator
  4. Azure Function App
  5. SharePoint Flow

Installation

1. SharePoint multilingual feature

Enable SharePoint multilingual feature as defined in documentation.

Note down your SharePoint tenant e.g., xyz.onmicrosoft.com.

2. Azure Active Directory application registration

Interactive way

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.

Command line way

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

3. Azure Translator

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).

4. Azure Function App

Create Function App

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

Function App Configuration

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.

Create function

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.

Function Code

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.

5. SharePoint Flow

Open the site in SharePoint and select Pages from top menu. Now from second level top menu open Automate > Power Automate > See your flows.

Create connection

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.

Create Flow

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:

Flow steps

1. When a file is created (properties only)

First step is the trigger when the flow starts.

When step

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)

2. Compose

Folder name equals to the translator language code and we can extract it from the site page path.

Compose step

Add following expression into Inputs:

replace(replace(triggerBody()?['{Path}'],'SitePages',''),'/','')

3. Initialize variable

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:

Initialize variable step

4. HTTP

Last step is to call the Azure Function App.

HTTP step

Use following properties/values for HTTP step:

Property Value
Method POST
URI Function URL from Create function
Headers
KeyValue
Content-Typeapplication/json; charset=UTF-8
Body Output from previous step

NOTE: Don't forget to save changes.

Run

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.

Troubleshooting

Go to SharePoint flow to access logs of the flow or to Azure Function and select Monitor to access logs of the function.

Limitations

SharePoint multilingual feature is available only for Communicaion Sites (not for Team Sites).

License

Distributed under MIT License. See LICENSE for more details.

Thanks

This manual is based on work of Michal Sacewicz.

About

Manual describing how to set up automatic translation of site pages in SharePoint.

Topics

Resources

License

Stars

Watchers

Forks