Code Samples, Simple Translation using CSOM, REST, and Machine Translation Services| Code Samples Machine Translation Services OneDrive for Business SharePoint SharePoint Server 2013
Machine Translation Services is a powerful Shared Service Application in SharePoint Server 2013 that provides automation synchronous and asynchronous translation of documents, folders, and sites. The code samples in this post provide simple examples of synchronous document translation using the Client Side Object Model in managed (C#) applications and Windows PowerShell in addition to accessing Machine Translation Services via REST.
The Client Side Object Model (CSOM) provides a rich alternative to earlier Web Services in providing an object-oriented system for interoperating with SharePoint data from a remote (client) machine.
The foundation of CSOM interop is the client context object which represents the current request context. In the provided samples, it is represented in the C# example as:
or in the Windows PowerShell sample as:
New-Object Microsoft.SharePoint.Client.ClientContext($url) where the $url in this example is a parameter passed to the script.
Through this context you can obtain access to client objects to include site collections and their subordinates as represented in the above examples.
For example, in the sample scripts (download link below), the top-level site collection represents the new client context which is passed to the SyncTranslator class of the TranslationServices namespace as the Context property.
$context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$context.Credentials = $credentials
$job = New-Object Microsoft.Office.Client.TranslationServices.SyncTranslator($context, $language)
In SharePoint the REST service is implemented in client.svc contained within _vti_bin; however, through substitution _api is used and establishes the base Url for each endpoint.
The service Url of specific endpoints is appended to the base Url, in the sample code:
$request = [System.Net.WebRequest]::Create($url +"/_api/TranslationJob.EnumerateSupportedLanguages")
These samples are intended to illustrate how Windows PowerShell can be used to access cloud services through CSOM and REST.
Download the samples here:
CSOM (Windows PowerShell and C# Samples)
REST (Windows PowerShell Samples)
More like this...
- Transitioning from Authoratative Web Pages to Answers in SharePoint Online
- Using a Flic Smart Button as a PowerPoint Remote
- Microsoft 365 migration on your terms with new improvements to the SharePoint Migration Tool
- Kick start the new year and your cloud migration with new SharePoint Migration Tool improvements
- Migrating to Microsoft Teams using the SharePoint Migration Tool