Sharepoint 2013 : Developing Applications Using Office Services - The New Machine Translation Services

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
7/2/2014 9:31:20 PM

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.

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 (

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:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.Office.TranslationServices\v4.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 =
string myOutput =

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,
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}",
Console.WriteLine("SaveBehaviorForOutput: {0}",


static void displayTranslationItemInfo(TranslationItemInfo itemInfo)
Console.WriteLine("\nTranslation 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("\nFinal 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("\nTranslation 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 1 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.

  •  Sharepoint 2013 : Developing Applications Using Office Services - Word Automation Services and the New PowerPoint Automation Services
  •  Sharepoint 2013 : Developing Applications Using Office Services - What’s New in Excel Services
  •  Sharepoint 2013 : Developing Applications Using Office Services - WOPI and the New Office Web Apps Server
  •  Sharepoint 2013 : Building a BCS-enabled Business Solution : Building an Integrated BCS Solution with an App for SharePoint Containing an App for Office
  •  Business Connectivity Services in Apps for SharePoint 2013 : Building an App-level BCS Solution for Office 365 SharePoint Online
  •  Business Connectivity Services in SharePoint 2013 : Adding a Business Data Connectivity Model to Office 365 SharePoint Online
  •  Remote Event Receivers in Sharepoint 2013 : Introducing Remote Event Receivers
  •  InfoPath with SharePoint 2010 : Apply Rich Text to the Entry
  •  InfoPath with SharePoint 2010 : Add Changed Event Code for Tracking Changes
  •  InfoPath with SharePoint 2010 : Set Up the Form for Tracking Changes
    Top 10
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
    - Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
    - Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    programming4us programming4us