15 49.0138 8.38624 1 0 4000 1 https://vladtalkstech.com 300 1
theme-sticky-logo-alt

Test the Machine Translation Service Application with PowerShell

1 Comment

The Machine Translation Services Service Application is a Service Application that allows users and developers to translate not only sites, but their content as well to other languages. The Machine Translation Services is interacted through APIs, and the users do not have a “Translate Document” button, unless of course, their developers created a custom action for them.

Test the Machine Translation Service Application with PowerShell

As a SharePoint IT Professional, I don’t want to write code simply to test a Service Application. Luckily, PowerShell is there for us! By using PowerShell, we can convert a document from Word to PDF, and test that this service application is working properly!

To test the Machine Translation Service Application works properly, you can run a PowerShell script that uses CSOM to call the required functions. We have created the sample script below.

We first have to get the URL of the site where the document is stored, as well as get the username and password of the user who will request the translation.

$siteUrl = "https://sharepoint.learn-sp2016.com"
$loginname = "corp\vlad"
$language = "fr-fr"
Write-Host "Please enter password for $($loginname):"
$pwd = Read-Host -AsSecureString

We then need to get the current document location in the $input variable, and the new document location in the $output variable

$input = "https://sharepoint.learn-sp2016.com/Shared%20Documents/DocumentToTranslate.docx"
$output = "https://sharepoint.learn-sp2016.com/Shared%20Documents/DocumentFR.docx"
Next, we have to add some DLLs in order to be able to run the Translation Services cmdlets.
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.Office.Client.TranslationServices.dll'

Next up, we connect to our site using CSOM, and start the translation job.

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.Credentials = New-Object System.Net.NetworkCredential($loginname, $pwd)
$job = New-Object Microsoft.Office.Client.TranslationServices.SyncTranslator($ctx, $language)
$job.OutputSaveBehavior = [Microsoft.Office.Client.TranslationServices.SaveBehavior]::AppendIfPossible
$job.Translate([string]$input, [string]$output);
$ctx.ExecuteQuery()

If we put it all together it looks like this:

$siteUrl = "https://sharepoint.learn-sp2016.com"
$loginname = "corp\vlad"
$language = "fr-fr"
$input = "https://sharepoint.learn-sp2016.com/Shared%20Documents/DocumentToTranslate.docx"
$output = "https://sharepoint.learn-sp2016.com/Shared%20Documents/DocumentFR.docx"
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.Office.Client.TranslationServices.dll'
Write-Host "Please enter password for $($siteUrl):"
$pwd = Read-Host -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.Credentials = New-Object System.Net.NetworkCredential($loginname, $pwd)
$job = New-Object Microsoft.Office.Client.TranslationServices.SyncTranslator($ctx, $language)
$job.OutputSaveBehavior = [Microsoft.Office.Client.TranslationServices.SaveBehavior]::AppendIfPossible
$job.Translate([string]$input, [string]$output);
$ctx.ExecuteQuery()

If it finishes sucesfully and you see your  new document, you know what your Machine Translation Service Application works, and you can now let your developers create custom solutions to take benefit from this Service Application.

 

Did you find this article useful?

If yes, you will love Deploying SharePoint 2016: Best Practices for Installing, Configuring, and Maintaining SharePoint Server 2016 written by myself, and SharePoint Server MVP Trevor Seward! Get it now at the links below!
Previous Post
Review of harmon.ie Collage: Bringing a New Outlook to Your Business
Next Post
New Pluralsight Course: Planning for SharePoint Server 2016 – Logical Architecture and Integrations

1 Comment

Leave a Reply