Tuesday, October 4, 2016

Test the Machine Translation Service Application with PowerShell

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 = "http://ift.tt/2chXCin"
$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 = "http://ift.tt/2dq29U1"
$output = "http://ift.tt/2dPGxia"
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 = "http://ift.tt/2chXCin"
$loginname = "corp\vlad"
$language = "fr-fr"
$input = "http://ift.tt/2dq29U1"
$output = "http://ift.tt/2dPGxia"
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!

The post Test the Machine Translation Service Application with PowerShell appeared first on Absolute SharePoint Blog by Vlad Catrinescu.


by Vlad Catrinescu via Absolute SharePoint Blog by Vlad Catrinescu

No comments:

Post a Comment