Machine Translation Services is also an all-new server-side service with an architecture and runtime patterned after Word Automation Services. Using this service you can request translation of document libraries, folders, and files using a timer job, synchronously or asynchronously. The Machine Translation Service passes your content through to a Microsoft cloud-based translation service and returns the translated results. If you choose to use the Machine Translation Services, for privacy concerns, it is your responsibility to inform your users that their content will be sent to Microsoft and that Microsoft might use the content to improve its translation service. Be sure to see the Microsoft Translator Privacy statement for more detailed information. The reference is provided in the “Recommended Reading” section for this chapter.
Like Word Automation Services, Machine Translation Services is available on-premises only and is configured through the SharePoint Central Administration console. The time interval for the translation service can be set to run as often as every one minute. As a developer you have several ways you might choose to interact with the service. You are not limited to timer jobs only, but on-demand synchronous or asynchronous requests are supported. You can use the SharePoint server object model or you can remotely request translations using the REST API. For the REST API you can asynchronously translate a document library, folder, or file, but synchronously you can only request a single file translation. In the following Try It Out you perform a synchronous file conversion on a document in a document library.
using System.Globalization; using System.Web; using System.IO; using Microsoft.SharePoint; using Microsoft.Office.TranslationServices;
Console.WriteLine("C14TranslateSPOM Started"); string myWebSite = "http://YourServerNameHere"; string myCulture = "fr"; string myInput = "http://YourServerNameHere/YourDocumentLibrary/YourDocumentName.docx"; string myOutput = "http://YourServerNameHere/YourDocumentLibrary/YourDocumentName-fr.docx"; serviceContext = SPServiceContext.GetContext(new SPSite(myWebSite)); // Run synchronous conversion on a single file in doc lib. Console.WriteLine("Synchronous Translation Process Starting"); SyncTranslator job = new SyncTranslator(serviceContext, CultureInfo.GetCultureInfo(myCulture)); Console.WriteLine("File names for processing"); Console.WriteLine("File input: " + myInput); Console.WriteLine("File to be output: " + myOutput); TranslationItemInfo itemInfo = job.Translate(myInput, myOutput); Console.WriteLine("Translation Language: {0}", job.TargetLanguage.Name); Console.WriteLine("SaveBehaviorForOutput: {0}", job.OutputSaveBehavior.ToString()); displayTranslationItemInfo(itemInfo); Console.ReadLine(); } static void displayTranslationItemInfo(TranslationItemInfo itemInfo) { Console.WriteLine(" Translation completed -- Resulting information:"); Console.WriteLine("File Input: " + itemInfo.InputFile); Console.WriteLine("File Output: " + itemInfo.OutputFile); Console.WriteLine("Job Start Time: " + itemInfo.StartTime); Console.WriteLine("Job Complete Time: " + itemInfo.CompleteTime); Console.WriteLine("Error Message: " + itemInfo.ErrorMessage); Console.WriteLine("Translation Id: " + itemInfo.TranslationId); Console.WriteLine(" Final Job Status"); Console.WriteLine("Succeeded: " + itemInfo.Succeeded); Console.WriteLine("Failed: " + itemInfo.Failed); Console.WriteLine("Canceled: " + itemInfo.Canceled); Console.WriteLine("In Progress: " + itemInfo.InProgress); Console.WriteLine("Not Started: " + itemInfo.NotStarted); Console.WriteLine(" Translation completed. Press <Enter> to quit."); }
Machine Translation Services is a unique asset in the server-side services. It is important to note that it does not translate all Office document types. It’s limited primarily to the dot file extensions that Word can read or write such as .docx, .doc, .docm, .rtf, .txt, and some HTML-based files. You can query the server with REST to see which file extensions are supported in your environment using http://SharePointServer/_api/TranslationJob.EnumerateSupportedFileEXtensions. To see whether a specific extension is available use http://serverName/_api/TranslationJob.IsFileExtensionSupported('extension'). In any case, Machine Translation Services does not translate Excel or PowerPoint files.
Remember to inform the end users of your translation solutions that their document content will be sent to a Microsoft service for translation.