THE NEW MACHINE TRANSLATION SERVICES

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.


TRY IT OUT: Translating a Document Synchronously with Machine Translation Services (C14TranslateSPOM.zip)
In this exercise you use a simple console application to see the fundamental code pattern to synchronously convert a Word document in a document library into French using Machine Translation Services. For this Try It Out you need access to a SharePoint 2013 on-premises server development environment with Visual Studio 2012 installed and Machine Translation Services running on the SharePoint server.
1. Either confirm with your SharePoint Administrator that Machine Translation Services is running in your on-premises environment, or open the SharePoint Administration Console, click Application Management, click Manage Service Applications and confirm that the Machine Translation Service and Proxy are started. If they are not, return to Application Management, click Manage Services on Server, locate the Machine Translation Service and click the Start link.
2. Run Visual Studio 2012 as Administrator. Select New Project.
3. In the New Project dialog, expand the Templates ⇒ Visual C# ⇒ Windows nodes. Select Console Application and provide the name C14TranslateSPOM. Click OK.
4. When the project loads, close the Program.cs file.
5. In the Solution Explorer, right-click the project and select Properties. On the Application tab confirm the Target framework is set to .NET Framework 4. If it’s not, set it and confirm any prompts and reopen the Properties pane. Click the Build tab, set the Configuration drop-down list to All Configurations, and close the Properties pane.
6. In the Solution Explorer, right-click the project and select Add Reference.
7. In the Reference Manager, under Framework, add System.Web, and under Extensions add Microsoft.SharePoint. Click Browse and navigate to the following location: c:WindowsMicrosoft.NETassemblyGAC_MSILMicrosoft.Office.TranslationServicesv4.0_15.0.0.0__71e9bce111e9429c. Click the Microsoft.Office.TranslationServices.dll, click Add and click OK.
8. In the Solution Explorer, double-click the Program.cs file to open it. Add the following using statements:
using System.Globalization;
using System.Web;
using System.IO;
using Microsoft.SharePoint;
using Microsoft.Office.TranslationServices;
9. In the Main method, add the following:
            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.");
        }
10. Open a browser, navigate to a site, and upload a .docx document to be translated.
11. After the file is uploaded, click the ellipsis (...) by the filename and copy the URL for the document. Use it to do all of the following tasks:
  • Replace the YourServerNameHere literal in the myWebSite variable with the root URL for your SharePoint site.
  • Replace the YourServerNameHere/YourDocumentLibrary/YourDocumentName literal values in the myInput variable, with the full path to your document.
  • Replace the YourServerNameHere/YourDocumentLibrary/YourDocumentName literal values in the myOutput variable with the full path to your document. Be sure to leave the -fr on the filename or some other arbitrary value so the output file does not overwrite the input file when the translation is completed.
12. Press F5 to run the code. Depending on the hardware speed of your test server, this might take several minutes to complete. The command window will show the resulting processing information when the translation is completed. Figure 14-3 provides an example of the output results in the command window.
13. When the operation completes, close the command window and look in the document library to review the new translated document.
How It Works
For this Try It Out you performed a synchronous translation on a document in a document library, and to do this you used the SyncTranslator class. You created an object and passed in the full URL input/output path to a document. It is possible to use SyncTranslator to input/output file stream objects and byte arrays, yet in all cases, synchronous interactions with the Machine Translation Service is for a single file translation only. With asynchronous interactions with the service, where you submit timer jobs into the queue, you have more latitude and for this you use the TranslationJob class. Using this class you can not only designate a single file on a document library to be translated asynchronously, you can designate SPFolder objects for both input and output to translate the contents of an entire folder, or you can translate an entire document library by providing an SPDocumentLibrary object for both an input and output location.

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.107.241